Clean up drill and chainsaw breaking logic, closes #1465
This commit is contained in:
parent
b0e79aa1e6
commit
c8886bbd9b
2 changed files with 11 additions and 44 deletions
|
@ -24,28 +24,21 @@
|
|||
|
||||
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;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import reborncore.common.powerSystem.PoweredItem;
|
||||
import techreborn.config.ConfigTechReborn;
|
||||
import techreborn.init.ModItems;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemAdvancedChainsaw extends ItemChainsaw {
|
||||
|
||||
public ItemAdvancedChainsaw() {
|
||||
|
@ -96,30 +89,14 @@ public class ItemAdvancedChainsaw extends ItemChainsaw {
|
|||
return;
|
||||
}
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
Block block = blockState.getBlock();
|
||||
if (blockState.getBlockHardness(world, pos) == -1.0F) {
|
||||
return;
|
||||
}
|
||||
List<ItemStack> stuff = block.getDrops(world, pos, blockState, 0);
|
||||
List<ItemStack> 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.isEmpty() && drop.getCount() > 0) {
|
||||
stuff.add(drop);
|
||||
if(!(entityLiving instanceof EntityPlayer)){
|
||||
return;
|
||||
}
|
||||
}
|
||||
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);
|
||||
blockState.getBlock().harvestBlock(world, (EntityPlayer) entityLiving, pos, blockState, world.getTileEntity(pos), stack);
|
||||
world.setBlockToAir(pos);
|
||||
world.removeTileEntity(pos);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
package techreborn.items.tools;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
|
@ -36,18 +37,13 @@ import net.minecraft.util.NonNullList;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
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 {
|
||||
|
@ -96,7 +92,7 @@ public class ItemAdvancedDrill extends ItemDrill {
|
|||
return targetBlocks;
|
||||
}
|
||||
|
||||
public void breakBlock(BlockPos pos, World world, EntityPlayer playerIn, BlockPos originalPos, float originalHardness) {
|
||||
public void breakBlock(BlockPos pos, World world, EntityPlayer playerIn, BlockPos originalPos, float originalHardness, ItemStack drill) {
|
||||
if (originalPos == pos) {
|
||||
return;
|
||||
}
|
||||
|
@ -111,18 +107,12 @@ public class ItemAdvancedDrill extends ItemDrill {
|
|||
if ((originalHardness / blockHardness) > 10.0F) {
|
||||
return;
|
||||
}
|
||||
NonNullList<ItemStack> stuff = NonNullList.create();
|
||||
blockState.getBlock().getDrops(stuff, world, pos, blockState, 0);
|
||||
List<ItemStack> 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);
|
||||
if(blockState.getMaterial() == Material.AIR){
|
||||
return;
|
||||
}
|
||||
}
|
||||
WorldUtils.dropItems(stuff, world, pos);
|
||||
blockState.getBlock().harvestBlock(world, playerIn, pos, blockState, world.getTileEntity(pos), drill);
|
||||
world.setBlockToAir(pos);
|
||||
world.removeTileEntity(pos);
|
||||
}
|
||||
|
||||
// ItemDrill
|
||||
|
@ -132,7 +122,7 @@ public class ItemAdvancedDrill extends ItemDrill {
|
|||
EntityPlayer playerIn = (EntityPlayer) entityLiving;
|
||||
float originalHardness = blockIn.getPlayerRelativeBlockHardness(playerIn, worldIn, pos);
|
||||
for (BlockPos additionalPos : getTargetBlocks(worldIn, pos, entityLiving)) {
|
||||
breakBlock(additionalPos, worldIn, playerIn, pos, originalHardness);
|
||||
breakBlock(additionalPos, worldIn, playerIn, pos, originalHardness, stack);
|
||||
}
|
||||
}
|
||||
// Use energy only once no matter how many blocks were broken, e.g. energy used per application of a drill
|
||||
|
|
Loading…
Add table
Reference in a new issue