Skip to content

Commit

Permalink
supply getPickBlock with a valid raytrace. Fixes #5034
Browse files Browse the repository at this point in the history
  • Loading branch information
thiakil committed Apr 30, 2018
1 parent 92914f6 commit 4a877de
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/main/java/mekanism/common/item/ItemAtomicDisassembler.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;

Expand Down Expand Up @@ -112,6 +114,17 @@ public boolean onBlockDestroyed(ItemStack itemstack, World world, IBlockState st

return true;
}

private RayTraceResult doRayTrace(IBlockState state, BlockPos pos, EntityPlayer player)
{
Vec3d positionEyes = player.getPositionEyes(1.0F);
Vec3d playerLook = player.getLook(1.0F);
double blockReachDistance = player.getAttributeMap().getAttributeInstance(EntityPlayer.REACH_DISTANCE).getAttributeValue();
Vec3d maxReach = positionEyes.addVector(playerLook.x * blockReachDistance, playerLook.y * blockReachDistance, playerLook.z * blockReachDistance);
RayTraceResult res = state.collisionRayTrace(player.world, pos, playerLook, maxReach);
//noinspection ConstantConditions - idea thinks it's nonnull due to package level annotations, but it's not
return res != null ? res : new RayTraceResult(RayTraceResult.Type.MISS, Vec3d.ZERO, EnumFacing.UP, pos);
}

@Override
public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, EntityPlayer player)
Expand All @@ -129,7 +142,8 @@ public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, EntityPlayer
block = Blocks.REDSTONE_ORE;
}

ItemStack stack = block.getPickBlock(state, null, player.world, pos, player);
RayTraceResult raytrace = doRayTrace(state, pos, player);
ItemStack stack = block.getPickBlock(state, raytrace, player.world, pos, player);
Coord4D orig = new Coord4D(pos, player.world);

List<String> names = MekanismUtils.getOreDictName(stack);
Expand All @@ -146,7 +160,7 @@ public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, EntityPlayer

if(getMode(itemstack) == 3 && isOre && !player.capabilities.isCreativeMode)
{
Set<Coord4D> found = new Finder(player.world, stack, new Coord4D(pos, player.world)).calc();
Set<Coord4D> found = new Finder(player.world, stack, new Coord4D(pos, player.world), raytrace).calc();

for(Coord4D coord : found)
{
Expand Down Expand Up @@ -372,13 +386,16 @@ public static class Finder
private Block startBlock;

public static Map<Block, List<Block>> ignoreBlocks = new HashMap<>();

RayTraceResult rayTraceResult;

public Finder(World w, ItemStack s, Coord4D loc)
public Finder(World w, ItemStack s, Coord4D loc, RayTraceResult traceResult)
{
world = w;
stack = s;
location = loc;
startBlock = loc.getBlock(w);
rayTraceResult = traceResult;
}

public void loop(Coord4D pointer)
Expand All @@ -394,7 +411,7 @@ public void loop(Coord4D pointer)
{
Coord4D coord = pointer.offset(side);

ItemStack blockStack = coord.getBlock(world).getPickBlock(coord.getBlockState(world), null, world, coord.getPos(), null);
ItemStack blockStack = coord.getBlock(world).getPickBlock(coord.getBlockState(world), rayTraceResult, world, coord.getPos(), null);

if(coord.exists(world) && checkID(coord.getBlock(world)) && (stack.isItemEqual(blockStack) || (coord.getBlock(world) == startBlock && MekanismUtils.getOreDictName(stack).contains("logWood") && coord.getBlockMeta(world) % 4 == stack.getItemDamage() % 4)))
{
Expand Down

0 comments on commit 4a877de

Please sign in to comment.