From ca829c18cc0e4df86cca9298961e47d462fc62c2 Mon Sep 17 00:00:00 2001 From: drcrazy Date: Sun, 8 Oct 2017 00:04:08 +0300 Subject: [PATCH] Added wrench support --- .../techreborn/blocks/BlockFusionCoil.java | 34 +++++++++++++++++++ .../TileFusionControlComputer.java | 8 ++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/main/java/techreborn/blocks/BlockFusionCoil.java b/src/main/java/techreborn/blocks/BlockFusionCoil.java index 2c959edb5..067de0154 100644 --- a/src/main/java/techreborn/blocks/BlockFusionCoil.java +++ b/src/main/java/techreborn/blocks/BlockFusionCoil.java @@ -27,9 +27,21 @@ package techreborn.blocks; import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; import prospector.shootingstar.ShootingStar; import prospector.shootingstar.model.ModelCompound; +import reborncore.api.ToolManager; import techreborn.client.TechRebornCreativeTab; +import techreborn.init.ModBlocks; +import techreborn.init.ModSounds; import techreborn.lib.ModInfo; public class BlockFusionCoil extends Block { @@ -41,4 +53,26 @@ public class BlockFusionCoil extends Block { setCreativeTab(TechRebornCreativeTab.instance); ShootingStar.registerModel(new ModelCompound(ModInfo.MOD_ID, this, "machines/generators")); } + + @Override + public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, + EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { + + ItemStack tool = playerIn.getHeldItem(EnumHand.MAIN_HAND); + if (!tool.isEmpty() && ToolManager.INSTANCE.canHandleTool(tool)) { + if (ToolManager.INSTANCE.handleTool(tool, pos, worldIn, playerIn, side, false)) { + if (playerIn.isSneaking()) { + ItemStack drop = new ItemStack(ModBlocks.FUSION_COIL, 1); + spawnAsEntity(worldIn, pos, drop); + worldIn.playSound(null, playerIn.posX, playerIn.posY, playerIn.posZ, ModSounds.BLOCK_DISMANTLE, + SoundCategory.BLOCKS, 0.6F, 1F); + if (!worldIn.isRemote) { + worldIn.setBlockState(pos, Blocks.AIR.getDefaultState(), 2); + } + return true; + } + } + } + return false; + } } diff --git a/src/main/java/techreborn/tiles/fusionReactor/TileFusionControlComputer.java b/src/main/java/techreborn/tiles/fusionReactor/TileFusionControlComputer.java index 0a6059500..82b8d48f7 100644 --- a/src/main/java/techreborn/tiles/fusionReactor/TileFusionControlComputer.java +++ b/src/main/java/techreborn/tiles/fusionReactor/TileFusionControlComputer.java @@ -30,6 +30,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.ITextComponent; +import reborncore.api.IToolDrop; import reborncore.api.tile.IInventoryProvider; import reborncore.common.powerSystem.TilePowerAcceptor; import reborncore.common.registration.RebornRegistry; @@ -45,7 +46,7 @@ import techreborn.init.ModBlocks; import techreborn.lib.ModInfo; @RebornRegistry(modID = ModInfo.MOD_ID) -public class TileFusionControlComputer extends TilePowerAcceptor implements IInventoryProvider, IContainerProvider { +public class TileFusionControlComputer extends TilePowerAcceptor implements IToolDrop, IInventoryProvider, IContainerProvider { @ConfigRegistry(config = "machines", category = "fusion_reactor", key = "FusionReactorMaxInput", comment = "Fusion Reactor Max Input (Value in EU)") public static int maxInput = 8192; @@ -382,4 +383,9 @@ public class TileFusionControlComputer extends TilePowerAcceptor implements IInv .syncIntegerValue(this::getFinalTickTime, this::setFinalTickTime) .syncIntegerValue(this::getNeededPower, this::setNeededPower).addInventory().create(this); } + + @Override + public ItemStack getToolDrop(EntityPlayer p0) { + return new ItemStack(ModBlocks.FUSION_CONTROL_COMPUTER, 1); + } }