Work on Advanced Drill (#1411)

* Raytracing for drill
* Stop crashes if raytrace is somehow null
* getCount() already checks for emptiness I think
This commit is contained in:
temp1011 2018-01-19 07:07:40 +00:00 committed by drcrazy
parent 8e12543902
commit 91a56077d8

View file

@ -24,6 +24,7 @@
package techreborn.items.tools; package techreborn.items.tools;
import codechicken.lib.raytracer.RayTracer;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
@ -35,6 +36,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.NonNullList; import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.event.world.BlockEvent;
@ -77,13 +79,12 @@ public class ItemAdvancedDrill extends ItemDrill {
@Override @Override
public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState blockIn, BlockPos pos, EntityLivingBase entityLiving) { public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState blockIn, BlockPos pos, EntityLivingBase entityLiving) {
//TODO raytrace if(!(entityLiving instanceof EntityPlayer))
EnumFacing enumfacing = entityLiving.getHorizontalFacing().getOpposite(); return false;
if (entityLiving.rotationPitch < -50) { RayTraceResult raytrace= RayTracer.retrace((EntityPlayer) entityLiving);
enumfacing = EnumFacing.DOWN; if(raytrace==null)
} else if (entityLiving.rotationPitch > 50) { return false;
enumfacing = EnumFacing.UP; EnumFacing enumfacing = raytrace.sideHit;
}
if (enumfacing == EnumFacing.SOUTH || enumfacing == EnumFacing.NORTH) { if (enumfacing == EnumFacing.SOUTH || enumfacing == EnumFacing.NORTH) {
for (int i = -1; i < 2; i++) { for (int i = -1; i < 2; i++) {
for (int j = -1; j < 2; j++) { for (int j = -1; j < 2; j++) {
@ -125,7 +126,7 @@ public class ItemAdvancedDrill extends ItemDrill {
BlockEvent.HarvestDropsEvent event = new BlockEvent.HarvestDropsEvent(world, pos, blockState, 0, 1, dropList, (EntityPlayer) entityLiving, false); BlockEvent.HarvestDropsEvent event = new BlockEvent.HarvestDropsEvent(world, pos, blockState, 0, 1, dropList, (EntityPlayer) entityLiving, false);
MinecraftForge.EVENT_BUS.post(event); MinecraftForge.EVENT_BUS.post(event);
for (ItemStack drop : dropList) { for (ItemStack drop : dropList) {
if (!drop.isEmpty() && drop.getCount() > 0) { if (drop.getCount() > 0) {
stuff.add(drop); stuff.add(drop);
} }
} }