diff --git a/src/main/java/techreborn/compat/crafttweaker/CTAlloySmelter.java b/src/main/java/techreborn/compat/crafttweaker/CTAlloySmelter.java index 8fc2fa82f..d6c9bf42b 100644 --- a/src/main/java/techreborn/compat/crafttweaker/CTAlloySmelter.java +++ b/src/main/java/techreborn/compat/crafttweaker/CTAlloySmelter.java @@ -27,7 +27,6 @@ package techreborn.compat.crafttweaker; import crafttweaker.CraftTweakerAPI; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; -import net.minecraft.item.ItemStack; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; import techreborn.api.Reference; diff --git a/src/main/java/techreborn/compat/crafttweaker/CTAssemblingMachine.java b/src/main/java/techreborn/compat/crafttweaker/CTAssemblingMachine.java index 11860333e..ba058a2e9 100644 --- a/src/main/java/techreborn/compat/crafttweaker/CTAssemblingMachine.java +++ b/src/main/java/techreborn/compat/crafttweaker/CTAssemblingMachine.java @@ -27,7 +27,6 @@ package techreborn.compat.crafttweaker; import crafttweaker.CraftTweakerAPI; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; -import net.minecraft.item.ItemStack; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; import techreborn.api.Reference; diff --git a/src/main/java/techreborn/compat/crafttweaker/CTBlastFurnace.java b/src/main/java/techreborn/compat/crafttweaker/CTBlastFurnace.java index 6dac3e2c6..48065cdba 100644 --- a/src/main/java/techreborn/compat/crafttweaker/CTBlastFurnace.java +++ b/src/main/java/techreborn/compat/crafttweaker/CTBlastFurnace.java @@ -27,7 +27,6 @@ package techreborn.compat.crafttweaker; import crafttweaker.CraftTweakerAPI; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; -import net.minecraft.item.ItemStack; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; import techreborn.api.Reference; diff --git a/src/main/java/techreborn/compat/crafttweaker/CTCentrifuge.java b/src/main/java/techreborn/compat/crafttweaker/CTCentrifuge.java index 7a2a45447..2a8e8659a 100644 --- a/src/main/java/techreborn/compat/crafttweaker/CTCentrifuge.java +++ b/src/main/java/techreborn/compat/crafttweaker/CTCentrifuge.java @@ -27,7 +27,6 @@ package techreborn.compat.crafttweaker; import crafttweaker.CraftTweakerAPI; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; -import net.minecraft.item.ItemStack; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; import techreborn.api.Reference; diff --git a/src/main/java/techreborn/compat/crafttweaker/CTChemicalReactor.java b/src/main/java/techreborn/compat/crafttweaker/CTChemicalReactor.java index 3caf0cd53..8709be1c6 100644 --- a/src/main/java/techreborn/compat/crafttweaker/CTChemicalReactor.java +++ b/src/main/java/techreborn/compat/crafttweaker/CTChemicalReactor.java @@ -27,7 +27,6 @@ package techreborn.compat.crafttweaker; import crafttweaker.CraftTweakerAPI; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; -import net.minecraft.item.ItemStack; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; import techreborn.api.Reference; diff --git a/src/main/java/techreborn/compat/crafttweaker/CTCompressor.java b/src/main/java/techreborn/compat/crafttweaker/CTCompressor.java index d70d427cf..daed5820d 100644 --- a/src/main/java/techreborn/compat/crafttweaker/CTCompressor.java +++ b/src/main/java/techreborn/compat/crafttweaker/CTCompressor.java @@ -27,7 +27,6 @@ package techreborn.compat.crafttweaker; import crafttweaker.CraftTweakerAPI; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; -import net.minecraft.item.ItemStack; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; import techreborn.api.Reference; diff --git a/src/main/java/techreborn/compat/crafttweaker/CTDistillationTower.java b/src/main/java/techreborn/compat/crafttweaker/CTDistillationTower.java index d5351f76e..e3ba0ae64 100644 --- a/src/main/java/techreborn/compat/crafttweaker/CTDistillationTower.java +++ b/src/main/java/techreborn/compat/crafttweaker/CTDistillationTower.java @@ -27,7 +27,6 @@ package techreborn.compat.crafttweaker; import crafttweaker.CraftTweakerAPI; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; -import net.minecraft.item.ItemStack; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; import techreborn.api.Reference; diff --git a/src/main/java/techreborn/compat/crafttweaker/CTGrinder.java b/src/main/java/techreborn/compat/crafttweaker/CTGrinder.java index a071758c1..c359cb542 100644 --- a/src/main/java/techreborn/compat/crafttweaker/CTGrinder.java +++ b/src/main/java/techreborn/compat/crafttweaker/CTGrinder.java @@ -27,7 +27,6 @@ package techreborn.compat.crafttweaker; import crafttweaker.CraftTweakerAPI; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; -import net.minecraft.item.ItemStack; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; import techreborn.api.Reference; diff --git a/src/main/java/techreborn/compat/crafttweaker/CTImplosionCompressor.java b/src/main/java/techreborn/compat/crafttweaker/CTImplosionCompressor.java index b67d0abf7..e9c0bddd0 100644 --- a/src/main/java/techreborn/compat/crafttweaker/CTImplosionCompressor.java +++ b/src/main/java/techreborn/compat/crafttweaker/CTImplosionCompressor.java @@ -27,7 +27,6 @@ package techreborn.compat.crafttweaker; import crafttweaker.CraftTweakerAPI; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; -import net.minecraft.item.ItemStack; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; import techreborn.api.Reference; diff --git a/src/main/java/techreborn/compat/crafttweaker/CTIndustrialElectrolyzer.java b/src/main/java/techreborn/compat/crafttweaker/CTIndustrialElectrolyzer.java index a19b485e1..de48f79f4 100644 --- a/src/main/java/techreborn/compat/crafttweaker/CTIndustrialElectrolyzer.java +++ b/src/main/java/techreborn/compat/crafttweaker/CTIndustrialElectrolyzer.java @@ -27,7 +27,6 @@ package techreborn.compat.crafttweaker; import crafttweaker.CraftTweakerAPI; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; -import net.minecraft.item.ItemStack; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; import techreborn.api.Reference; diff --git a/src/main/java/techreborn/compat/crafttweaker/CTIndustrialGrinder.java b/src/main/java/techreborn/compat/crafttweaker/CTIndustrialGrinder.java index cf524a488..7fade3795 100644 --- a/src/main/java/techreborn/compat/crafttweaker/CTIndustrialGrinder.java +++ b/src/main/java/techreborn/compat/crafttweaker/CTIndustrialGrinder.java @@ -28,7 +28,6 @@ import crafttweaker.CraftTweakerAPI; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; import crafttweaker.api.liquid.ILiquidStack; -import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; diff --git a/src/main/java/techreborn/compat/crafttweaker/CTIndustrialSawmill.java b/src/main/java/techreborn/compat/crafttweaker/CTIndustrialSawmill.java index 0e88c2f0d..3767b8c56 100644 --- a/src/main/java/techreborn/compat/crafttweaker/CTIndustrialSawmill.java +++ b/src/main/java/techreborn/compat/crafttweaker/CTIndustrialSawmill.java @@ -28,7 +28,6 @@ import crafttweaker.CraftTweakerAPI; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; import crafttweaker.api.liquid.ILiquidStack; -import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; diff --git a/src/main/java/techreborn/compat/crafttweaker/CTVacuumFreezer.java b/src/main/java/techreborn/compat/crafttweaker/CTVacuumFreezer.java index 2ddb43280..bc78df186 100644 --- a/src/main/java/techreborn/compat/crafttweaker/CTVacuumFreezer.java +++ b/src/main/java/techreborn/compat/crafttweaker/CTVacuumFreezer.java @@ -27,7 +27,6 @@ package techreborn.compat.crafttweaker; import crafttweaker.CraftTweakerAPI; import crafttweaker.api.item.IIngredient; import crafttweaker.api.item.IItemStack; -import net.minecraft.item.ItemStack; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; import techreborn.api.Reference; diff --git a/src/main/java/techreborn/items/tools/ItemAdvancedDrill.java b/src/main/java/techreborn/items/tools/ItemAdvancedDrill.java index 4dc9b5399..bdb2d3e61 100644 --- a/src/main/java/techreborn/items/tools/ItemAdvancedDrill.java +++ b/src/main/java/techreborn/items/tools/ItemAdvancedDrill.java @@ -24,11 +24,9 @@ package techreborn.items.tools; -import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; @@ -42,20 +40,101 @@ import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import reborncore.common.powerSystem.PoweredItem; +import reborncore.common.util.WorldUtils; import techreborn.config.ConfigTechReborn; import techreborn.init.ModItems; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; public class ItemAdvancedDrill extends ItemDrill { public ItemAdvancedDrill() { - super(ToolMaterial.DIAMOND, "techreborn.advancedDrill", ConfigTechReborn.AdvancedDrillCharge, - 4.0F, 10F); + super(ToolMaterial.DIAMOND, "techreborn.advancedDrill", ConfigTechReborn.AdvancedDrillCharge, 4.0F, 10F); this.cost = 250; } + public Set getTargetBlocks(World worldIn, BlockPos pos, EntityLivingBase entityLiving) { + Set targetBlocks = new HashSet(); + if (!(entityLiving instanceof EntityPlayer)) { + return new HashSet(); + } + RayTraceResult raytrace = rayTrace(worldIn, (EntityPlayer) entityLiving, false); + EnumFacing enumfacing = raytrace.sideHit; + if (enumfacing == EnumFacing.SOUTH || enumfacing == EnumFacing.NORTH) { + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + BlockPos newPos = pos.add(i, j, 0); + targetBlocks.add(newPos); + } + } + } else if (enumfacing == EnumFacing.EAST || enumfacing == EnumFacing.WEST) { + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + BlockPos newPos = pos.add(0, j, i); + targetBlocks.add(newPos); + } + } + } else if (enumfacing == EnumFacing.DOWN || enumfacing == EnumFacing.UP) { + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + BlockPos newPos = pos.add(j, 0, i); + targetBlocks.add(newPos); + } + } + } + return targetBlocks; + } + + public void breakBlock(BlockPos pos, World world, EntityPlayer playerIn, BlockPos originalPos, float originalHardness) { + if (originalPos == pos) { + return; + } + IBlockState blockState = world.getBlockState(pos); + float blockHardness = world.getBlockState(pos).getPlayerRelativeBlockHardness(playerIn, world, pos); + if (blockHardness == -1.0F) { + return; + } + if ((blockHardness / originalHardness) > 20.0F) { + return; + } + NonNullList stuff = NonNullList.create(); + blockState.getBlock().getDrops(stuff, world, pos, blockState, 0); + List drops = new ArrayList<>(); + BlockEvent.HarvestDropsEvent event = new BlockEvent.HarvestDropsEvent(world, pos, blockState, 0, 1, drops, playerIn, false); + MinecraftForge.EVENT_BUS.post(event); + for (ItemStack drop : drops) { + if (drop.getCount() > 0) { + stuff.add(drop); + } + } + WorldUtils.dropItems(stuff, world, pos); + world.setBlockToAir(pos); + } + + // ItemDrill + @Override + public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState blockIn, BlockPos pos, EntityLivingBase entityLiving) { + if (PoweredItem.canUseEnergy(cost, stack)) { + EntityPlayer playerIn = (EntityPlayer) entityLiving; + float originalHardness = blockIn.getPlayerRelativeBlockHardness(playerIn, worldIn, pos); + for (BlockPos additionalPos : getTargetBlocks(worldIn, pos, entityLiving)) { + breakBlock(additionalPos, worldIn, playerIn, pos, originalHardness); + PoweredItem.useEnergy(cost, stack); + } + } + return super.onBlockDestroyed(stack, worldIn, blockIn, pos, entityLiving); + } + + // ItemPickaxe + @Override + public boolean canHarvestBlock(IBlockState blockIn) { + return Items.DIAMOND_PICKAXE.canHarvestBlock(blockIn) || Items.DIAMOND_SHOVEL.canHarvestBlock(blockIn); + } + + // Item @SideOnly(Side.CLIENT) @Override public void getSubItems(CreativeTabs par2CreativeTabs, NonNullList itemList) { @@ -70,76 +149,4 @@ public class ItemAdvancedDrill extends ItemDrill { itemList.add(uncharged); itemList.add(charged); } - - @Override - public boolean canHarvestBlock(IBlockState blockIn) { - return Items.DIAMOND_PICKAXE.canHarvestBlock(blockIn) || Items.DIAMOND_SHOVEL.canHarvestBlock(blockIn); - } - - @Override - public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState blockIn, BlockPos pos, EntityLivingBase entityLiving) { - if(!(entityLiving instanceof EntityPlayer)) - return false; - RayTraceResult raytrace= rayTrace(worldIn, (EntityPlayer) entityLiving, false); - if(raytrace==null) - return false; - EnumFacing enumfacing = raytrace.sideHit; - if (enumfacing == EnumFacing.SOUTH || enumfacing == EnumFacing.NORTH) { - for (int i = -1; i < 2; i++) { - for (int j = -1; j < 2; j++) { - breakBlock(pos.add(i, j, 0), stack, worldIn, entityLiving, pos); - } - } - } else if (enumfacing == EnumFacing.EAST || enumfacing == EnumFacing.WEST) { - for (int i = -1; i < 2; i++) { - for (int j = -1; j < 2; j++) { - breakBlock(pos.add(0, j, i), stack, worldIn, entityLiving, pos); - } - } - } else if (enumfacing == EnumFacing.DOWN || enumfacing == EnumFacing.UP) { - for (int i = -1; i < 2; i++) { - for (int j = -1; j < 2; j++) { - breakBlock(pos.add(j, 0, i), stack, worldIn, entityLiving, pos); - } - } - } - - return super.onBlockDestroyed(stack, worldIn, blockIn, pos, entityLiving); - } - - @SuppressWarnings("deprecation") - public void breakBlock(BlockPos pos, ItemStack stack, World world, EntityLivingBase entityLiving, BlockPos oldPos) { - if (oldPos == pos) { - return; - } - if (!PoweredItem.canUseEnergy(cost, stack)) { - return; - } - IBlockState blockState = world.getBlockState(pos); - Block block = blockState.getBlock(); - if (blockState.getBlockHardness(world, pos) == -1.0F) { - return; - } - List stuff = block.getDrops(world, pos, blockState, 0); - List dropList = new ArrayList<>(); - BlockEvent.HarvestDropsEvent event = new BlockEvent.HarvestDropsEvent(world, pos, blockState, 0, 1, dropList, (EntityPlayer) entityLiving, false); - MinecraftForge.EVENT_BUS.post(event); - for (ItemStack drop : dropList) { - if (drop.getCount() > 0) { - stuff.add(drop); - } - } - for (ItemStack drop : stuff) { - if (world.isRemote) { - continue; - } - final EntityItem entityitem = new EntityItem(world, oldPos.getX(), oldPos.getY(), oldPos.getZ(), drop); - entityitem.motionX = (oldPos.getX() - oldPos.getX()) / 10.0f; - entityitem.motionY = 0.15000000596046448; - entityitem.motionZ = (oldPos.getZ() - oldPos.getZ()) / 10.0f; - world.spawnEntity(entityitem); - } - PoweredItem.useEnergy(cost, stack); - world.setBlockToAir(pos); - } }