Fix Drill break speed in certain conditions (#1428)

Some work on AdvancedDrill break speed. Thanks to temp1011
This commit is contained in:
temp1011 2018-03-22 12:39:32 +00:00 committed by drcrazy
parent 1a5299df55
commit a36c2d4065
2 changed files with 39 additions and 9 deletions

View file

@ -39,6 +39,7 @@ import reborncore.common.util.OreDrop;
import techreborn.init.ModItems;
import techreborn.items.ItemDusts;
import techreborn.items.ItemGems;
import techreborn.items.tools.ItemAdvancedDrill;
import techreborn.lib.ModInfo;
import techreborn.utils.OreDictUtils;
@ -106,5 +107,12 @@ public class BlockBreakHandler {
}
event.setNewSpeed(speed / blocks);
}
if(event.getEntityPlayer().getHeldItem(EnumHand.MAIN_HAND).getItem() == ModItems.ADVANCED_DRILL && event.getOriginalSpeed() > 1.0f) {
BlockPos pos = event.getPos();
World worldIn = event.getEntityPlayer().world;
ItemAdvancedDrill drill = new ItemAdvancedDrill();
ItemStack stack = new ItemStack(drill);
event.setNewSpeed(drill.getMinSpeed(worldIn,pos,event.getEntityLiving(),stack));
}
}
}

View file

@ -46,7 +46,9 @@ 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 {
@ -76,34 +78,54 @@ public class ItemAdvancedDrill extends ItemDrill {
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) {
public Set<BlockPos> getTargetBlocks(World worldIn, BlockPos pos, EntityLivingBase entityLiving) {
Set<BlockPos> targetBlocks = new HashSet<BlockPos>();
if(!(entityLiving instanceof EntityPlayer))
return false;
return new HashSet<BlockPos>();
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);
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++) {
breakBlock(pos.add(0, j, i), stack, worldIn, entityLiving, pos);
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++) {
breakBlock(pos.add(j, 0, i), stack, worldIn, entityLiving, pos);
BlockPos newPos = pos.add(j,0,i);
targetBlocks.add(newPos);
}
}
}
return targetBlocks;
}
public float getMinSpeed(World worldIn, BlockPos pos, EntityLivingBase entityLiving, ItemStack stack) {
Set<BlockPos> positions = getTargetBlocks(worldIn,pos,entityLiving);
float min = Short.MAX_VALUE; //Hopefully this is big enough
for(BlockPos position : positions) {
IBlockState state = worldIn.getBlockState(position);
float breakSpeed = super.getDestroySpeed(stack,state);
if(breakSpeed < min && breakSpeed > 0)
min = breakSpeed;
}
return min;
}
@Override
public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState blockIn, BlockPos pos, EntityLivingBase entityLiving) {
for(BlockPos newPos : getTargetBlocks(worldIn, pos, entityLiving)) {
breakBlock(newPos, stack, worldIn, entityLiving, pos);
}
return super.onBlockDestroyed(stack, worldIn, blockIn, pos, entityLiving);
}