You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.7 KiB
Java

package net.brokenmoon.redcontrol.blocks;
import com.mojang.serialization.MapCodec;
import net.brokenmoon.redcontrol.RedControl;
import net.brokenmoon.redcontrol.blockentities.DriveEntity;
import net.brokenmoon.redcontrol.item.FloppyDisk;
import net.minecraft.block.BlockState;
import net.minecraft.block.BlockWithEntity;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
public class DriveBlock extends NetworkCarrier{
public DriveBlock(Settings settings) {
super(settings);
}
@Override
protected MapCodec<? extends BlockWithEntity> getCodec() {
return null;
}
@Nullable
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new DriveEntity(pos, state);
}
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (player.getStackInHand(hand).getItem() == RedControl.SQUEAKY_HAMMER) {
return super.onUse(state,world,pos,player,hand,hit);
} else if(player.getStackInHand(hand).getItem() instanceof FloppyDisk || player.getStackInHand(hand) == ItemStack.EMPTY){
if(world.getBlockEntity(pos) instanceof DriveEntity){
return ((DriveEntity)world.getBlockEntity(pos)).onUse(player, hand);
}
}
return ActionResult.PASS;
}
}