package com.thebrokenrail.energonrelics.block.reactor; import com.thebrokenrail.energonrelics.EnergonRelics; import com.thebrokenrail.energonrelics.block.entity.reactor.ReactorInputBlockEntity; import com.thebrokenrail.energonrelics.api.block.SimpleBlockWithEntity; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.minecraft.block.BlockState; import net.minecraft.block.Material; import net.minecraft.block.MaterialColor; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.inventory.Inventory; import net.minecraft.screen.HopperScreenHandler; import net.minecraft.screen.SimpleNamedScreenHandlerFactory; import net.minecraft.text.TranslatableText; 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 java.util.function.Function; @SuppressWarnings("deprecation") public class ReactorInputBlock extends SimpleBlockWithEntity { public ReactorInputBlock() { super(FabricBlockSettings.of(Material.STONE, MaterialColor.YELLOW_TERRACOTTA).requiresTool().strength(1.5f, 6.0f)); } @Override protected Function, BlockEntity> getFactory() { return ReactorInputBlockEntity::new; } @Override public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { BlockEntity entity = world.getBlockEntity(pos); if (entity instanceof Inventory) { if (!world.isClient()) { player.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, inv, player2) -> new HopperScreenHandler(i, inv, (Inventory) entity), new TranslatableText("block." + EnergonRelics.NAMESPACE + ".reactor_input"))); } return ActionResult.SUCCESS; } else { return ActionResult.FAIL; } } @Override protected boolean hasInventory() { return true; } }