From 99fca02856cf0b297b02417f4fc7a7037a3cd91f Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Fri, 11 Oct 2013 19:16:57 -0700 Subject: [PATCH] Fix Pipe Raytracing + Improve Pipe interactions Closes #1246 Its now much easier and more consistent to remove specific addons from a pipe. Sneak-click with a gate to remove a gate, sneak-click with a Yellow Wire to remove a Yellow Wire, etc... Plugs can now be placed easily and simply on any side of the pipe in any configuration. Selection Box now highlights the part of the pipe you are pointing at. --- common/buildcraft/BuildCraftTransport.java | 8 +- common/buildcraft/core/CoreConstants.java | 19 + common/buildcraft/core/ItemBuildCraft.java | 30 +- .../core/render/RenderingEntityBlocks.java | 7 +- .../core/utils/MatrixTranformations.java | 73 +++ common/buildcraft/core/utils/Utils.java | 13 +- common/buildcraft/factory/BlockFrame.java | 19 +- common/buildcraft/factory/BlockPlainPipe.java | 10 +- common/buildcraft/factory/TilePump.java | 7 +- common/buildcraft/factory/TileQuarry.java | 8 +- .../silicon/SiliconRenderBlock.java | 4 +- .../transport/BlockGenericPipe.java | 576 ++++++++++-------- common/buildcraft/transport/ItemFacade.java | 48 +- common/buildcraft/transport/ItemGate.java | 1 + common/buildcraft/transport/ItemPlug.java | 48 +- common/buildcraft/transport/Pipe.java | 24 + .../transport/PipeTransportItems.java | 16 +- .../buildcraft/transport/TileGenericPipe.java | 41 +- .../transport/TransportConstants.java | 21 + .../transport/pipes/PipeItemsDaizuli.java | 10 +- .../transport/pipes/PipeItemsGold.java | 4 +- .../transport/pipes/PipeItemsLapis.java | 10 +- .../transport/pipes/PipeItemsObsidian.java | 4 +- .../transport/pipes/PipeItemsQuartz.java | 10 +- .../transport/pipes/PipeItemsStone.java | 10 +- .../transport/render/FacadeItemRenderer.java | 8 +- .../transport/render/PipeItemRenderer.java | 4 +- .../transport/render/PipeRendererTESR.java | 126 ++-- .../transport/render/PipeRendererWorld.java | 116 +--- .../transport/render/TileEntityPickupFX.java | 4 +- .../transport/utils/TransportUtils.java | 27 + 31 files changed, 763 insertions(+), 543 deletions(-) create mode 100644 common/buildcraft/core/CoreConstants.java create mode 100644 common/buildcraft/core/utils/MatrixTranformations.java create mode 100644 common/buildcraft/transport/TransportConstants.java create mode 100644 common/buildcraft/transport/utils/TransportUtils.java diff --git a/common/buildcraft/BuildCraftTransport.java b/common/buildcraft/BuildCraftTransport.java index 026a147b..6d3edfe7 100644 --- a/common/buildcraft/BuildCraftTransport.java +++ b/common/buildcraft/BuildCraftTransport.java @@ -313,28 +313,28 @@ public class BuildCraftTransport { // 1, 0), Block.glass, new ItemStack(Item.dyePowder, 1, 11)); Property redPipeWireId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "redPipeWire.id", DefaultProps.RED_PIPE_WIRE); - redPipeWire = new ItemBuildCraft(redPipeWireId.getInt()); + redPipeWire = new ItemBuildCraft(redPipeWireId.getInt()).setPassSneakClick(true); redPipeWire.setUnlocalizedName("redPipeWire"); LanguageRegistry.addName(redPipeWire, "Red Pipe Wire"); AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[]{new ItemStack(Item.dyePowder, 1, 1), new ItemStack(Item.redstone, 1), new ItemStack(Item.ingotIron, 1)}, 500, new ItemStack(redPipeWire, 8))); Property bluePipeWireId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "bluePipeWire.id", DefaultProps.BLUE_PIPE_WIRE); - bluePipeWire = new ItemBuildCraft(bluePipeWireId.getInt()); + bluePipeWire = new ItemBuildCraft(bluePipeWireId.getInt()).setPassSneakClick(true); bluePipeWire.setUnlocalizedName("bluePipeWire"); LanguageRegistry.addName(bluePipeWire, "Blue Pipe Wire"); AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[]{new ItemStack(Item.dyePowder, 1, 4), new ItemStack(Item.redstone, 1), new ItemStack(Item.ingotIron, 1)}, 500, new ItemStack(bluePipeWire, 8))); Property greenPipeWireId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "greenPipeWire.id", DefaultProps.GREEN_PIPE_WIRE); - greenPipeWire = new ItemBuildCraft(greenPipeWireId.getInt()); + greenPipeWire = new ItemBuildCraft(greenPipeWireId.getInt()).setPassSneakClick(true); greenPipeWire.setUnlocalizedName("greenPipeWire"); LanguageRegistry.addName(greenPipeWire, "Green Pipe Wire"); AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[]{new ItemStack(Item.dyePowder, 1, 2), new ItemStack(Item.redstone, 1), new ItemStack(Item.ingotIron, 1)}, 500, new ItemStack(greenPipeWire, 8))); Property yellowPipeWireId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "yellowPipeWire.id", DefaultProps.YELLOW_PIPE_WIRE); - yellowPipeWire = new ItemBuildCraft(yellowPipeWireId.getInt()); + yellowPipeWire = new ItemBuildCraft(yellowPipeWireId.getInt()).setPassSneakClick(true); yellowPipeWire.setUnlocalizedName("yellowPipeWire"); LanguageRegistry.addName(yellowPipeWire, "Yellow Pipe Wire"); AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[]{new ItemStack(Item.dyePowder, 1, 11), new ItemStack(Item.redstone, 1), diff --git a/common/buildcraft/core/CoreConstants.java b/common/buildcraft/core/CoreConstants.java new file mode 100644 index 00000000..eb9ab89d --- /dev/null +++ b/common/buildcraft/core/CoreConstants.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) SpaceToad, 2011-2012 + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package buildcraft.core; + +/** + * + * @author CovertJaguar + */ +public class CoreConstants { + + public static final float PIPE_MIN_POS = 0.25F; + public static final float PIPE_MAX_POS = 0.75F; +} diff --git a/common/buildcraft/core/ItemBuildCraft.java b/common/buildcraft/core/ItemBuildCraft.java index 42a8467b..57baa729 100644 --- a/common/buildcraft/core/ItemBuildCraft.java +++ b/common/buildcraft/core/ItemBuildCraft.java @@ -1,12 +1,10 @@ /** - * Copyright (c) SpaceToad, 2011 - * http://www.mod-buildcraft.com + * Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com * - * BuildCraft is distributed under the terms of the Minecraft Mod Public - * License 1.0, or MMPL. Please check the contents of the license located in + * BuildCraft is distributed under the terms of the Minecraft Mod Public License + * 1.0, or MMPL. Please check the contents of the license located in * http://www.mod-buildcraft.com/MMPL-1.0.txt */ - package buildcraft.core; import buildcraft.core.utils.StringUtils; @@ -15,10 +13,13 @@ import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.world.World; public class ItemBuildCraft extends Item { private String iconName; + private boolean passSneakClick = false; + public ItemBuildCraft(int i) { super(i); setCreativeTab(CreativeTabBuildCraft.tabBuildCraft); @@ -36,9 +37,18 @@ public class ItemBuildCraft extends Item { } @Override - @SideOnly(Side.CLIENT) - public void registerIcons(IconRegister par1IconRegister) - { - this.itemIcon = par1IconRegister.registerIcon("buildcraft:" + iconName); - } + @SideOnly(Side.CLIENT) + public void registerIcons(IconRegister par1IconRegister) { + this.itemIcon = par1IconRegister.registerIcon("buildcraft:" + iconName); + } + + public Item setPassSneakClick(boolean passClick) { + this.passSneakClick = passClick; + return this; + } + + @Override + public boolean shouldPassSneakingClickToBlock(World par2World, int par4, int par5, int par6) { + return passSneakClick; + } } diff --git a/common/buildcraft/core/render/RenderingEntityBlocks.java b/common/buildcraft/core/render/RenderingEntityBlocks.java index cf217e0f..cc4a8bc2 100644 --- a/common/buildcraft/core/render/RenderingEntityBlocks.java +++ b/common/buildcraft/core/render/RenderingEntityBlocks.java @@ -1,6 +1,7 @@ package buildcraft.core.render; import buildcraft.BuildCraftCore; +import buildcraft.core.CoreConstants; import buildcraft.core.IInventoryRenderer; import buildcraft.core.utils.Utils; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; @@ -57,7 +58,7 @@ public class RenderingEntityBlocks implements ISimpleBlockRenderingHandler { } else if (block.getRenderType() == BuildCraftCore.legacyPipeModel) { Tessellator tessellator = Tessellator.instance; - block.setBlockBounds(Utils.pipeMinPos, 0.0F, Utils.pipeMinPos, Utils.pipeMaxPos, 1.0F, Utils.pipeMaxPos); + block.setBlockBounds(CoreConstants.PIPE_MIN_POS, 0.0F, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, 1.0F, CoreConstants.PIPE_MAX_POS); renderer.setRenderBoundsFromBlock(block); block.setBlockBoundsForItemRender(); GL11.glTranslatef(-0.5F, -0.5F, -0.5F); @@ -116,8 +117,8 @@ public class RenderingEntityBlocks implements ISimpleBlockRenderingHandler { /* LEGACY PIPE RENDERING and quarry frames! */ private void legacyPipeRender(RenderBlocks renderblocks, IBlockAccess iblockaccess, int i, int j, int k, Block block, int l) { - float minSize = Utils.pipeMinPos; - float maxSize = Utils.pipeMaxPos; + float minSize = CoreConstants.PIPE_MIN_POS; + float maxSize = CoreConstants.PIPE_MAX_POS; block.setBlockBounds(minSize, minSize, minSize, maxSize, maxSize, maxSize); renderblocks.setRenderBoundsFromBlock(block); diff --git a/common/buildcraft/core/utils/MatrixTranformations.java b/common/buildcraft/core/utils/MatrixTranformations.java new file mode 100644 index 00000000..c5eae1a4 --- /dev/null +++ b/common/buildcraft/core/utils/MatrixTranformations.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) SpaceToad, 2011-2012 + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package buildcraft.core.utils; + +import net.minecraftforge.common.ForgeDirection; + +/** + * + * @author Krapht + */ +public class MatrixTranformations { + + /** + * Mirrors the array on the Y axis by calculating offsets from 0.5F + * + * @param targetArray + */ + public static void mirrorY(float[][] targetArray) { + float temp = targetArray[1][0]; + targetArray[1][0] = (targetArray[1][1] - 0.5F) * -1F + 0.5F; // 1 -> 0.5F -> -0.5F -> 0F + targetArray[1][1] = (temp - 0.5F) * -1F + 0.5F; // 0 -> -0.5F -> 0.5F -> 1F + } + + /** + * Shifts the coordinates around effectively rotating something. Zero state + * is DOWN then -> NORTH -> WEST Note - To obtain Position, do a mirrorY() before + * rotating + * + * @param targetArray the array that should be rotated + */ + public static void rotate(float[][] targetArray) { + for (int i = 0; i < 2; i++) { + float temp = targetArray[2][i]; + targetArray[2][i] = targetArray[1][i]; + targetArray[1][i] = targetArray[0][i]; + targetArray[0][i] = temp; + } + } + + /** + * @param targetArray the array that should be transformed + * @param direction + */ + public static void transform(float[][] targetArray, ForgeDirection direction) { + if ((direction.ordinal() & 0x1) == 1) { + mirrorY(targetArray); + } + + for (int i = 0; i < (direction.ordinal() >> 1); i++) { + rotate(targetArray); + } + } + + /** + * Clones both dimensions of a float[][] + * + * @param source the float[][] to deepClone + * @return + */ + public static float[][] deepClone(float[][] source) { + float[][] target = source.clone(); + for (int i = 0; i < target.length; i++) { + target[i] = source[i].clone(); + } + return target; + } +} diff --git a/common/buildcraft/core/utils/Utils.java b/common/buildcraft/core/utils/Utils.java index c4435fcb..435170de 100644 --- a/common/buildcraft/core/utils/Utils.java +++ b/common/buildcraft/core/utils/Utils.java @@ -47,9 +47,6 @@ import net.minecraftforge.common.ForgeDirection; public class Utils { public static final Random RANDOM = new Random(); - public static final float pipeMinPos = 0.25F; - public static final float pipeMaxPos = 0.75F; - public static float pipeNormalSpeed = 0.01F; private static final List directions = new ArrayList(Arrays.asList(ForgeDirection.VALID_DIRECTIONS)); /* IINVENTORY HELPERS */ @@ -80,14 +77,6 @@ public class Utils { } - /** - * Depending on the kind of item in the pipe, set the floor at a different - * level to optimize graphical aspect. - */ - public static float getPipeFloorOf(ItemStack item) { - return pipeMinPos; - } - public static ForgeDirection get2dOrientation(Position pos1, Position pos2) { double Dx = pos1.x - pos2.x; double Dz = pos1.z - pos2.z; @@ -338,7 +327,7 @@ public class Utils { if (tile instanceof IInventory && !CoreProxy.proxy.isRenderWorld(world)) { if (!(tile instanceof IDropControlInventory) || ((IDropControlInventory) tile).doDrop()) { InvUtils.dropItems(world, (IInventory) tile, i, j, k); - InvUtils.wipeInventory((IInventory)tile); + InvUtils.wipeInventory((IInventory) tile); } } diff --git a/common/buildcraft/factory/BlockFrame.java b/common/buildcraft/factory/BlockFrame.java index a6a155db..fa063b39 100644 --- a/common/buildcraft/factory/BlockFrame.java +++ b/common/buildcraft/factory/BlockFrame.java @@ -10,6 +10,7 @@ package buildcraft.factory; import buildcraft.BuildCraftCore; +import buildcraft.core.CoreConstants; import buildcraft.core.IFramePipeConnection; import buildcraft.core.utils.Utils; import cpw.mods.fml.relauncher.Side; @@ -69,7 +70,7 @@ public class BlockFrame extends Block implements IFramePipeConnection { @Override public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int i, int j, int k) { - float xMin = Utils.pipeMinPos, xMax = Utils.pipeMaxPos, yMin = Utils.pipeMinPos, yMax = Utils.pipeMaxPos, zMin = Utils.pipeMinPos, zMax = Utils.pipeMaxPos; + float xMin = CoreConstants.PIPE_MIN_POS, xMax = CoreConstants.PIPE_MAX_POS, yMin = CoreConstants.PIPE_MIN_POS, yMax = CoreConstants.PIPE_MAX_POS, zMin = CoreConstants.PIPE_MIN_POS, zMax = CoreConstants.PIPE_MAX_POS; if (Utils.checkLegacyPipesConnections(world, i, j, k, i - 1, j, k)) { xMin = 0.0F; @@ -107,36 +108,36 @@ public class BlockFrame extends Block implements IFramePipeConnection { @SuppressWarnings("rawtypes") @Override public void addCollisionBoxesToList(World world, int i, int j, int k, AxisAlignedBB axisalignedbb, List arraylist, Entity par7Entity) { - setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos); + setBlockBounds(CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS); super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity); if (Utils.checkLegacyPipesConnections(world, i, j, k, i - 1, j, k)) { - setBlockBounds(0.0F, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos); + setBlockBounds(0.0F, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS); super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity); } if (Utils.checkLegacyPipesConnections(world, i, j, k, i + 1, j, k)) { - setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMinPos, 1.0F, Utils.pipeMaxPos, Utils.pipeMaxPos); + setBlockBounds(CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, 1.0F, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS); super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity); } if (Utils.checkLegacyPipesConnections(world, i, j, k, i, j - 1, k)) { - setBlockBounds(Utils.pipeMinPos, 0.0F, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos); + setBlockBounds(CoreConstants.PIPE_MIN_POS, 0.0F, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS); super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity); } if (Utils.checkLegacyPipesConnections(world, i, j, k, i, j + 1, k)) { - setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, 1.0F, Utils.pipeMaxPos); + setBlockBounds(CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, 1.0F, CoreConstants.PIPE_MAX_POS); super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity); } if (Utils.checkLegacyPipesConnections(world, i, j, k, i, j, k - 1)) { - setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, 0.0F, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos); + setBlockBounds(CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, 0.0F, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS); super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity); } if (Utils.checkLegacyPipesConnections(world, i, j, k, i, j, k + 1)) { - setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMaxPos, 1.0F); + setBlockBounds(CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS, 1.0F); super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity); } @@ -145,7 +146,7 @@ public class BlockFrame extends Block implements IFramePipeConnection { @Override public MovingObjectPosition collisionRayTrace(World world, int i, int j, int k, Vec3 vec3d, Vec3 vec3d1) { - float xMin = Utils.pipeMinPos, xMax = Utils.pipeMaxPos, yMin = Utils.pipeMinPos, yMax = Utils.pipeMaxPos, zMin = Utils.pipeMinPos, zMax = Utils.pipeMaxPos; + float xMin = CoreConstants.PIPE_MIN_POS, xMax = CoreConstants.PIPE_MAX_POS, yMin = CoreConstants.PIPE_MIN_POS, yMax = CoreConstants.PIPE_MAX_POS, zMin = CoreConstants.PIPE_MIN_POS, zMax = CoreConstants.PIPE_MAX_POS; if (Utils.checkLegacyPipesConnections(world, i, j, k, i - 1, j, k)) { xMin = 0.0F; diff --git a/common/buildcraft/factory/BlockPlainPipe.java b/common/buildcraft/factory/BlockPlainPipe.java index 13a0f444..bba34558 100644 --- a/common/buildcraft/factory/BlockPlainPipe.java +++ b/common/buildcraft/factory/BlockPlainPipe.java @@ -9,8 +9,8 @@ package buildcraft.factory; +import buildcraft.core.CoreConstants; import buildcraft.core.IFramePipeConnection; -import buildcraft.core.utils.Utils; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import java.util.ArrayList; @@ -26,13 +26,13 @@ public class BlockPlainPipe extends Block implements IFramePipeConnection { public BlockPlainPipe(int i) { super(i, Material.glass); - minX = Utils.pipeMinPos; + minX = CoreConstants.PIPE_MIN_POS; minY = 0.0; - minZ = Utils.pipeMinPos; + minZ = CoreConstants.PIPE_MIN_POS; - maxX = Utils.pipeMaxPos; + maxX = CoreConstants.PIPE_MAX_POS; maxY = 1.0; - maxZ = Utils.pipeMaxPos; + maxZ = CoreConstants.PIPE_MAX_POS; } @Override diff --git a/common/buildcraft/factory/TilePump.java b/common/buildcraft/factory/TilePump.java index 04d96439..87a1b948 100644 --- a/common/buildcraft/factory/TilePump.java +++ b/common/buildcraft/factory/TilePump.java @@ -16,6 +16,7 @@ import buildcraft.api.power.PowerHandler; import buildcraft.api.power.PowerHandler.PowerReceiver; import buildcraft.api.power.PowerHandler.Type; import buildcraft.core.BlockIndex; +import buildcraft.core.CoreConstants; import buildcraft.core.EntityBlock; import buildcraft.core.IMachine; import buildcraft.core.TileBuffer; @@ -370,11 +371,11 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor private void setTubePosition() { if (tube != null) { - tube.iSize = Utils.pipeMaxPos - Utils.pipeMinPos; - tube.kSize = Utils.pipeMaxPos - Utils.pipeMinPos; + tube.iSize = CoreConstants.PIPE_MAX_POS - CoreConstants.PIPE_MIN_POS; + tube.kSize = CoreConstants.PIPE_MAX_POS - CoreConstants.PIPE_MIN_POS; tube.jSize = yCoord - tube.posY; - tube.setPosition(xCoord + Utils.pipeMinPos, tubeY, zCoord + Utils.pipeMinPos); + tube.setPosition(xCoord + CoreConstants.PIPE_MIN_POS, tubeY, zCoord + CoreConstants.PIPE_MIN_POS); } } diff --git a/common/buildcraft/factory/TileQuarry.java b/common/buildcraft/factory/TileQuarry.java index 837f18b6..a995dc71 100644 --- a/common/buildcraft/factory/TileQuarry.java +++ b/common/buildcraft/factory/TileQuarry.java @@ -11,7 +11,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Set; -import net.minecraft.block.Block; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -33,6 +32,7 @@ import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.PowerHandler; import buildcraft.api.power.PowerHandler.PowerReceiver; import buildcraft.core.Box; +import buildcraft.core.CoreConstants; import buildcraft.core.DefaultAreaProvider; import buildcraft.core.EntityRobot; import buildcraft.core.IBuilderInventory; @@ -128,9 +128,9 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept private void createArm() { - worldObj.spawnEntityInWorld(new EntityMechanicalArm(worldObj, box.xMin + Utils.pipeMaxPos, yCoord + bluePrintBuilder.bluePrint.sizeY - 1 - + Utils.pipeMinPos, box.zMin + Utils.pipeMaxPos, bluePrintBuilder.bluePrint.sizeX - 2 + Utils.pipeMinPos * 2, bluePrintBuilder.bluePrint.sizeZ - - 2 + Utils.pipeMinPos * 2, this)); + worldObj.spawnEntityInWorld(new EntityMechanicalArm(worldObj, box.xMin + CoreConstants.PIPE_MAX_POS, yCoord + bluePrintBuilder.bluePrint.sizeY - 1 + + CoreConstants.PIPE_MIN_POS, box.zMin + CoreConstants.PIPE_MAX_POS, bluePrintBuilder.bluePrint.sizeX - 2 + CoreConstants.PIPE_MIN_POS * 2, bluePrintBuilder.bluePrint.sizeZ + - 2 + CoreConstants.PIPE_MIN_POS * 2, this)); } // Callback from the arm once it's created diff --git a/common/buildcraft/silicon/SiliconRenderBlock.java b/common/buildcraft/silicon/SiliconRenderBlock.java index 0732e9e6..fcb1f0f8 100644 --- a/common/buildcraft/silicon/SiliconRenderBlock.java +++ b/common/buildcraft/silicon/SiliconRenderBlock.java @@ -9,7 +9,7 @@ package buildcraft.silicon; -import buildcraft.core.utils.Utils; +import buildcraft.core.CoreConstants; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import net.minecraft.block.Block; import net.minecraft.client.renderer.RenderBlocks; @@ -121,7 +121,7 @@ public class SiliconRenderBlock implements ISimpleBlockRenderingHandler { @Override public void renderInventoryBlock(Block block, int i, int j, RenderBlocks renderblocks) { - block.setBlockBounds(Utils.pipeMinPos, 0.0F, Utils.pipeMinPos, Utils.pipeMaxPos, 1.0F, Utils.pipeMaxPos); + block.setBlockBounds(CoreConstants.PIPE_MIN_POS, 0.0F, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, 1.0F, CoreConstants.PIPE_MAX_POS); GL11.glTranslatef(-0.5F, -0.5F, -0.5F); block.setBlockBounds(0.0F, 0.0F, 0.0F, 1, 4F / 16F, 1); diff --git a/common/buildcraft/transport/BlockGenericPipe.java b/common/buildcraft/transport/BlockGenericPipe.java index 15d05963..f1e6d8ee 100644 --- a/common/buildcraft/transport/BlockGenericPipe.java +++ b/common/buildcraft/transport/BlockGenericPipe.java @@ -40,30 +40,45 @@ import buildcraft.api.tools.IToolWrench; import buildcraft.api.transport.IPipe; import buildcraft.api.transport.ISolidSideTile; import buildcraft.core.BlockIndex; +import buildcraft.core.CoreConstants; import buildcraft.core.proxy.CoreProxy; import buildcraft.core.utils.Utils; -import buildcraft.transport.render.PipeRendererWorld; +import buildcraft.core.utils.MatrixTranformations; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import java.util.Arrays; +import net.minecraft.client.Minecraft; public class BlockGenericPipe extends BlockContainer { static enum Part { Pipe, - Gate + Gate, + Facade, + Plug } static class RaytraceResult { - RaytraceResult(Part hitPart, MovingObjectPosition movingObjectPosition) { + RaytraceResult(Part hitPart, MovingObjectPosition movingObjectPosition, AxisAlignedBB boundingBox, ForgeDirection side) { this.hitPart = hitPart; this.movingObjectPosition = movingObjectPosition; + this.boundingBox = boundingBox; + this.sideHit = side; + } + public final Part hitPart; + public final MovingObjectPosition movingObjectPosition; + public final AxisAlignedBB boundingBox; + public final ForgeDirection sideHit; + + @Override + public String toString() { + return String.format("RayTraceResult: %s, %s", hitPart == null ? "null" : hitPart.name(), boundingBox == null ? "null" : boundingBox.toString()); } - public Part hitPart; - public MovingObjectPosition movingObjectPosition; } + private static final ForgeDirection[] DIR_VALUES = ForgeDirection.values(); private static Random rand = new Random(); private boolean skippedFirstIconRegister; private char renderAxis = 'a'; @@ -130,7 +145,7 @@ public class BlockGenericPipe extends BlockContainer { @SuppressWarnings("rawtypes") @Override public void addCollisionBoxesToList(World world, int i, int j, int k, AxisAlignedBB axisalignedbb, List arraylist, Entity par7Entity) { - setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos); + setBlockBounds(CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS); super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity); TileEntity tile1 = world.getBlockTileEntity(i, j, k); @@ -138,36 +153,36 @@ public class BlockGenericPipe extends BlockContainer { TileGenericPipe tileG = (TileGenericPipe) tile1; if (tileG.isPipeConnected(ForgeDirection.WEST)) { - setBlockBounds(0.0F, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos); + setBlockBounds(0.0F, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS); super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity); } if (tileG.isPipeConnected(ForgeDirection.EAST)) { - setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMinPos, 1.0F, Utils.pipeMaxPos, Utils.pipeMaxPos); + setBlockBounds(CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, 1.0F, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS); super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity); } if (tileG.isPipeConnected(ForgeDirection.DOWN)) { - setBlockBounds(Utils.pipeMinPos, 0.0F, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos); + setBlockBounds(CoreConstants.PIPE_MIN_POS, 0.0F, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS); super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity); } if (tileG.isPipeConnected(ForgeDirection.UP)) { - setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, 1.0F, Utils.pipeMaxPos); + setBlockBounds(CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, 1.0F, CoreConstants.PIPE_MAX_POS); super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity); } if (tileG.isPipeConnected(ForgeDirection.NORTH)) { - setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, 0.0F, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos); + setBlockBounds(CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, 0.0F, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS); super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity); } if (tileG.isPipeConnected(ForgeDirection.SOUTH)) { - setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMaxPos, 1.0F); + setBlockBounds(CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS, 1.0F); super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity); } - float facadeThickness = PipeRendererWorld.facadeThickness; + float facadeThickness = TransportConstants.FACADE_THICKNESS; if (tileG.hasFacade(ForgeDirection.EAST)) { setBlockBounds(1 - facadeThickness, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); @@ -202,61 +217,29 @@ public class BlockGenericPipe extends BlockContainer { setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); } + @SideOnly(Side.CLIENT) @Override - public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int i, int j, int k) { - float xMin = Utils.pipeMinPos, xMax = Utils.pipeMaxPos, yMin = Utils.pipeMinPos, yMax = Utils.pipeMaxPos, zMin = Utils.pipeMinPos, zMax = Utils.pipeMaxPos; + public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) { + RaytraceResult rayTraceResult = doRayTrace(world, x, y, z, Minecraft.getMinecraft().thePlayer); - TileEntity tile1 = world.getBlockTileEntity(i, j, k); - - if (tile1 instanceof TileGenericPipe) { - TileGenericPipe tileG = (TileGenericPipe) tile1; - if (tileG.isPipeConnected(ForgeDirection.WEST) || tileG.hasFacade(ForgeDirection.WEST)) { - xMin = 0.0F; - } - - if (tileG.isPipeConnected(ForgeDirection.EAST) || tileG.hasFacade(ForgeDirection.EAST)) { - xMax = 1.0F; - } - - if (tileG.isPipeConnected(ForgeDirection.DOWN) || tileG.hasFacade(ForgeDirection.DOWN)) { - yMin = 0.0F; - } - - if (tileG.isPipeConnected(ForgeDirection.UP) || tileG.hasFacade(ForgeDirection.UP)) { - yMax = 1.0F; - } - - if (tileG.isPipeConnected(ForgeDirection.NORTH) || tileG.hasFacade(ForgeDirection.NORTH)) { - zMin = 0.0F; - } - - if (tileG.isPipeConnected(ForgeDirection.SOUTH) || tileG.hasFacade(ForgeDirection.SOUTH)) { - zMax = 1.0F; - } - - if (tileG.hasFacade(ForgeDirection.EAST) || tileG.hasFacade(ForgeDirection.WEST)) { - yMin = 0.0F; - yMax = 1.0F; - zMin = 0.0F; - zMax = 1.0F; - } - - if (tileG.hasFacade(ForgeDirection.UP) || tileG.hasFacade(ForgeDirection.DOWN)) { - xMin = 0.0F; - xMax = 1.0F; - zMin = 0.0F; - zMax = 1.0F; - } - - if (tileG.hasFacade(ForgeDirection.SOUTH) || tileG.hasFacade(ForgeDirection.NORTH)) { - xMin = 0.0F; - xMax = 1.0F; - yMin = 0.0F; - yMax = 1.0F; + if (rayTraceResult != null && rayTraceResult.boundingBox != null) { + AxisAlignedBB box = rayTraceResult.boundingBox; + switch (rayTraceResult.hitPart) { + case Gate: + case Plug: { + float scale = 0.001F; + box = box.expand(scale, scale, scale); + break; + } + case Pipe: { + float scale = 0.08F; + box = box.expand(scale, scale, scale); + break; + } } + return box.getOffsetBoundingBox(x, y, z); } - - return AxisAlignedBB.getBoundingBox((double) i + xMin, (double) j + yMin, (double) k + zMin, (double) i + xMax, (double) j + yMax, (double) k + zMax); + return super.getSelectedBoundingBoxFromPool(world, x, y, z).expand(-0.85F, -0.85F, -0.85F); } @Override @@ -291,8 +274,6 @@ public class BlockGenericPipe extends BlockContainer { } private RaytraceResult doRayTrace(World world, int x, int y, int z, Vec3 origin, Vec3 direction) { - float xMin = Utils.pipeMinPos, xMax = Utils.pipeMaxPos, yMin = Utils.pipeMinPos, yMax = Utils.pipeMaxPos, zMin = Utils.pipeMinPos, zMax = Utils.pipeMaxPos; - TileEntity pipeTileEntity = world.getBlockTileEntity(x, y, z); TileGenericPipe tileG = null; @@ -311,96 +292,60 @@ public class BlockGenericPipe extends BlockContainer { * pipe hits along x, y, and z axis, gate (all 6 sides) [and * wires+facades] */ - MovingObjectPosition[] hits = new MovingObjectPosition[9]; + MovingObjectPosition[] hits = new MovingObjectPosition[25]; + AxisAlignedBB[] boxes = new AxisAlignedBB[25]; + ForgeDirection[] sideHit = new ForgeDirection[25]; + Arrays.fill(sideHit, ForgeDirection.UNKNOWN); - boolean needAxisCheck = false; - boolean needCenterCheck = true; + // pipe - // check along the x axis - - if (tileG.isPipeConnected(ForgeDirection.WEST)) { - xMin = 0.0F; - needAxisCheck = true; - } - - if (tileG.isPipeConnected(ForgeDirection.WEST)) { - xMax = 1.0F; - needAxisCheck = true; - } - - if (needAxisCheck) { - setBlockBounds(xMin, yMin, zMin, xMax, yMax, zMax); - - hits[0] = super.collisionRayTrace(world, x, y, z, origin, direction); - xMin = Utils.pipeMinPos; - xMax = Utils.pipeMaxPos; - needAxisCheck = false; - needCenterCheck = false; // center already checked through this axis - } - - // check along the y axis - - if (tileG.isPipeConnected(ForgeDirection.DOWN)) { - yMin = 0.0F; - needAxisCheck = true; - } - - if (tileG.isPipeConnected(ForgeDirection.UP)) { - yMax = 1.0F; - needAxisCheck = true; - } - - if (needAxisCheck) { - setBlockBounds(xMin, yMin, zMin, xMax, yMax, zMax); - - hits[1] = super.collisionRayTrace(world, x, y, z, origin, direction); - yMin = Utils.pipeMinPos; - yMax = Utils.pipeMaxPos; - needAxisCheck = false; - needCenterCheck = false; // center already checked through this axis - } - - // check along the z axis - - if (tileG.isPipeConnected(ForgeDirection.NORTH)) { - zMin = 0.0F; - needAxisCheck = true; - } - - if (tileG.isPipeConnected(ForgeDirection.SOUTH)) { - zMax = 1.0F; - needAxisCheck = true; - } - - if (needAxisCheck) { - setBlockBounds(xMin, yMin, zMin, xMax, yMax, zMax); - - hits[2] = super.collisionRayTrace(world, x, y, z, origin, direction); - zMin = Utils.pipeMinPos; - zMax = Utils.pipeMaxPos; - needAxisCheck = false; - needCenterCheck = false; // center already checked through this axis - } - - // check center (only if no axis were checked/the pipe has no connections) - - if (needCenterCheck) { - setBlockBounds(xMin, yMin, zMin, xMax, yMax, zMax); - - hits[0] = super.collisionRayTrace(world, x, y, z, origin, direction); + for (ForgeDirection side : DIR_VALUES) { + if (side == ForgeDirection.UNKNOWN || tileG.isPipeConnected(side)) { + AxisAlignedBB bb = getPipeBoundingBox(side); + setBlockBounds(bb); + boxes[side.ordinal()] = bb; + hits[side.ordinal()] = super.collisionRayTrace(world, x, y, z, origin, direction); + sideHit[side.ordinal()] = side; + } } // gates - if (pipe.hasGate()) { - for (int side = 0; side < 6; side++) { - setBlockBoundsToGate(ForgeDirection.VALID_DIRECTIONS[side]); - - hits[3 + side] = super.collisionRayTrace(world, x, y, z, origin, direction); + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + if (pipe.hasGate(side)) { + AxisAlignedBB bb = getGateBoundingBox(side); + setBlockBounds(bb); + boxes[7 + side.ordinal()] = bb; + hits[7 + side.ordinal()] = super.collisionRayTrace(world, x, y, z, origin, direction); + sideHit[7 + side.ordinal()] = side; } } - // TODO: check wires, facades + // facades + + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + if (tileG.hasFacade(side)) { + AxisAlignedBB bb = getFacadeBoundingBox(side); + setBlockBounds(bb); + boxes[13 + side.ordinal()] = bb; + hits[13 + side.ordinal()] = super.collisionRayTrace(world, x, y, z, origin, direction); + sideHit[13 + side.ordinal()] = side; + } + } + + // plugs + + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + if (tileG.hasPlug(side)) { + AxisAlignedBB bb = getPlugBoundingBox(side); + setBlockBounds(bb); + boxes[19 + side.ordinal()] = bb; + hits[19 + side.ordinal()] = super.collisionRayTrace(world, x, y, z, origin, direction); + sideHit[19 + side.ordinal()] = side; + } + } + + // TODO: check wires // get closest hit @@ -429,41 +374,96 @@ public class BlockGenericPipe extends BlockContainer { } else { Part hitPart; - if (minIndex < 3) { + if (minIndex < 7) { hitPart = Part.Pipe; - } else { + } else if (minIndex < 13) { hitPart = Part.Gate; + } else if (minIndex < 19) { + hitPart = Part.Facade; + } else { + hitPart = Part.Plug; } - return new RaytraceResult(hitPart, hits[minIndex]); + return new RaytraceResult(hitPart, hits[minIndex], boxes[minIndex], sideHit[minIndex]); } } - private void setBlockBoundsToGate(ForgeDirection dir) { - float min = Utils.pipeMinPos + 0.05F; - float max = Utils.pipeMaxPos - 0.05F; + private void setBlockBounds(AxisAlignedBB bb) { + setBlockBounds((float) bb.minX, (float) bb.minY, (float) bb.minZ, (float) bb.maxX, (float) bb.maxY, (float) bb.maxZ); + } - switch (dir) { - case DOWN: - setBlockBounds(min, Utils.pipeMinPos - 0.10F, min, max, Utils.pipeMinPos, max); - break; - case UP: - setBlockBounds(min, Utils.pipeMaxPos, min, max, Utils.pipeMaxPos + 0.10F, max); - break; - case NORTH: - setBlockBounds(min, min, Utils.pipeMinPos - 0.10F, max, max, Utils.pipeMinPos); - break; - case SOUTH: - setBlockBounds(min, min, Utils.pipeMaxPos, max, max, Utils.pipeMaxPos + 0.10F); - break; - case WEST: - setBlockBounds(Utils.pipeMinPos - 0.10F, min, min, Utils.pipeMinPos, max, max); - break; - default: - case EAST: - setBlockBounds(Utils.pipeMaxPos, min, min, Utils.pipeMaxPos + 0.10F, max, max); - break; + private AxisAlignedBB getGateBoundingBox(ForgeDirection side) { + float min = CoreConstants.PIPE_MIN_POS + 0.05F; + float max = CoreConstants.PIPE_MAX_POS - 0.05F; + + float[][] bounds = new float[3][2]; + // X START - END + bounds[0][0] = min; + bounds[0][1] = max; + // Y START - END + bounds[1][0] = CoreConstants.PIPE_MIN_POS - 0.10F; + bounds[1][1] = CoreConstants.PIPE_MIN_POS; + // Z START - END + bounds[2][0] = min; + bounds[2][1] = max; + + MatrixTranformations.transform(bounds, side); + return AxisAlignedBB.getAABBPool().getAABB(bounds[0][0], bounds[1][0], bounds[2][0], bounds[0][1], bounds[1][1], bounds[2][1]); + } + + private AxisAlignedBB getFacadeBoundingBox(ForgeDirection side) { + float[][] bounds = new float[3][2]; + // X START - END + bounds[0][0] = 0.0F; + bounds[0][1] = 1.0F; + // Y START - END + bounds[1][0] = 0.0F; + bounds[1][1] = TransportConstants.FACADE_THICKNESS; + // Z START - END + bounds[2][0] = 0.0F; + bounds[2][1] = 1.0F; + + MatrixTranformations.transform(bounds, side); + return AxisAlignedBB.getAABBPool().getAABB(bounds[0][0], bounds[1][0], bounds[2][0], bounds[0][1], bounds[1][1], bounds[2][1]); + } + + private AxisAlignedBB getPlugBoundingBox(ForgeDirection side) { + float[][] bounds = new float[3][2]; + // X START - END + bounds[0][0] = 0.25F; + bounds[0][1] = 0.75F; + // Y START - END + bounds[1][0] = 0.125F; + bounds[1][1] = 0.251F; + // Z START - END + bounds[2][0] = 0.25F; + bounds[2][1] = 0.75F; + + MatrixTranformations.transform(bounds, side); + return AxisAlignedBB.getAABBPool().getAABB(bounds[0][0], bounds[1][0], bounds[2][0], bounds[0][1], bounds[1][1], bounds[2][1]); + } + + private AxisAlignedBB getPipeBoundingBox(ForgeDirection side) { + float min = CoreConstants.PIPE_MIN_POS; + float max = CoreConstants.PIPE_MAX_POS; + + if (side == ForgeDirection.UNKNOWN) { + return AxisAlignedBB.getAABBPool().getAABB(min, min, min, max, max, max); } + + float[][] bounds = new float[3][2]; + // X START - END + bounds[0][0] = min; + bounds[0][1] = max; + // Y START - END + bounds[1][0] = 0; + bounds[1][1] = min; + // Z START - END + bounds[2][0] = min; + bounds[2][1] = max; + + MatrixTranformations.transform(bounds, side); + return AxisAlignedBB.getAABBPool().getAABB(bounds[0][0], bounds[1][0], bounds[2][0], bounds[0][1], bounds[1][1], bounds[2][1]); } public static void removePipe(Pipe pipe) { @@ -619,91 +619,65 @@ public class BlockGenericPipe extends BlockContainer { Pipe pipe = getPipe(world, x, y, z); if (isValid(pipe)) { + ItemStack currentItem = player.getCurrentEquippedItem(); - // / Right click while sneaking without wrench to strip equipment + // Right click while sneaking with empty hand to strip equipment // from the pipe. - if (player.isSneaking() - && (player.getCurrentEquippedItem() == null || !(player.getCurrentEquippedItem().getItem() instanceof IToolWrench))) { - - if (pipe.hasGate() || pipe.isWired()) - return stripEquipment(pipe); - - } else if (player.getCurrentEquippedItem() == null) { + if (player.isSneaking() && currentItem == null) { + if (stripEquipment(world, x, y, z, player, pipe)) + return true; + } else if (currentItem == null) { // Fall through the end of the test - } else if (player.getCurrentEquippedItem().itemID == Item.sign.itemID) + } else if (currentItem.itemID == Item.sign.itemID) // Sign will be placed anyway, so lets show the sign gui return false; - else if (player.getCurrentEquippedItem().getItem() instanceof ItemPipe) + else if (currentItem.getItem() instanceof ItemPipe) return false; - else if (player.getCurrentEquippedItem().getItem() instanceof IToolWrench) + else if (currentItem.getItem() instanceof IToolWrench) // Only check the instance at this point. Call the IToolWrench // interface callbacks for the individual pipe/logic calls return pipe.blockActivated(player); - else if (player.getCurrentEquippedItem().getItem() == BuildCraftTransport.redPipeWire) { - if (!pipe.wireSet[IPipe.WireColor.Red.ordinal()]) { - pipe.wireSet[IPipe.WireColor.Red.ordinal()] = true; - if (!player.capabilities.isCreativeMode) { - player.getCurrentEquippedItem().splitStack(1); - } - pipe.signalStrength[IPipe.WireColor.Red.ordinal()] = 0; - pipe.container.scheduleNeighborChange(); + else if (currentItem.getItem() == BuildCraftTransport.redPipeWire) { + if (addOrStripWire(player, pipe, IPipe.WireColor.Red)) { return true; } - } else if (player.getCurrentEquippedItem().getItem() == BuildCraftTransport.bluePipeWire) { - if (!pipe.wireSet[IPipe.WireColor.Blue.ordinal()]) { - pipe.wireSet[IPipe.WireColor.Blue.ordinal()] = true; - if (!player.capabilities.isCreativeMode) { - player.getCurrentEquippedItem().splitStack(1); - } - pipe.signalStrength[IPipe.WireColor.Blue.ordinal()] = 0; - pipe.container.scheduleNeighborChange(); + } else if (currentItem.getItem() == BuildCraftTransport.bluePipeWire) { + if (addOrStripWire(player, pipe, IPipe.WireColor.Blue)) { return true; } - } else if (player.getCurrentEquippedItem().getItem() == BuildCraftTransport.greenPipeWire) { - if (!pipe.wireSet[IPipe.WireColor.Green.ordinal()]) { - pipe.wireSet[IPipe.WireColor.Green.ordinal()] = true; - if (!player.capabilities.isCreativeMode) { - player.getCurrentEquippedItem().splitStack(1); - } - pipe.signalStrength[IPipe.WireColor.Green.ordinal()] = 0; - pipe.container.scheduleNeighborChange(); + } else if (currentItem.getItem() == BuildCraftTransport.greenPipeWire) { + if (addOrStripWire(player, pipe, IPipe.WireColor.Green)) { return true; } - } else if (player.getCurrentEquippedItem().getItem() == BuildCraftTransport.yellowPipeWire) { - if (!pipe.wireSet[IPipe.WireColor.Yellow.ordinal()]) { - pipe.wireSet[IPipe.WireColor.Yellow.ordinal()] = true; - if (!player.capabilities.isCreativeMode) { - player.getCurrentEquippedItem().splitStack(1); - } - pipe.signalStrength[IPipe.WireColor.Yellow.ordinal()] = 0; - pipe.container.scheduleNeighborChange(); + } else if (currentItem.getItem() == BuildCraftTransport.yellowPipeWire) { + if (addOrStripWire(player, pipe, IPipe.WireColor.Yellow)) { return true; } - } else if (player.getCurrentEquippedItem().itemID == BuildCraftTransport.pipeGate.itemID - || player.getCurrentEquippedItem().itemID == BuildCraftTransport.pipeGateAutarchic.itemID) - if (!pipe.hasGate()) { - - pipe.gate = Gate.makeGate(pipe, player.getCurrentEquippedItem()); - if (!player.capabilities.isCreativeMode) { - player.getCurrentEquippedItem().splitStack(1); - } - pipe.container.scheduleRenderUpdate(); + } else if (currentItem.getItem() instanceof ItemGate) { + if (addOrStripGate(world, x, y, z, player, pipe)) { + return true; + } + } else if (currentItem.getItem() instanceof ItemPlug) { + if (addOrStripPlug(world, x, y, z, player, ForgeDirection.getOrientation(side), pipe)) { + return true; + } + } else if (currentItem.getItem() instanceof ItemFacade) + if (addOrStripFacade(world, x, y, z, player, ForgeDirection.getOrientation(side), pipe)) { return true; } - boolean openGateGui = false; + boolean clickedOnGate = false; if (pipe.hasGate()) { RaytraceResult rayTraceResult = doRayTrace(world, x, y, z, player); if (rayTraceResult != null && rayTraceResult.hitPart == Part.Gate) { - openGateGui = true; + clickedOnGate = true; } } - if (openGateGui) { + if (clickedOnGate) { pipe.gate.openGui(player); - return true; } else return pipe.blockActivated(player); @@ -712,22 +686,32 @@ public class BlockGenericPipe extends BlockContainer { return false; } - private boolean stripEquipment(Pipe pipe) { - - // Try to strip wires first, starting with yellow. - for (IPipe.WireColor color : IPipe.WireColor.values()) { - if (pipe.wireSet[color.reverse().ordinal()]) { - if (!CoreProxy.proxy.isRenderWorld(pipe.container.worldObj)) { - dropWire(color.reverse(), pipe); - } - pipe.wireSet[color.reverse().ordinal()] = false; - // pipe.worldObj.markBlockNeedsUpdate(pipe.xCoord, pipe.yCoord, pipe.zCoord); - pipe.container.scheduleRenderUpdate(); - return true; + private boolean addOrStripGate(World world, int x, int y, int z, EntityPlayer player, Pipe pipe) { + if (addGate(player, pipe)) + return true; + if (player.isSneaking()) { + RaytraceResult rayTraceResult = doRayTrace(world, x, y, z, player); + if (rayTraceResult != null && rayTraceResult.hitPart == Part.Facade) { + if (stripGate(pipe)) + return true; } } + return false; + } - // Try to strip gate next + private boolean addGate(EntityPlayer player, Pipe pipe) { + if (!pipe.hasGate()) { + pipe.gate = Gate.makeGate(pipe, player.getCurrentEquippedItem()); + if (!player.capabilities.isCreativeMode) { + player.getCurrentEquippedItem().splitStack(1); + } + pipe.container.scheduleRenderUpdate(); + return true; + } + return false; + } + + private boolean stripGate(Pipe pipe) { if (pipe.hasGate()) { if (!CoreProxy.proxy.isRenderWorld(pipe.container.worldObj)) { pipe.gate.dropGate(); @@ -735,10 +719,116 @@ public class BlockGenericPipe extends BlockContainer { pipe.resetGate(); return true; } - return false; } + private boolean addOrStripWire(EntityPlayer player, Pipe pipe, IPipe.WireColor color) { + if (addWire(pipe, color)) { + if (!player.capabilities.isCreativeMode) { + player.getCurrentEquippedItem().splitStack(1); + } + return true; + } + return player.isSneaking() && stripWire(pipe, color); + } + + private boolean addWire(Pipe pipe, IPipe.WireColor color) { + if (!pipe.wireSet[color.ordinal()]) { + pipe.wireSet[color.ordinal()] = true; + pipe.signalStrength[color.ordinal()] = 0; + pipe.container.scheduleNeighborChange(); + return true; + } + return false; + } + + private boolean stripWire(Pipe pipe, IPipe.WireColor color) { + if (pipe.wireSet[color.ordinal()]) { + if (!CoreProxy.proxy.isRenderWorld(pipe.container.worldObj)) { + dropWire(color, pipe); + } + pipe.wireSet[color.ordinal()] = false; + pipe.container.scheduleRenderUpdate(); + return true; + } + return false; + } + + private boolean addOrStripFacade(World world, int x, int y, int z, EntityPlayer player, ForgeDirection side, Pipe pipe) { + if (player.isSneaking()) { + RaytraceResult rayTraceResult = doRayTrace(world, x, y, z, player); + if (rayTraceResult != null && rayTraceResult.hitPart == Part.Facade) { + if (stripFacade(pipe, rayTraceResult.sideHit)) + return true; + } + } + if (addFacade(player, pipe, side)) + return true; + return false; + } + + private boolean addFacade(EntityPlayer player, Pipe pipe, ForgeDirection side) { + ItemStack stack = player.getCurrentEquippedItem(); + if (pipe.container.addFacade(side, ItemFacade.getBlockId(stack), ItemFacade.getMetaData(stack))) { + if (!player.capabilities.isCreativeMode) { + stack.stackSize--; + } + return true; + } + return false; + } + + private boolean stripFacade(Pipe pipe, ForgeDirection side) { + return pipe.container.dropFacade(side); + } + + private boolean addOrStripPlug(World world, int x, int y, int z, EntityPlayer player, ForgeDirection side, Pipe pipe) { + RaytraceResult rayTraceResult = doRayTrace(world, x, y, z, player); + if (player.isSneaking()) { + if (rayTraceResult != null && rayTraceResult.hitPart == Part.Plug) { + if (stripPlug(pipe, rayTraceResult.sideHit)) + return true; + } + } + if (rayTraceResult != null && rayTraceResult.hitPart == Part.Pipe) { + if (addPlug(player, pipe, rayTraceResult.sideHit != null && rayTraceResult.sideHit != ForgeDirection.UNKNOWN ? rayTraceResult.sideHit : side)) + return true; + } + return false; + } + + private boolean addPlug(EntityPlayer player, Pipe pipe, ForgeDirection side) { + ItemStack stack = player.getCurrentEquippedItem(); + if (pipe.container.addPlug(side)) { + if (!player.capabilities.isCreativeMode) { + stack.stackSize--; + } + return true; + } + return false; + } + + private boolean stripPlug(Pipe pipe, ForgeDirection side) { + return pipe.container.removeAndDropPlug(side); + } + + private boolean stripEquipment(World world, int x, int y, int z, EntityPlayer player, Pipe pipe) { + // Try to strip facades first + RaytraceResult rayTraceResult = doRayTrace(world, x, y, z, player); + if (rayTraceResult != null && rayTraceResult.hitPart == Part.Facade) { + if (stripFacade(pipe, rayTraceResult.sideHit)) + return true; + } + + // Try to strip wires second, starting with yellow. + for (IPipe.WireColor color : IPipe.WireColor.values()) { + if (stripWire(pipe, color)) + return true; + } + + return stripGate(pipe); + } + /** * Drops a pipe wire item of the passed color. * diff --git a/common/buildcraft/transport/ItemFacade.java b/common/buildcraft/transport/ItemFacade.java index e74b70ca..67ecc66a 100644 --- a/common/buildcraft/transport/ItemFacade.java +++ b/common/buildcraft/transport/ItemFacade.java @@ -71,30 +71,30 @@ public class ItemFacade extends ItemBuildCraft { } } - @Override - public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World worldObj, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { - if (worldObj.isRemote) - return false; - TileEntity tile = worldObj.getBlockTileEntity(x, y, z); - if (!(tile instanceof TileGenericPipe)) - return false; - TileGenericPipe pipeTile = (TileGenericPipe) tile; - - if (player.isSneaking()) { // Strip facade - if (!pipeTile.hasFacade(ForgeDirection.VALID_DIRECTIONS[side])) - return false; - pipeTile.dropFacade(ForgeDirection.VALID_DIRECTIONS[side]); - return true; - } else { - if (((TileGenericPipe) tile).addFacade(ForgeDirection.values()[side], ItemFacade.getBlockId(stack), ItemFacade.getMetaData(stack))) { - if (!player.capabilities.isCreativeMode) { - stack.stackSize--; - } - return true; - } - return false; - } - } +// @Override +// public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World worldObj, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { +// if (worldObj.isRemote) +// return false; +// TileEntity tile = worldObj.getBlockTileEntity(x, y, z); +// if (!(tile instanceof TileGenericPipe)) +// return false; +// TileGenericPipe pipeTile = (TileGenericPipe) tile; +// +// if (player.isSneaking()) { // Strip facade +// if (!pipeTile.hasFacade(ForgeDirection.VALID_DIRECTIONS[side])) +// return false; +// pipeTile.dropFacade(ForgeDirection.VALID_DIRECTIONS[side]); +// return true; +// } else { +// if (((TileGenericPipe) tile).addFacade(ForgeDirection.values()[side], ItemFacade.getBlockId(stack), ItemFacade.getMetaData(stack))) { +// if (!player.capabilities.isCreativeMode) { +// stack.stackSize--; +// } +// return true; +// } +// return false; +// } +// } public static void initialize() { for (Field f : Block.class.getDeclaredFields()) { diff --git a/common/buildcraft/transport/ItemGate.java b/common/buildcraft/transport/ItemGate.java index 43c0ba7e..62ef67f7 100644 --- a/common/buildcraft/transport/ItemGate.java +++ b/common/buildcraft/transport/ItemGate.java @@ -46,6 +46,7 @@ public class ItemGate extends ItemBuildCraft { setHasSubtypes(true); setMaxDamage(0); setCreativeTab(CreativeTabBuildCraft.tabBuildCraft); + setPassSneakClick(true); } @SuppressWarnings({ "all" }) diff --git a/common/buildcraft/transport/ItemPlug.java b/common/buildcraft/transport/ItemPlug.java index f819d006..46498201 100644 --- a/common/buildcraft/transport/ItemPlug.java +++ b/common/buildcraft/transport/ItemPlug.java @@ -23,30 +23,30 @@ public class ItemPlug extends ItemBuildCraft { return "item.PipePlug"; } - @Override - public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World worldObj, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { - if (worldObj.isRemote) - return false; - TileEntity tile = worldObj.getBlockTileEntity(x, y, z); - if (!(tile instanceof TileGenericPipe)) - return false; - TileGenericPipe pipeTile = (TileGenericPipe) tile; - - if (player.isSneaking()) { // Strip plug - if (!pipeTile.hasPlug(ForgeDirection.VALID_DIRECTIONS[side])) - return false; - pipeTile.removeAndDropPlug(ForgeDirection.VALID_DIRECTIONS[side]); - return true; - } else { - if (((TileGenericPipe) tile).addPlug(ForgeDirection.VALID_DIRECTIONS[side])){ - if (!player.capabilities.isCreativeMode) { - stack.stackSize--; - } - return true; - } - return false; - } - } +// @Override +// public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World worldObj, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { +// if (worldObj.isRemote) +// return false; +// TileEntity tile = worldObj.getBlockTileEntity(x, y, z); +// if (!(tile instanceof TileGenericPipe)) +// return false; +// TileGenericPipe pipeTile = (TileGenericPipe) tile; +// +// if (player.isSneaking()) { // Strip plug +// if (!pipeTile.hasPlug(ForgeDirection.VALID_DIRECTIONS[side])) +// return false; +// pipeTile.removeAndDropPlug(ForgeDirection.VALID_DIRECTIONS[side]); +// return true; +// } else { +// if (((TileGenericPipe) tile).addPlug(ForgeDirection.VALID_DIRECTIONS[side])){ +// if (!player.capabilities.isCreativeMode) { +// stack.stackSize--; +// } +// return true; +// } +// return false; +// } +// } @Override public boolean shouldPassSneakingClickToBlock(World worldObj, int x, int y, int z ) { diff --git a/common/buildcraft/transport/Pipe.java b/common/buildcraft/transport/Pipe.java index 6fd1043a..bfdf4955 100644 --- a/common/buildcraft/transport/Pipe.java +++ b/common/buildcraft/transport/Pipe.java @@ -365,6 +365,30 @@ public abstract class Pipe implements IPipe, IDropContr return gate != null; } + public boolean hasGate(ForgeDirection side) { + if (!hasGate()) + return false; + if (container.hasFacade(side)) + return false; + if (container.hasPlug(side)) + return false; + + int connections = 0; + ForgeDirection targetOrientation = ForgeDirection.UNKNOWN; + for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) { + if (container.isPipeConnected(o)) { + connections++; + if (connections == 1) + targetOrientation = o; + } + } + + if (connections > 1 || connections == 0) + return true; + + return targetOrientation.getOpposite() != side; + } + protected void notifyBlocksOfNeighborChange(ForgeDirection side) { container.worldObj.notifyBlocksOfNeighborChange(container.xCoord + side.offsetX, container.yCoord + side.offsetY, container.zCoord + side.offsetZ, BuildCraftTransport.genericPipeBlock.blockID); } diff --git a/common/buildcraft/transport/PipeTransportItems.java b/common/buildcraft/transport/PipeTransportItems.java index 52ddb4fb..cc39547e 100644 --- a/common/buildcraft/transport/PipeTransportItems.java +++ b/common/buildcraft/transport/PipeTransportItems.java @@ -19,10 +19,10 @@ import buildcraft.core.inventory.Transactor; import buildcraft.core.network.PacketIds; import buildcraft.core.proxy.CoreProxy; import buildcraft.core.utils.BlockUtil; -import buildcraft.core.utils.Utils; import buildcraft.transport.network.PacketPipeTransportContent; import buildcraft.transport.network.PacketPipeTransportNBT; import buildcraft.transport.network.PacketSimpleId; +import buildcraft.transport.utils.TransportUtils; import com.google.common.collect.BiMap; import com.google.common.collect.ForwardingSet; import com.google.common.collect.HashBiMap; @@ -134,12 +134,12 @@ public class PipeTransportItems extends PipeTransport { public void defaultReajustSpeed(TravelingItem item) { float speed = item.getSpeed(); - if (speed > Utils.pipeNormalSpeed) { - speed -= Utils.pipeNormalSpeed; + if (speed > TransportConstants.PIPE_NORMAL_SPEED) { + speed -= TransportConstants.PIPE_NORMAL_SPEED; } - if (speed < Utils.pipeNormalSpeed) { - speed = Utils.pipeNormalSpeed; + if (speed < TransportConstants.PIPE_NORMAL_SPEED) { + speed = TransportConstants.PIPE_NORMAL_SPEED; } item.setSpeed(speed); @@ -159,7 +159,7 @@ public class PipeTransportItems extends PipeTransport { z = Math.min(z, container.zCoord + 0.99); if (item.input != ForgeDirection.UP && item.input != ForgeDirection.DOWN) { - y = container.yCoord + Utils.getPipeFloorOf(item.getItemStack()); + y = container.yCoord + TransportUtils.getPipeFloorOf(item.getItemStack()); } item.setPosition(x, y, z); @@ -338,7 +338,7 @@ public class PipeTransportItems extends PipeTransport { item.toCenter = false; // Reajusting to the middle - item.setPosition(container.xCoord + 0.5, container.yCoord + Utils.getPipeFloorOf(item.getItemStack()), container.zCoord + 0.5); + item.setPosition(container.xCoord + 0.5, container.yCoord + TransportUtils.getPipeFloorOf(item.getItemStack()), container.zCoord + 0.5); if (item.output == ForgeDirection.UNKNOWN) { if (travelHook != null) { @@ -421,7 +421,7 @@ public class PipeTransportItems extends PipeTransport { protected boolean middleReached(TravelingItem item) { float middleLimit = item.getSpeed() * 1.01F; - return (Math.abs(container.xCoord + 0.5 - item.xCoord) < middleLimit && Math.abs(container.yCoord + Utils.getPipeFloorOf(item.getItemStack()) - item.yCoord) < middleLimit && Math + return (Math.abs(container.xCoord + 0.5 - item.xCoord) < middleLimit && Math.abs(container.yCoord + TransportUtils.getPipeFloorOf(item.getItemStack()) - item.yCoord) < middleLimit && Math .abs(container.zCoord + 0.5 - item.zCoord) < middleLimit); } diff --git a/common/buildcraft/transport/TileGenericPipe.java b/common/buildcraft/transport/TileGenericPipe.java index 4a94280e..429bab14 100644 --- a/common/buildcraft/transport/TileGenericPipe.java +++ b/common/buildcraft/transport/TileGenericPipe.java @@ -570,6 +570,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui } public boolean hasFacade(ForgeDirection direction) { + if (direction == null || direction == ForgeDirection.UNKNOWN) + return false; if (this.worldObj.isRemote) return renderState.facadeMatrix.getFacadeBlockId(direction) != 0; return (this.facadeBlocks[direction.ordinal()] != 0); @@ -579,16 +581,17 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui InvUtils.dropItems(worldObj, ItemFacade.getStack(this.facadeBlocks[direction.ordinal()], this.facadeMeta[direction.ordinal()]), this.xCoord, this.yCoord, this.zCoord); } - public void dropFacade(ForgeDirection direction) { - if (this.worldObj.isRemote) - return; + public boolean dropFacade(ForgeDirection direction) { if (!hasFacade(direction)) - return; - dropFacadeItem(direction); - this.facadeBlocks[direction.ordinal()] = 0; - this.facadeMeta[direction.ordinal()] = 0; - worldObj.notifyBlockChange(this.xCoord, this.yCoord, this.zCoord, getBlockId()); - scheduleRenderUpdate(); + return false; + if (!worldObj.isRemote) { + dropFacadeItem(direction); + this.facadeBlocks[direction.ordinal()] = 0; + this.facadeMeta[direction.ordinal()] = 0; + worldObj.notifyBlockChange(this.xCoord, this.yCoord, this.zCoord, getBlockId()); + scheduleRenderUpdate(); + } + return true; } /** @@ -677,15 +680,17 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui return plugs[side.ordinal()]; } - public void removeAndDropPlug(ForgeDirection side) { + public boolean removeAndDropPlug(ForgeDirection side) { if (!hasPlug(side)) - return; - - plugs[side.ordinal()] = false; - InvUtils.dropItems(worldObj, new ItemStack(BuildCraftTransport.plugItem), this.xCoord, this.yCoord, this.zCoord); - worldObj.notifyBlockChange(this.xCoord, this.yCoord, this.zCoord, getBlockId()); - scheduleNeighborChange(); //To force recalculation of connections - scheduleRenderUpdate(); + return false; + if (!worldObj.isRemote) { + plugs[side.ordinal()] = false; + InvUtils.dropItems(worldObj, new ItemStack(BuildCraftTransport.plugItem), this.xCoord, this.yCoord, this.zCoord); + worldObj.notifyBlockChange(this.xCoord, this.yCoord, this.zCoord, getBlockId()); + scheduleNeighborChange(); //To force recalculation of connections + scheduleRenderUpdate(); + } + return true; } public boolean addPlug(ForgeDirection forgeDirection) { @@ -714,7 +719,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui public boolean isUseableByPlayer(EntityPlayer player) { return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this; } - + @Override public void writeGuiData(DataOutputStream data) throws IOException { if (BlockGenericPipe.isValid(pipe) && pipe instanceof IGuiReturnHandler) diff --git a/common/buildcraft/transport/TransportConstants.java b/common/buildcraft/transport/TransportConstants.java new file mode 100644 index 00000000..10a2eaf8 --- /dev/null +++ b/common/buildcraft/transport/TransportConstants.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) SpaceToad, 2011-2012 + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package buildcraft.transport; + +import net.minecraft.item.ItemStack; + +/** + * + * @author CovertJaguar + */ +public class TransportConstants { + + public static final float FACADE_THICKNESS = 1F / 16F; + public static final float PIPE_NORMAL_SPEED = 0.01F; +} diff --git a/common/buildcraft/transport/pipes/PipeItemsDaizuli.java b/common/buildcraft/transport/pipes/PipeItemsDaizuli.java index 2d631529..cad1b80e 100644 --- a/common/buildcraft/transport/pipes/PipeItemsDaizuli.java +++ b/common/buildcraft/transport/pipes/PipeItemsDaizuli.java @@ -14,12 +14,12 @@ import buildcraft.api.gates.IAction; import buildcraft.api.tools.IToolWrench; import buildcraft.core.network.TileNetworkData; import buildcraft.core.utils.EnumColor; -import buildcraft.core.utils.Utils; import buildcraft.transport.IPipeTransportItemsHook; import buildcraft.transport.Pipe; import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeTransportItems; import buildcraft.transport.TileGenericPipe; +import buildcraft.transport.TransportConstants; import buildcraft.transport.TravelingItem; import buildcraft.transport.triggers.ActionPipeColor; import buildcraft.transport.triggers.ActionPipeDirection; @@ -140,12 +140,12 @@ public class PipeItemsDaizuli extends Pipe implements IPipeT @Override public void readjustSpeed(TravelingItem item) { - if (item.getSpeed() > Utils.pipeNormalSpeed) - item.setSpeed(item.getSpeed() - Utils.pipeNormalSpeed / 4.0F); + if (item.getSpeed() > TransportConstants.PIPE_NORMAL_SPEED) + item.setSpeed(item.getSpeed() - TransportConstants.PIPE_NORMAL_SPEED / 4.0F); - if (item.getSpeed() < Utils.pipeNormalSpeed) - item.setSpeed(Utils.pipeNormalSpeed); + if (item.getSpeed() < TransportConstants.PIPE_NORMAL_SPEED) + item.setSpeed(TransportConstants.PIPE_NORMAL_SPEED); } @Override diff --git a/common/buildcraft/transport/pipes/PipeItemsGold.java b/common/buildcraft/transport/pipes/PipeItemsGold.java index 13ec571b..cc35cc5c 100644 --- a/common/buildcraft/transport/pipes/PipeItemsGold.java +++ b/common/buildcraft/transport/pipes/PipeItemsGold.java @@ -10,11 +10,11 @@ package buildcraft.transport.pipes; import buildcraft.BuildCraftTransport; import buildcraft.api.core.IIconProvider; import buildcraft.api.core.Position; -import buildcraft.core.utils.Utils; import buildcraft.transport.IPipeTransportItemsHook; import buildcraft.transport.Pipe; import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeTransportItems; +import buildcraft.transport.TransportConstants; import buildcraft.transport.TravelingItem; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -50,6 +50,6 @@ public class PipeItemsGold extends Pipe implements IPipeTransportItemsHook { @Override public void readjustSpeed(TravelingItem item) { - item.setSpeed(Math.min(Math.max(Utils.pipeNormalSpeed, item.getSpeed()) * 2f, Utils.pipeNormalSpeed * 20F)); + item.setSpeed(Math.min(Math.max(TransportConstants.PIPE_NORMAL_SPEED, item.getSpeed()) * 2f, TransportConstants.PIPE_NORMAL_SPEED * 20F)); } } diff --git a/common/buildcraft/transport/pipes/PipeItemsLapis.java b/common/buildcraft/transport/pipes/PipeItemsLapis.java index 3966a23e..4df7a8f6 100644 --- a/common/buildcraft/transport/pipes/PipeItemsLapis.java +++ b/common/buildcraft/transport/pipes/PipeItemsLapis.java @@ -13,12 +13,12 @@ import buildcraft.api.core.Position; import buildcraft.api.gates.IAction; import buildcraft.api.tools.IToolWrench; import buildcraft.core.utils.EnumColor; -import buildcraft.core.utils.Utils; import buildcraft.transport.IItemTravelingHook; import buildcraft.transport.IPipeTransportItemsHook; import buildcraft.transport.Pipe; import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeTransportItems; +import buildcraft.transport.TransportConstants; import buildcraft.transport.TravelingItem; import buildcraft.transport.triggers.ActionPipeColor; import cpw.mods.fml.relauncher.Side; @@ -96,12 +96,12 @@ public class PipeItemsLapis extends Pipe implements IItemTra @Override public void readjustSpeed(TravelingItem item) { - if (item.getSpeed() > Utils.pipeNormalSpeed) { - item.setSpeed(item.getSpeed() - Utils.pipeNormalSpeed / 4.0F); + if (item.getSpeed() > TransportConstants.PIPE_NORMAL_SPEED) { + item.setSpeed(item.getSpeed() - TransportConstants.PIPE_NORMAL_SPEED / 4.0F); } - if (item.getSpeed() < Utils.pipeNormalSpeed) { - item.setSpeed(Utils.pipeNormalSpeed); + if (item.getSpeed() < TransportConstants.PIPE_NORMAL_SPEED) { + item.setSpeed(TransportConstants.PIPE_NORMAL_SPEED); } } diff --git a/common/buildcraft/transport/pipes/PipeItemsObsidian.java b/common/buildcraft/transport/pipes/PipeItemsObsidian.java index 67dde61b..eff8cfb3 100644 --- a/common/buildcraft/transport/pipes/PipeItemsObsidian.java +++ b/common/buildcraft/transport/pipes/PipeItemsObsidian.java @@ -19,10 +19,10 @@ import buildcraft.core.inventory.Transactor; import buildcraft.core.inventory.filters.StackFilter; import buildcraft.transport.TravelingItem; import buildcraft.core.proxy.CoreProxy; -import buildcraft.core.utils.Utils; import buildcraft.transport.Pipe; import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeTransportItems; +import buildcraft.transport.utils.TransportUtils; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import java.util.Arrays; @@ -226,7 +226,7 @@ public class PipeItemsObsidian extends Pipe implements IPowe CoreProxy.proxy.removeEntity(entity); } - TravelingItem passive = new TravelingItem(container.xCoord + 0.5, container.yCoord + Utils.getPipeFloorOf(stack), container.zCoord + 0.5, stack); + TravelingItem passive = new TravelingItem(container.xCoord + 0.5, container.yCoord + TransportUtils.getPipeFloorOf(stack), container.zCoord + 0.5, stack); passive.setSpeed((float) speed); diff --git a/common/buildcraft/transport/pipes/PipeItemsQuartz.java b/common/buildcraft/transport/pipes/PipeItemsQuartz.java index 384c21e0..13c6a0d5 100644 --- a/common/buildcraft/transport/pipes/PipeItemsQuartz.java +++ b/common/buildcraft/transport/pipes/PipeItemsQuartz.java @@ -10,11 +10,11 @@ package buildcraft.transport.pipes; import buildcraft.BuildCraftTransport; import buildcraft.api.core.IIconProvider; import buildcraft.api.core.Position; -import buildcraft.core.utils.Utils; import buildcraft.transport.IPipeTransportItemsHook; import buildcraft.transport.Pipe; import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeTransportItems; +import buildcraft.transport.TransportConstants; import buildcraft.transport.TravelingItem; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -41,12 +41,12 @@ public class PipeItemsQuartz extends Pipe implements IPipeTransportItemsHook { @Override public void readjustSpeed(TravelingItem item) { - if (item.getSpeed() > Utils.pipeNormalSpeed) { - item.setSpeed(item.getSpeed() - Utils.pipeNormalSpeed / 4.0F); + if (item.getSpeed() > TransportConstants.PIPE_NORMAL_SPEED) { + item.setSpeed(item.getSpeed() - TransportConstants.PIPE_NORMAL_SPEED / 4.0F); } - if (item.getSpeed() < Utils.pipeNormalSpeed) { - item.setSpeed(Utils.pipeNormalSpeed); + if (item.getSpeed() < TransportConstants.PIPE_NORMAL_SPEED) { + item.setSpeed(TransportConstants.PIPE_NORMAL_SPEED); } } diff --git a/common/buildcraft/transport/pipes/PipeItemsStone.java b/common/buildcraft/transport/pipes/PipeItemsStone.java index 6199c8ea..415e5dd2 100644 --- a/common/buildcraft/transport/pipes/PipeItemsStone.java +++ b/common/buildcraft/transport/pipes/PipeItemsStone.java @@ -10,11 +10,11 @@ package buildcraft.transport.pipes; import buildcraft.BuildCraftTransport; import buildcraft.api.core.IIconProvider; import buildcraft.api.core.Position; -import buildcraft.core.utils.Utils; import buildcraft.transport.IPipeTransportItemsHook; import buildcraft.transport.Pipe; import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeTransportItems; +import buildcraft.transport.TransportConstants; import buildcraft.transport.TravelingItem; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -40,12 +40,12 @@ public class PipeItemsStone extends Pipe implements IPipeTransportItemsHook { @Override public void readjustSpeed(TravelingItem item) { - if (item.getSpeed() > Utils.pipeNormalSpeed) { - item.setSpeed(item.getSpeed() - Utils.pipeNormalSpeed / 2.0F); + if (item.getSpeed() > TransportConstants.PIPE_NORMAL_SPEED) { + item.setSpeed(item.getSpeed() - TransportConstants.PIPE_NORMAL_SPEED / 2.0F); } - if (item.getSpeed() < Utils.pipeNormalSpeed) { - item.setSpeed(Utils.pipeNormalSpeed); + if (item.getSpeed() < TransportConstants.PIPE_NORMAL_SPEED) { + item.setSpeed(TransportConstants.PIPE_NORMAL_SPEED); } } diff --git a/common/buildcraft/transport/render/FacadeItemRenderer.java b/common/buildcraft/transport/render/FacadeItemRenderer.java index 56e98d1d..2572ae6e 100644 --- a/common/buildcraft/transport/render/FacadeItemRenderer.java +++ b/common/buildcraft/transport/render/FacadeItemRenderer.java @@ -1,7 +1,7 @@ package buildcraft.transport.render; import buildcraft.BuildCraftTransport; -import buildcraft.core.utils.Utils; +import buildcraft.core.CoreConstants; import buildcraft.transport.ItemFacade; import buildcraft.transport.PipeIconProvider; import net.minecraft.block.Block; @@ -11,6 +11,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.Icon; import net.minecraftforge.client.IItemRenderer; +import static net.minecraftforge.client.IItemRenderer.ItemRenderType.EQUIPPED_FIRST_PERSON; import org.lwjgl.opengl.GL11; public class FacadeItemRenderer implements IItemRenderer { @@ -72,7 +73,7 @@ public class FacadeItemRenderer implements IItemRenderer { block = BuildCraftTransport.genericPipeBlock; Icon textureID = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal()); // Structure pipe - block.setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos - 1F / 16F); + block.setBlockBounds(CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS - 1F / 16F); block.setBlockBoundsForItemRender(); render.setRenderBoundsFromBlock(block); GL11.glTranslatef(translateX, translateY, translateZ + 0.25F); @@ -112,6 +113,8 @@ public class FacadeItemRenderer implements IItemRenderer { return true; case EQUIPPED: return true; + case EQUIPPED_FIRST_PERSON: + return true; case INVENTORY: return true; default: @@ -133,6 +136,7 @@ public class FacadeItemRenderer implements IItemRenderer { renderFacadeItem((RenderBlocks) data[0], item, -0.6F, 0f, -0.6F); break; case EQUIPPED: + case EQUIPPED_FIRST_PERSON: renderFacadeItem((RenderBlocks) data[0], item, 0F, 0F, 0f); break; case INVENTORY: diff --git a/common/buildcraft/transport/render/PipeItemRenderer.java b/common/buildcraft/transport/render/PipeItemRenderer.java index 29a07364..7d8f39e3 100644 --- a/common/buildcraft/transport/render/PipeItemRenderer.java +++ b/common/buildcraft/transport/render/PipeItemRenderer.java @@ -1,7 +1,7 @@ package buildcraft.transport.render; import buildcraft.BuildCraftTransport; -import buildcraft.core.utils.Utils; +import buildcraft.core.CoreConstants; import buildcraft.transport.ItemPipe; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; @@ -27,7 +27,7 @@ public class PipeItemRenderer implements IItemRenderer { if (icon == null) icon = ((TextureMap) Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationBlocksTexture)).getAtlasSprite("missingno"); - block.setBlockBounds(Utils.pipeMinPos, 0.0F, Utils.pipeMinPos, Utils.pipeMaxPos, 1.0F, Utils.pipeMaxPos); + block.setBlockBounds(CoreConstants.PIPE_MIN_POS, 0.0F, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, 1.0F, CoreConstants.PIPE_MAX_POS); block.setBlockBoundsForItemRender(); render.setRenderBoundsFromBlock(block); diff --git a/common/buildcraft/transport/render/PipeRendererTESR.java b/common/buildcraft/transport/render/PipeRendererTESR.java index 425cfde7..128fad2d 100644 --- a/common/buildcraft/transport/render/PipeRendererTESR.java +++ b/common/buildcraft/transport/render/PipeRendererTESR.java @@ -12,11 +12,11 @@ import buildcraft.BuildCraftCore.RenderMode; import buildcraft.BuildCraftTransport; import buildcraft.api.transport.IPipe; import buildcraft.api.transport.IPipe.WireColor; +import buildcraft.core.CoreConstants; import buildcraft.core.render.FluidRenderer; import buildcraft.core.render.RenderEntityBlock; import buildcraft.core.render.RenderEntityBlock.RenderInfo; import buildcraft.core.utils.EnumColor; -import buildcraft.core.utils.Utils; import buildcraft.transport.Pipe; import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeRenderState; @@ -98,7 +98,7 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer { } block.texture = fluid.getStillIcon(); - float size = Utils.pipeMaxPos - Utils.pipeMinPos; + float size = CoreConstants.PIPE_MAX_POS - CoreConstants.PIPE_MIN_POS; // render size @@ -111,12 +111,12 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer { GL11.glNewList(d.sideHorizontal[s], 4864 /* GL_COMPILE */); block.minX = 0.0F; - block.minZ = Utils.pipeMinPos + 0.01F; + block.minZ = CoreConstants.PIPE_MIN_POS + 0.01F; block.maxX = block.minX + size / 2F + 0.01F; block.maxZ = block.minZ + size - 0.02F; - block.minY = Utils.pipeMinPos + 0.01F; + block.minY = CoreConstants.PIPE_MIN_POS + 0.01F; block.maxY = block.minY + (size - 0.02F) * ratio; RenderEntityBlock.INSTANCE.renderBlock(block, world, 0, 0, 0, false, true); @@ -128,7 +128,7 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer { d.sideVertical[s] = GLAllocation.generateDisplayLists(1); GL11.glNewList(d.sideVertical[s], 4864 /* GL_COMPILE */); - block.minY = Utils.pipeMaxPos - 0.01; + block.minY = CoreConstants.PIPE_MAX_POS - 0.01; block.maxY = 1; block.minX = 0.5 - (size / 2 - 0.01) * ratio; @@ -146,13 +146,13 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer { d.centerHorizontal[s] = GLAllocation.generateDisplayLists(1); GL11.glNewList(d.centerHorizontal[s], 4864 /* GL_COMPILE */); - block.minX = Utils.pipeMinPos + 0.01; - block.minZ = Utils.pipeMinPos + 0.01; + block.minX = CoreConstants.PIPE_MIN_POS + 0.01; + block.minZ = CoreConstants.PIPE_MIN_POS + 0.01; block.maxX = block.minX + size - 0.02; block.maxZ = block.minZ + size - 0.02; - block.minY = Utils.pipeMinPos + 0.01; + block.minY = CoreConstants.PIPE_MIN_POS + 0.01; block.maxY = block.minY + (size - 0.02F) * ratio; RenderEntityBlock.INSTANCE.renderBlock(block, world, 0, 0, 0, false, true); @@ -164,8 +164,8 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer { d.centerVertical[s] = GLAllocation.generateDisplayLists(1); GL11.glNewList(d.centerVertical[s], 4864 /* GL_COMPILE */); - block.minY = Utils.pipeMinPos + 0.01; - block.maxY = Utils.pipeMaxPos - 0.01; + block.minY = CoreConstants.PIPE_MIN_POS + 0.01; + block.maxY = CoreConstants.PIPE_MAX_POS - 0.01; block.minX = 0.5 - (size / 2 - 0.02) * ratio; block.maxX = 0.5 + (size / 2 - 0.02) * ratio; @@ -192,7 +192,7 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer { RenderInfo block = new RenderInfo(); block.texture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.Power_Normal.ordinal()); - float size = Utils.pipeMaxPos - Utils.pipeMinPos; + float size = CoreConstants.PIPE_MAX_POS - CoreConstants.PIPE_MIN_POS; for (int s = 0; s < POWER_STAGES; ++s) { displayPowerList[s] = GLAllocation.generateDisplayLists(1); @@ -218,7 +218,7 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer { block.texture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.Power_Overload.ordinal()); - size = Utils.pipeMaxPos - Utils.pipeMinPos; + size = CoreConstants.PIPE_MAX_POS - CoreConstants.PIPE_MIN_POS; for (int s = 0; s < POWER_STAGES; ++s) { displayPowerListOverload[s] = GLAllocation.generateDisplayLists(1); @@ -273,19 +273,19 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer { PipeRenderState state = pipe.getRenderState(); if (state.wireMatrix.hasWire(WireColor.Red)) { - pipeWireRender(pipe, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMinPos, IPipe.WireColor.Red, x, y, z); + pipeWireRender(pipe, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MIN_POS, IPipe.WireColor.Red, x, y, z); } if (state.wireMatrix.hasWire(WireColor.Blue)) { - pipeWireRender(pipe, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos, IPipe.WireColor.Blue, x, y, z); + pipeWireRender(pipe, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS, IPipe.WireColor.Blue, x, y, z); } if (state.wireMatrix.hasWire(WireColor.Green)) { - pipeWireRender(pipe, Utils.pipeMaxPos, Utils.pipeMinPos, Utils.pipeMinPos, IPipe.WireColor.Green, x, y, z); + pipeWireRender(pipe, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, IPipe.WireColor.Green, x, y, z); } if (state.wireMatrix.hasWire(WireColor.Yellow)) { - pipeWireRender(pipe, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, IPipe.WireColor.Yellow, x, y, z); + pipeWireRender(pipe, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, IPipe.WireColor.Yellow, x, y, z); } if (state.hasGate()) { @@ -297,13 +297,13 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer { PipeRenderState state = pipe.getRenderState(); - float minX = Utils.pipeMinPos; - float minY = Utils.pipeMinPos; - float minZ = Utils.pipeMinPos; + float minX = CoreConstants.PIPE_MIN_POS; + float minY = CoreConstants.PIPE_MIN_POS; + float minZ = CoreConstants.PIPE_MIN_POS; - float maxX = Utils.pipeMaxPos; - float maxY = Utils.pipeMaxPos; - float maxZ = Utils.pipeMaxPos; + float maxX = CoreConstants.PIPE_MAX_POS; + float maxY = CoreConstants.PIPE_MAX_POS; + float maxZ = CoreConstants.PIPE_MAX_POS; boolean foundX = false, foundY = false, foundZ = false; @@ -340,43 +340,43 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer { boolean center = false; if (minX == 0 && maxX != 1 && (foundY || foundZ)) - if (cx == Utils.pipeMinPos) { - maxX = Utils.pipeMinPos; + if (cx == CoreConstants.PIPE_MIN_POS) { + maxX = CoreConstants.PIPE_MIN_POS; } else { center = true; } if (minX != 0 && maxX == 1 && (foundY || foundZ)) - if (cx == Utils.pipeMaxPos) { - minX = Utils.pipeMaxPos; + if (cx == CoreConstants.PIPE_MAX_POS) { + minX = CoreConstants.PIPE_MAX_POS; } else { center = true; } if (minY == 0 && maxY != 1 && (foundX || foundZ)) - if (cy == Utils.pipeMinPos) { - maxY = Utils.pipeMinPos; + if (cy == CoreConstants.PIPE_MIN_POS) { + maxY = CoreConstants.PIPE_MIN_POS; } else { center = true; } if (minY != 0 && maxY == 1 && (foundX || foundZ)) - if (cy == Utils.pipeMaxPos) { - minY = Utils.pipeMaxPos; + if (cy == CoreConstants.PIPE_MAX_POS) { + minY = CoreConstants.PIPE_MAX_POS; } else { center = true; } if (minZ == 0 && maxZ != 1 && (foundX || foundY)) - if (cz == Utils.pipeMinPos) { - maxZ = Utils.pipeMinPos; + if (cz == CoreConstants.PIPE_MIN_POS) { + maxZ = CoreConstants.PIPE_MIN_POS; } else { center = true; } if (minZ != 0 && maxZ == 1 && (foundX || foundY)) - if (cz == Utils.pipeMaxPos) { - minZ = Utils.pipeMaxPos; + if (cz == CoreConstants.PIPE_MAX_POS) { + minZ = CoreConstants.PIPE_MAX_POS; } else { center = true; } @@ -389,10 +389,16 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer { GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_CULL_FACE); RenderHelper.disableStandardItemLighting(); - + GL11.glColor3f(1, 1, 1); - GL11.glTranslatef((float) x, (float) y, (float) z); - + GL11.glTranslatef((float) x, (float) y, (float) z); + + float scale = 1.001f; + GL11.glTranslatef(0.5F, 0.5F, 0.5F); + GL11.glScalef(scale, scale, scale); + GL11.glTranslatef(-0.5F, -0.5F, -0.5F); + + bindTexture(TextureMap.locationBlocksTexture); RenderInfo box = new RenderInfo(); @@ -400,36 +406,36 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer { // Z render - if (minZ != Utils.pipeMinPos || maxZ != Utils.pipeMaxPos || !found) { - box.setBounds(cx == Utils.pipeMinPos ? cx - 0.05F : cx, cy == Utils.pipeMinPos ? cy - 0.05F : cy, minZ, cx == Utils.pipeMinPos ? cx - : cx + 0.05F, cy == Utils.pipeMinPos ? cy : cy + 0.05F, maxZ); + if (minZ != CoreConstants.PIPE_MIN_POS || maxZ != CoreConstants.PIPE_MAX_POS || !found) { + box.setBounds(cx == CoreConstants.PIPE_MIN_POS ? cx - 0.05F : cx, cy == CoreConstants.PIPE_MIN_POS ? cy - 0.05F : cy, minZ, cx == CoreConstants.PIPE_MIN_POS ? cx + : cx + 0.05F, cy == CoreConstants.PIPE_MIN_POS ? cy : cy + 0.05F, maxZ); RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true); } // X render - if (minX != Utils.pipeMinPos || maxX != Utils.pipeMaxPos || !found) { - box.setBounds(minX, cy == Utils.pipeMinPos ? cy - 0.05F : cy, cz == Utils.pipeMinPos ? cz - 0.05F : cz, maxX, cy == Utils.pipeMinPos ? cy - : cy + 0.05F, cz == Utils.pipeMinPos ? cz : cz + 0.05F); + if (minX != CoreConstants.PIPE_MIN_POS || maxX != CoreConstants.PIPE_MAX_POS || !found) { + box.setBounds(minX, cy == CoreConstants.PIPE_MIN_POS ? cy - 0.05F : cy, cz == CoreConstants.PIPE_MIN_POS ? cz - 0.05F : cz, maxX, cy == CoreConstants.PIPE_MIN_POS ? cy + : cy + 0.05F, cz == CoreConstants.PIPE_MIN_POS ? cz : cz + 0.05F); RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true); } // Y render - if (minY != Utils.pipeMinPos || maxY != Utils.pipeMaxPos || !found) { - box.setBounds(cx == Utils.pipeMinPos ? cx - 0.05F : cx, minY, cz == Utils.pipeMinPos ? cz - 0.05F : cz, cx == Utils.pipeMinPos ? cx - : cx + 0.05F, maxY, cz == Utils.pipeMinPos ? cz : cz + 0.05F); + if (minY != CoreConstants.PIPE_MIN_POS || maxY != CoreConstants.PIPE_MAX_POS || !found) { + box.setBounds(cx == CoreConstants.PIPE_MIN_POS ? cx - 0.05F : cx, minY, cz == CoreConstants.PIPE_MIN_POS ? cz - 0.05F : cz, cx == CoreConstants.PIPE_MIN_POS ? cx + : cx + 0.05F, maxY, cz == CoreConstants.PIPE_MIN_POS ? cz : cz + 0.05F); RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true); } if (center || !found) { - box.setBounds(cx == Utils.pipeMinPos ? cx - 0.05F : cx, cy == Utils.pipeMinPos ? cy - 0.05F : cy, cz == Utils.pipeMinPos ? cz - 0.05F : cz, - cx == Utils.pipeMinPos ? cx : cx + 0.05F, cy == Utils.pipeMinPos ? cy : cy + 0.05F, cz == Utils.pipeMinPos ? cz : cz + 0.05F); + box.setBounds(cx == CoreConstants.PIPE_MIN_POS ? cx - 0.05F : cx, cy == CoreConstants.PIPE_MIN_POS ? cy - 0.05F : cy, cz == CoreConstants.PIPE_MIN_POS ? cz - 0.05F : cz, + cx == CoreConstants.PIPE_MIN_POS ? cx : cx + 0.05F, cy == CoreConstants.PIPE_MIN_POS ? cy : cy + 0.05F, cz == CoreConstants.PIPE_MIN_POS ? cz : cz + 0.05F); RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true); } - + RenderHelper.enableStandardItemLighting(); - + GL11.glPopAttrib(); GL11.glPopMatrix(); } @@ -442,7 +448,7 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer { GL11.glEnable(GL11.GL_CULL_FACE); // GL11.glDisable(GL11.GL_TEXTURE_2D); RenderHelper.disableStandardItemLighting(); - + GL11.glColor3f(1, 1, 1); GL11.glTranslatef((float) x, (float) y, (float) z); @@ -450,42 +456,42 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer { PipeRenderState state = pipe.getRenderState(); - float min = Utils.pipeMinPos + 0.05F; - float max = Utils.pipeMaxPos - 0.05F; + float min = CoreConstants.PIPE_MIN_POS + 0.05F; + float max = CoreConstants.PIPE_MAX_POS - 0.05F; RenderInfo box = new RenderInfo(); box.texture = BuildCraftTransport.instance.gateIconProvider.getIcon(state.getGateIconIndex()); if (shouldRenderNormalPipeSide(state, ForgeDirection.WEST)) { - box.setBounds(Utils.pipeMinPos - 0.10F, min, min, Utils.pipeMinPos + 0.001F, max, max); + box.setBounds(CoreConstants.PIPE_MIN_POS - 0.10F, min, min, CoreConstants.PIPE_MIN_POS + 0.001F, max, max); RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true); } if (shouldRenderNormalPipeSide(state, ForgeDirection.EAST)) { - box.setBounds(Utils.pipeMaxPos + 0.001F, min, min, Utils.pipeMaxPos + 0.10F, max, max); + box.setBounds(CoreConstants.PIPE_MAX_POS + 0.001F, min, min, CoreConstants.PIPE_MAX_POS + 0.10F, max, max); RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true); } if (shouldRenderNormalPipeSide(state, ForgeDirection.DOWN)) { - box.setBounds(min, Utils.pipeMinPos - 0.10F, min, max, Utils.pipeMinPos + 0.001F, max); + box.setBounds(min, CoreConstants.PIPE_MIN_POS - 0.10F, min, max, CoreConstants.PIPE_MIN_POS + 0.001F, max); RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true); } if (shouldRenderNormalPipeSide(state, ForgeDirection.UP)) { - box.setBounds(min, Utils.pipeMaxPos + 0.001F, min, max, Utils.pipeMaxPos + 0.10F, max); + box.setBounds(min, CoreConstants.PIPE_MAX_POS + 0.001F, min, max, CoreConstants.PIPE_MAX_POS + 0.10F, max); RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true); } if (shouldRenderNormalPipeSide(state, ForgeDirection.NORTH)) { - box.setBounds(min, min, Utils.pipeMinPos - 0.10F, max, max, Utils.pipeMinPos + 0.001F); + box.setBounds(min, min, CoreConstants.PIPE_MIN_POS - 0.10F, max, max, CoreConstants.PIPE_MIN_POS + 0.001F); RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true); } if (shouldRenderNormalPipeSide(state, ForgeDirection.SOUTH)) { - box.setBounds(min, min, Utils.pipeMaxPos + 0.001F, max, max, Utils.pipeMaxPos + 0.10F); + box.setBounds(min, min, CoreConstants.PIPE_MAX_POS + 0.001F, max, max, CoreConstants.PIPE_MAX_POS + 0.10F); RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true); } - + RenderHelper.enableStandardItemLighting(); GL11.glPopAttrib(); diff --git a/common/buildcraft/transport/render/PipeRendererWorld.java b/common/buildcraft/transport/render/PipeRendererWorld.java index 5cc1baef..77f8f4a8 100644 --- a/common/buildcraft/transport/render/PipeRendererWorld.java +++ b/common/buildcraft/transport/render/PipeRendererWorld.java @@ -2,12 +2,14 @@ package buildcraft.transport.render; import buildcraft.BuildCraftTransport; import buildcraft.api.core.IIconProvider; -import buildcraft.core.utils.Utils; +import buildcraft.core.CoreConstants; import buildcraft.transport.BlockGenericPipe; import buildcraft.transport.IPipeRenderState; import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeRenderState; +import buildcraft.transport.TransportConstants; import buildcraft.transport.TransportProxy; +import buildcraft.core.utils.MatrixTranformations; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import net.minecraft.block.Block; import net.minecraft.client.renderer.RenderBlocks; @@ -20,62 +22,8 @@ import net.minecraftforge.common.ForgeDirection; public class PipeRendererWorld implements ISimpleBlockRenderingHandler { - public static final float facadeThickness = 1F / 16F; - /** - * Mirrors the array on the Y axis by calculating offsets from 0.5F - * - * @param targetArray - */ - private void mirrorY(float[][] targetArray) { - float temp = targetArray[1][0]; - targetArray[1][0] = (targetArray[1][1] - 0.5F) * -1F + 0.5F; // 1 -> 0.5F -> -0.5F -> 0F - targetArray[1][1] = (temp - 0.5F) * -1F + 0.5F; // 0 -> -0.5F -> 0.5F -> 1F - } - /** - * Shifts the coordinates around effectivly rotating something. Zero state - * is DOWN then -> NORTH -> WEST Note - To obtain Pos, do a mirrorY() before - * rotating - * - * @param targetArray the array that should be rotated - */ - private void rotate(float[][] targetArray) { - for (int i = 0; i < 2; i++) { - float temp = targetArray[2][i]; - targetArray[2][i] = targetArray[1][i]; - targetArray[1][i] = targetArray[0][i]; - targetArray[0][i] = temp; - } - } - - /** - * @param targetArray the array that should be transformed - * @param direction - */ - private void transform(float[][] targetArray, ForgeDirection direction) { - if ((direction.ordinal() & 0x1) == 1) { - mirrorY(targetArray); - } - - for (int i = 0; i < (direction.ordinal() >> 1); i++) { - rotate(targetArray); - } - } - - /** - * Clones both dimensions of a float[][] - * - * @param source the float[][] to deepClone - * @return - */ - private float[][] deepClone(float[][] source) { - float[][] target = source.clone(); - for (int i = 0; i < target.length; i++) { - target[i] = source[i].clone(); - } - return target; - } private void renderAllFaceExeptAxe(RenderBlocks renderblocks, BlockGenericPipe block, Icon icon, int x, int y, int z, char axe) { float minX = (float) renderblocks.renderMinX; @@ -121,8 +69,8 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler { public void renderPipe(RenderBlocks renderblocks, IBlockAccess iblockaccess, BlockGenericPipe block, IPipeRenderState renderState, int x, int y, int z) { - float minSize = Utils.pipeMinPos; - float maxSize = Utils.pipeMaxPos; + float minSize = CoreConstants.PIPE_MIN_POS; + float maxSize = CoreConstants.PIPE_MAX_POS; PipeRenderState state = renderState.getRenderState(); IIconProvider icons = renderState.getPipeIcons(); @@ -210,7 +158,7 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler { zeroState[0][1] = 1.0F + zFightOffset / 2; // Y START - END zeroState[1][0] = 0.0F - zFightOffset; - zeroState[1][1] = facadeThickness; + zeroState[1][1] = TransportConstants.FACADE_THICKNESS; // Z START - END zeroState[2][0] = 0.0F; zeroState[2][1] = 1.0F; @@ -241,39 +189,39 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler { // Hollow facade if (state.pipeConnectionMatrix.isConnected(direction)) { - float[][] rotated = deepClone(zeroState); + float[][] rotated = MatrixTranformations.deepClone(zeroState); rotated[2][0] = 0.0F; - rotated[2][1] = Utils.pipeMinPos - zFightOffset; + rotated[2][1] = CoreConstants.PIPE_MIN_POS - zFightOffset; rotated[1][0] -= zFightOffset / 2; - transform(rotated, direction); + MatrixTranformations.transform(rotated, direction); renderblocks.setRenderBounds(rotated[0][0], rotated[1][0], rotated[2][0], rotated[0][1], rotated[1][1], rotated[2][1]); renderblocks.renderStandardBlock(block, x, y, z); - rotated = deepClone(zeroState); - rotated[2][0] = Utils.pipeMaxPos + zFightOffset; + rotated = MatrixTranformations.deepClone(zeroState); + rotated[2][0] = CoreConstants.PIPE_MAX_POS + zFightOffset; rotated[1][0] -= zFightOffset / 2; - transform(rotated, direction); + MatrixTranformations.transform(rotated, direction); renderblocks.setRenderBounds(rotated[0][0], rotated[1][0], rotated[2][0], rotated[0][1], rotated[1][1], rotated[2][1]); renderblocks.renderStandardBlock(block, x, y, z); - rotated = deepClone(zeroState); + rotated = MatrixTranformations.deepClone(zeroState); rotated[0][0] = 0.0F; - rotated[0][1] = Utils.pipeMinPos - zFightOffset; + rotated[0][1] = CoreConstants.PIPE_MIN_POS - zFightOffset; rotated[1][1] -= zFightOffset; - transform(rotated, direction); + MatrixTranformations.transform(rotated, direction); renderblocks.setRenderBounds(rotated[0][0], rotated[1][0], rotated[2][0], rotated[0][1], rotated[1][1], rotated[2][1]); renderblocks.renderStandardBlock(block, x, y, z); - rotated = deepClone(zeroState); - rotated[0][0] = Utils.pipeMaxPos + zFightOffset; + rotated = MatrixTranformations.deepClone(zeroState); + rotated[0][0] = CoreConstants.PIPE_MAX_POS + zFightOffset; rotated[0][1] = 1F; rotated[1][1] -= zFightOffset; - transform(rotated, direction); + MatrixTranformations.transform(rotated, direction); renderblocks.setRenderBounds(rotated[0][0], rotated[1][0], rotated[2][0], rotated[0][1], rotated[1][1], rotated[2][1]); renderblocks.renderStandardBlock(block, x, y, z); } else { // Solid facade - float[][] rotated = deepClone(zeroState); - transform(rotated, direction); + float[][] rotated = MatrixTranformations.deepClone(zeroState); + MatrixTranformations.transform(rotated, direction); renderblocks.setRenderBounds(rotated[0][0], rotated[1][0], rotated[2][0], rotated[0][1], rotated[1][1], rotated[2][1]); renderblocks.renderStandardBlock(block, x, y, z); } @@ -292,21 +240,21 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler { } // X START - END - zeroState[0][0] = Utils.pipeMinPos; - zeroState[0][1] = Utils.pipeMaxPos; + zeroState[0][0] = CoreConstants.PIPE_MIN_POS; + zeroState[0][1] = CoreConstants.PIPE_MAX_POS; // Y START - END - zeroState[1][0] = facadeThickness; - zeroState[1][1] = Utils.pipeMinPos; + zeroState[1][0] = TransportConstants.FACADE_THICKNESS; + zeroState[1][1] = CoreConstants.PIPE_MIN_POS; // Z START - END - zeroState[2][0] = Utils.pipeMinPos; - zeroState[2][1] = Utils.pipeMaxPos; + zeroState[2][0] = CoreConstants.PIPE_MIN_POS; + zeroState[2][1] = CoreConstants.PIPE_MAX_POS; state.currentTexture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal()); // Structure Pipe for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { if (state.facadeMatrix.getFacadeBlockId(direction) != 0 && !state.pipeConnectionMatrix.isConnected(direction)) { - float[][] rotated = deepClone(zeroState); - transform(rotated, direction); + float[][] rotated = MatrixTranformations.deepClone(zeroState); + MatrixTranformations.transform(rotated, direction); renderblocks.setRenderBounds(rotated[0][0], rotated[1][0], rotated[2][0], rotated[0][1], rotated[1][1], rotated[2][1]); renderblocks.renderStandardBlock(block, x, y, z); @@ -333,8 +281,8 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler { for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { if (state.plugMatrix.isConnected(direction)) { - float[][] rotated = deepClone(zeroState); - transform(rotated, direction); + float[][] rotated = MatrixTranformations.deepClone(zeroState); + MatrixTranformations.transform(rotated, direction); renderblocks.setRenderBounds(rotated[0][0], rotated[1][0], rotated[2][0], rotated[0][1], rotated[1][1], rotated[2][1]); renderblocks.renderStandardBlock(block, x, y, z); @@ -355,8 +303,8 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler { for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { if (state.plugMatrix.isConnected(direction)) { - float[][] rotated = deepClone(zeroState); - transform(rotated, direction); + float[][] rotated = MatrixTranformations.deepClone(zeroState); + MatrixTranformations.transform(rotated, direction); renderblocks.setRenderBounds(rotated[0][0], rotated[1][0], rotated[2][0], rotated[0][1], rotated[1][1], rotated[2][1]); renderblocks.renderStandardBlock(block, x, y, z); diff --git a/common/buildcraft/transport/render/TileEntityPickupFX.java b/common/buildcraft/transport/render/TileEntityPickupFX.java index 3a525cbd..d5ac1411 100644 --- a/common/buildcraft/transport/render/TileEntityPickupFX.java +++ b/common/buildcraft/transport/render/TileEntityPickupFX.java @@ -11,7 +11,7 @@ */ package buildcraft.transport.render; -import buildcraft.core.utils.Utils; +import buildcraft.transport.utils.TransportUtils; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.particle.EntityFX; @@ -42,7 +42,7 @@ public class TileEntityPickupFX extends EntityFX this.entityToPickUp = par2Entity; this.entityPickingUp = par3Entity; this.maxAge = 3; - this.yOffs = Utils.getPipeFloorOf(par2Entity.getEntityItem()); + this.yOffs = TransportUtils.getPipeFloorOf(par2Entity.getEntityItem()); } @Override diff --git a/common/buildcraft/transport/utils/TransportUtils.java b/common/buildcraft/transport/utils/TransportUtils.java new file mode 100644 index 00000000..fb601108 --- /dev/null +++ b/common/buildcraft/transport/utils/TransportUtils.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) SpaceToad, 2011-2012 + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package buildcraft.transport.utils; + +import buildcraft.core.CoreConstants; +import net.minecraft.item.ItemStack; + +/** + * + * @author CovertJaguar + */ +public class TransportUtils { + + /** + * Depending on the kind of item in the pipe, set the floor at a different + * level to optimize graphical aspect. + */ + public static float getPipeFloorOf(ItemStack item) { + return CoreConstants.PIPE_MIN_POS; + } +}