Add ray tracing for cable parts again
This commit is contained in:
@@ -7,6 +7,8 @@ import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.fluid.FluidStorageNBT;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.item.ItemStorageNBT;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
@@ -17,6 +19,10 @@ import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
@@ -35,6 +41,7 @@ import javax.annotation.Nullable;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.function.Function;
|
||||
@@ -276,4 +283,78 @@ public final class RSUtils {
|
||||
|
||||
return String.valueOf(qty);
|
||||
}
|
||||
|
||||
private static class AdvancedRayTraceResultBase<T extends RayTraceResult> {
|
||||
public final AxisAlignedBB bounds;
|
||||
public final T hit;
|
||||
|
||||
public AdvancedRayTraceResultBase(T mop, AxisAlignedBB bounds) {
|
||||
|
||||
this.hit = mop;
|
||||
this.bounds = bounds;
|
||||
}
|
||||
|
||||
public boolean valid() {
|
||||
return hit != null && bounds != null;
|
||||
}
|
||||
|
||||
public double squareDistanceTo(Vec3d vec) {
|
||||
return hit.hitVec.squareDistanceTo(vec);
|
||||
}
|
||||
}
|
||||
|
||||
public static class AdvancedRayTraceResult extends AdvancedRayTraceResultBase<RayTraceResult> {
|
||||
public AdvancedRayTraceResult(RayTraceResult mop, AxisAlignedBB bounds) {
|
||||
super(mop, bounds);
|
||||
}
|
||||
}
|
||||
|
||||
public static Vec3d getStart(EntityPlayer player) {
|
||||
return new Vec3d(player.posX, player.posY + player.getEyeHeight(), player.posZ);
|
||||
}
|
||||
|
||||
public static Vec3d getEnd(EntityPlayer player) {
|
||||
double reachDistance = player instanceof EntityPlayerMP ? ((EntityPlayerMP) player).interactionManager.getBlockReachDistance() : (player.capabilities.isCreativeMode ? 5.0D : 4.5D);
|
||||
|
||||
Vec3d lookVec = player.getLookVec();
|
||||
Vec3d start = getStart(player);
|
||||
|
||||
return start.addVector(lookVec.xCoord * reachDistance, lookVec.yCoord * reachDistance, lookVec.zCoord * reachDistance);
|
||||
}
|
||||
|
||||
public static AdvancedRayTraceResult collisionRayTrace(BlockPos pos, Vec3d start, Vec3d end, Collection<AxisAlignedBB> boxes) {
|
||||
double minDistance = Double.POSITIVE_INFINITY;
|
||||
AdvancedRayTraceResult hit = null;
|
||||
int i = -1;
|
||||
|
||||
for (AxisAlignedBB aabb : boxes) {
|
||||
AdvancedRayTraceResult result = aabb == null ? null : collisionRayTrace(pos, start, end, aabb, i, null);
|
||||
|
||||
if (result != null) {
|
||||
double d = result.squareDistanceTo(start);
|
||||
if (d < minDistance) {
|
||||
minDistance = d;
|
||||
hit = result;
|
||||
}
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return hit;
|
||||
}
|
||||
|
||||
public static AdvancedRayTraceResult collisionRayTrace(BlockPos pos, Vec3d start, Vec3d end, AxisAlignedBB bounds, int subHit, Object hitInfo) {
|
||||
RayTraceResult result = bounds.offset(pos).calculateIntercept(start, end);
|
||||
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
result = new RayTraceResult(RayTraceResult.Type.BLOCK, result.hitVec, result.sideHit, pos);
|
||||
result.subHit = subHit;
|
||||
result.hitInfo = hitInfo;
|
||||
|
||||
return new AdvancedRayTraceResult(result, bounds);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.raoulvdberge.refinedstorage.block;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.tile.TileCable;
|
||||
import net.minecraft.block.properties.PropertyBool;
|
||||
@@ -164,12 +165,9 @@ public class BlockCable extends BlockNode {
|
||||
|
||||
@Override
|
||||
public RayTraceResult collisionRayTrace(IBlockState state, World world, BlockPos pos, Vec3d start, Vec3d end) {
|
||||
// @TODO
|
||||
/*RayTraceUtils.AdvancedRayTraceResult result = RayTraceUtils.collisionRayTrace(world, pos, start, end, getCollisionBoxes(this.getActualState(state, world, pos)));
|
||||
RSUtils.AdvancedRayTraceResult result = RSUtils.collisionRayTrace(pos, start, end, getCollisionBoxes(this.getActualState(state, world, pos)));
|
||||
|
||||
return result != null ? result.hit : null;
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.raoulvdberge.refinedstorage.proxy;
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.RSBlocks;
|
||||
import com.raoulvdberge.refinedstorage.RSItems;
|
||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||
import com.raoulvdberge.refinedstorage.block.*;
|
||||
import com.raoulvdberge.refinedstorage.gui.GuiCraftingPreview;
|
||||
import com.raoulvdberge.refinedstorage.gui.grid.GuiCraftingStart;
|
||||
@@ -15,6 +16,7 @@ import com.raoulvdberge.refinedstorage.tile.TileController;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.VertexBuffer;
|
||||
import net.minecraft.client.renderer.block.model.ModelBakery;
|
||||
@@ -42,6 +44,8 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ProxyClient extends ProxyCommon {
|
||||
@Override
|
||||
public void preInit(FMLPreInitializationEvent e) {
|
||||
@@ -290,13 +294,11 @@ public class ProxyClient extends ProxyCommon {
|
||||
|
||||
state = ((BlockCable) state.getBlock()).getActualState(state, player.getEntityWorld(), pos);
|
||||
|
||||
// @TODO
|
||||
/*if (((BlockCable) state.getBlock()).collisionRayTrace(state, player.getEntityWorld(), pos, RayTraceUtils.getStart(player), RayTraceUtils.getEnd(player)) instanceof PartMOP) {
|
||||
if (((BlockCable) state.getBlock()).collisionRayTrace(state, player.getEntityWorld(), pos, RSUtils.getStart(player), RSUtils.getEnd(player)) == null) {
|
||||
return;
|
||||
}*/
|
||||
return;
|
||||
}
|
||||
|
||||
/*List<AxisAlignedBB> unionized = ((BlockCable) state.getBlock()).getUnionizedCollisionBoxes(state);
|
||||
List<AxisAlignedBB> unionized = ((BlockCable) state.getBlock()).getUnionizedCollisionBoxes(state);
|
||||
List<AxisAlignedBB> nonUnionized = ((BlockCable) state.getBlock()).getNonUnionizedCollisionBoxes(state);
|
||||
|
||||
e.setCanceled(true);
|
||||
@@ -304,7 +306,7 @@ public class ProxyClient extends ProxyCommon {
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
||||
GlStateManager.color(0.0F, 0.0F, 0.0F, 0.4F);
|
||||
GL11.glLineWidth(2.0F);
|
||||
GlStateManager.glLineWidth(2.0F);
|
||||
GlStateManager.disableTexture2D();
|
||||
GlStateManager.depthMask(false);
|
||||
|
||||
@@ -326,7 +328,7 @@ public class ProxyClient extends ProxyCommon {
|
||||
|
||||
GlStateManager.depthMask(true);
|
||||
GlStateManager.enableTexture2D();
|
||||
GlStateManager.disableBlend();*/
|
||||
GlStateManager.disableBlend();
|
||||
}
|
||||
|
||||
private void drawSelectionBoundingBox(AxisAlignedBB aabb) {
|
||||
|
||||
Reference in New Issue
Block a user