diff --git a/buildcraft_resources/assets/buildcraft/lang/en_US.lang b/buildcraft_resources/assets/buildcraft/lang/en_US.lang index 424a99d9..376edf9e 100644 --- a/buildcraft_resources/assets/buildcraft/lang/en_US.lang +++ b/buildcraft_resources/assets/buildcraft/lang/en_US.lang @@ -248,6 +248,7 @@ item.FacadePhased.state=%s: %s item.FacadePhased.state_default=Default: %s item.FacadePhased.state_transparent=Transparent item.PipePlug.name=Pipe Plug +item.Lens.name=Lens itemGroup.buildcraft.blocks=Buildcraft Blocks itemGroup.buildcraft.boards=Buildcraft Robots diff --git a/buildcraft_resources/assets/buildcraft/textures/blocks/pipeLens.png b/buildcraft_resources/assets/buildcraft/textures/blocks/pipeLens.png new file mode 100644 index 00000000..b7c64104 Binary files /dev/null and b/buildcraft_resources/assets/buildcraft/textures/blocks/pipeLens.png differ diff --git a/buildcraft_resources/assets/buildcraft/textures/items/pipeLensItem0.png b/buildcraft_resources/assets/buildcraft/textures/items/pipeLensItem0.png new file mode 100644 index 00000000..3f37533a Binary files /dev/null and b/buildcraft_resources/assets/buildcraft/textures/items/pipeLensItem0.png differ diff --git a/buildcraft_resources/assets/buildcraft/textures/items/pipeLensItem1.png b/buildcraft_resources/assets/buildcraft/textures/items/pipeLensItem1.png new file mode 100644 index 00000000..166d1248 Binary files /dev/null and b/buildcraft_resources/assets/buildcraft/textures/items/pipeLensItem1.png differ diff --git a/common/buildcraft/BuildCraftTransport.java b/common/buildcraft/BuildCraftTransport.java index 2f7ec1e5..a1095eec 100644 --- a/common/buildcraft/BuildCraftTransport.java +++ b/common/buildcraft/BuildCraftTransport.java @@ -60,10 +60,12 @@ import buildcraft.transport.FacadePluggable; import buildcraft.transport.GuiHandler; import buildcraft.transport.ItemFacade; import buildcraft.transport.ItemGateCopier; +import buildcraft.transport.ItemLens; import buildcraft.transport.ItemPipe; import buildcraft.transport.ItemPipeWire; import buildcraft.transport.ItemPlug; import buildcraft.transport.ItemRobotStation; +import buildcraft.transport.LensPluggable; import buildcraft.transport.Pipe; import buildcraft.transport.PipeActionProvider; import buildcraft.transport.PipeColoringRecipe; @@ -166,6 +168,7 @@ public class BuildCraftTransport extends BuildCraftMod { public static Item pipeGate; public static Item pipeWire; public static Item plugItem; + public static Item lensItem; public static Item robotStationItem; public static Item pipeStructureCobblestone; public static Item gateCopier; @@ -430,6 +433,10 @@ public class BuildCraftTransport extends BuildCraftMod { plugItem.setUnlocalizedName("pipePlug"); CoreProxy.proxy.registerItem(plugItem); + lensItem = new ItemLens(); + lensItem.setUnlocalizedName("pipeLens"); + CoreProxy.proxy.registerItem(lensItem); + robotStationItem = new ItemRobotStation(); robotStationItem.setUnlocalizedName("robotStation"); CoreProxy.proxy.registerItem(robotStationItem); @@ -508,6 +515,7 @@ public class BuildCraftTransport extends BuildCraftMod { PipeManager.registerPipePluggable(FacadePluggable.class, "facade"); PipeManager.registerPipePluggable(GatePluggable.class, "gate"); + PipeManager.registerPipePluggable(LensPluggable.class, "lens"); PipeManager.registerPipePluggable(PlugPluggable.class, "plug"); PipeManager.registerPipePluggable(RobotStationPluggable.class, "robotStation"); diff --git a/common/buildcraft/transport/FacadePluggable.java b/common/buildcraft/transport/FacadePluggable.java index f612af33..16fd8e8d 100644 --- a/common/buildcraft/transport/FacadePluggable.java +++ b/common/buildcraft/transport/FacadePluggable.java @@ -98,21 +98,19 @@ public class FacadePluggable extends PipePluggable { activeState = states.length > 0 ? states[0] : null; } - data.writeBoolean(activeState == null ? false : activeState.hollow); - if (activeState == null || activeState.block == null) { data.writeShort(0); } else { data.writeShort(Block.getIdFromBlock(activeState.block)); } - data.writeByte(activeState == null ? 0 : activeState.metadata); - data.writeBoolean(activeState == null ? false : activeState.transparent); + data.writeByte((activeState != null && activeState.transparent ? 128 : 0) | + (activeState != null && activeState.hollow ? 64 : 0) | + (activeState == null ? 0 : activeState.metadata)); } @Override public void readData(ByteBuf data) { - renderAsHollow = data.readBoolean(); int blockId = data.readUnsignedShort(); if (blockId > 0) { @@ -121,8 +119,11 @@ public class FacadePluggable extends PipePluggable { block = null; } - meta = data.readByte(); - transparent = data.readBoolean(); + int flags = data.readUnsignedByte(); + + meta = flags & 0x0F; + transparent = (flags & 0x80) > 0; + renderAsHollow = (flags & 0x40) > 0; } protected void setActiveState(int id) { diff --git a/common/buildcraft/transport/ItemLens.java b/common/buildcraft/transport/ItemLens.java new file mode 100755 index 00000000..7d14a1b6 --- /dev/null +++ b/common/buildcraft/transport/ItemLens.java @@ -0,0 +1,89 @@ +/** + * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team + * 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 java.util.List; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraftforge.common.util.ForgeDirection; +import buildcraft.api.pipes.IPipe; +import buildcraft.api.pipes.IPipePluggableItem; +import buildcraft.api.pipes.PipePluggable; +import buildcraft.core.ItemBuildCraft; +import buildcraft.core.utils.ColorUtils; +import buildcraft.core.utils.StringUtils; + +public class ItemLens extends ItemBuildCraft implements IPipePluggableItem { + + private IIcon[] icons; + + public ItemLens() { + super(); + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIconFromDamageForRenderPass(int meta, int pass) + { + return icons[pass & 1]; + } + + @Override + @SideOnly(Side.CLIENT) + public boolean requiresMultipleRenderPasses() + { + return true; + } + + @Override + @SideOnly(Side.CLIENT) + public int getColorFromItemStack(ItemStack stack, int pass) { + return pass == 1 ? ColorUtils.getRGBColor(15 - stack.getItemDamage()) : 16777215; + } + + @Override + public String getItemStackDisplayName(ItemStack itemstack) { + return StringUtils.localize("item.Lens.name") + " (" + StringUtils.localize("color." + ColorUtils.getName(15 - itemstack.getItemDamage())) + ")"; + } + + @Override + public boolean doesSneakBypassUse(World world, int x, int y, int z, EntityPlayer player) { + return true; + } + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister register) { + icons = new IIcon[] { + register.registerIcon("buildcraft:pipeLensItem0"), + register.registerIcon("buildcraft:pipeLensItem1") + }; + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + @Override + @SideOnly(Side.CLIENT) + public void getSubItems(Item item, CreativeTabs tab, List itemList) { + for (int i = 0; i < 16; i++) { + itemList.add(new ItemStack(item, 1, i)); + } + } + + @Override + public PipePluggable createPipePluggable(IPipe pipe, ForgeDirection side, ItemStack stack) { + return new LensPluggable(stack); + } +} diff --git a/common/buildcraft/transport/LensPluggable.java b/common/buildcraft/transport/LensPluggable.java new file mode 100644 index 00000000..8b9f0624 --- /dev/null +++ b/common/buildcraft/transport/LensPluggable.java @@ -0,0 +1,110 @@ +package buildcraft.transport; + +import io.netty.buffer.ByteBuf; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.AxisAlignedBB; +import net.minecraftforge.common.util.ForgeDirection; +import buildcraft.BuildCraftTransport; +import buildcraft.api.core.EnumColor; +import buildcraft.api.core.render.ITextureStates; +import buildcraft.api.pipes.IPipe; +import buildcraft.api.pipes.IPipeContainer; +import buildcraft.api.pipes.IPipePluggableRenderer; +import buildcraft.api.pipes.PipePluggable; +import buildcraft.core.utils.MatrixTranformations; +import buildcraft.transport.pipes.events.PipeEventItem; + +public class LensPluggable extends PipePluggable { + private int color; + private ForgeDirection side; + + public class LensPluggableRenderer implements IPipePluggableRenderer { + private static final float zFightOffset = 1 / 4096.0F; + + @Override + public void renderPluggable(RenderBlocks renderblocks, IPipe pipe, ForgeDirection side, PipePluggable pipePluggable, ITextureStates blockStateMachine, int renderPass, int x, int y, int z) { + } + } + + public LensPluggable() { + + } + + public LensPluggable(ItemStack stack) { + color = stack.getItemDamage() & 15; + } + + @Override + public void validate(IPipeContainer pipe, ForgeDirection direction) { + side = direction; + } + + @Override + public ItemStack[] getDropItems(IPipeContainer pipe) { + return new ItemStack[]{ new ItemStack(BuildCraftTransport.lensItem, 1, color) }; + } + + @Override + public boolean isBlocking(IPipeContainer pipe, ForgeDirection direction) { + return false; + } + + @Override + public AxisAlignedBB getBoundingBox(ForgeDirection side) { + float[][] bounds = new float[3][2]; + // X START - END + bounds[0][0] = 0.25F - 0.0625F; + bounds[0][1] = 0.75F + 0.0625F; + // Y START - END + bounds[1][0] = 0.000F; + bounds[1][1] = 0.125F; + // Z START - END + bounds[2][0] = 0.25F - 0.0625F; + bounds[2][1] = 0.75F + 0.0625F; + + MatrixTranformations.transform(bounds, side); + return AxisAlignedBB.getBoundingBox(bounds[0][0], bounds[1][0], bounds[2][0], bounds[0][1], bounds[1][1], bounds[2][1]); + } + + @Override + public IPipePluggableRenderer getRenderer() { + return null; + } + + @Override + public void readFromNBT(NBTTagCompound tag) { + color = tag.getByte("c"); + } + + @Override + public void writeToNBT(NBTTagCompound tag) { + tag.setByte("c", (byte) color); + } + + @Override + public void writeData(ByteBuf data) { + data.writeByte(color); + } + + @Override + public void readData(ByteBuf data) { + color = data.readByte(); + } + + private void color(TravelingItem item) { + if ((item.toCenter && item.input.getOpposite() == side) + || (!item.toCenter && item.output == side)) { + item.color = EnumColor.fromId(color); + } + } + + public void eventHandler(PipeEventItem.ReachedEnd event) { + color(event.item); + } + + public void eventHandler(PipeEventItem.Entered event) { + color(event.item); + } +} diff --git a/common/buildcraft/transport/PipeIconProvider.java b/common/buildcraft/transport/PipeIconProvider.java index 7f078346..95613658 100644 --- a/common/buildcraft/transport/PipeIconProvider.java +++ b/common/buildcraft/transport/PipeIconProvider.java @@ -135,6 +135,7 @@ public class PipeIconProvider implements IIconProvider { Stripes("pipeStripes"), // PipeStainedOverlay("pipeStainedOverlay"), + PipeLens("pipeLens"), // TransparentFacade("transparent_facade"), Transparent("transparent"), diff --git a/common/buildcraft/transport/PipeTransportItems.java b/common/buildcraft/transport/PipeTransportItems.java index da746dd5..ed138490 100644 --- a/common/buildcraft/transport/PipeTransportItems.java +++ b/common/buildcraft/transport/PipeTransportItems.java @@ -97,7 +97,6 @@ public class PipeTransportItems extends PipeTransport { readjustSpeed(item); readjustPosition(item); - if (!container.getWorldObj().isRemote) { item.output = resolveDestination(item); } @@ -446,7 +445,6 @@ public class PipeTransportItems extends PipeTransport { item.input = packet.getInputOrientation(); item.output = packet.getOutputOrientation(); item.color = packet.getColor(); - } private void sendTravelerPacket(TravelingItem data, boolean forceStackRefresh) { diff --git a/common/buildcraft/transport/PlugPluggable.java b/common/buildcraft/transport/PlugPluggable.java index 26ae7547..c1d0e4f8 100644 --- a/common/buildcraft/transport/PlugPluggable.java +++ b/common/buildcraft/transport/PlugPluggable.java @@ -55,7 +55,6 @@ public class PlugPluggable extends PipePluggable { zeroState[2][1] = 0.75F - 0.125F / 2; blockStateMachine.getTextureState().set(BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal())); // Structure Pipe - rotated = MatrixTranformations.deepClone(zeroState); MatrixTranformations.transform(rotated, side); diff --git a/common/buildcraft/transport/TileGenericPipe.java b/common/buildcraft/transport/TileGenericPipe.java index 249d7292..3f0eac1e 100644 --- a/common/buildcraft/transport/TileGenericPipe.java +++ b/common/buildcraft/transport/TileGenericPipe.java @@ -353,6 +353,7 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler, for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) { if (sideProperties.pluggables[i] != null) { sideProperties.pluggables[i].onAttachedPipe(this, ForgeDirection.getOrientation(i)); + pipe.eventBus.registerHandler(sideProperties.pluggables[i]); } } } diff --git a/common/buildcraft/transport/network/PacketFluidUpdate.java b/common/buildcraft/transport/network/PacketFluidUpdate.java index d61ad0ec..0be8a768 100644 --- a/common/buildcraft/transport/network/PacketFluidUpdate.java +++ b/common/buildcraft/transport/network/PacketFluidUpdate.java @@ -88,7 +88,7 @@ public class PacketFluidUpdate extends PacketCoordinates { if (renderCache[dir.ordinal()] == null) { renderCache[dir.ordinal()] = new FluidStack(0, 0); } - renderCache[dir.ordinal()].amount = Math.min(transLiq.getCapacity(), data.readInt()); + renderCache[dir.ordinal()].amount = Math.min(transLiq.getCapacity(), data.readUnsignedShort()); } } } @@ -115,9 +115,9 @@ public class PacketFluidUpdate extends PacketCoordinates { } if (delta.get(dir.ordinal() * FLUID_DATA_NUM + FLUID_AMOUNT_BIT)) { if (liquid != null) { - data.writeInt(liquid.amount); + data.writeShort(liquid.amount); } else { - data.writeInt(0); + data.writeShort(0); } } } diff --git a/common/buildcraft/transport/network/PacketPipeTransportTraveler.java b/common/buildcraft/transport/network/PacketPipeTransportTraveler.java index 8232ab8f..62b6ae5e 100644 --- a/common/buildcraft/transport/network/PacketPipeTransportTraveler.java +++ b/common/buildcraft/transport/network/PacketPipeTransportTraveler.java @@ -51,14 +51,12 @@ public class PacketPipeTransportTraveler extends BuildCraftPacket { data.writeShort(item.id); - data.writeByte((byte) item.input.ordinal()); - data.writeByte((byte) item.output.ordinal()); + byte flags = (byte) ((item.output.ordinal() & 7) | ((item.input.ordinal() & 7) << 3) | (forceStackRefresh ? 64 : 0)); + data.writeByte(flags); data.writeByte(item.color != null ? item.color.ordinal() : -1); data.writeFloat(item.getSpeed()); - - data.writeBoolean(forceStackRefresh); } @Override @@ -73,8 +71,10 @@ public class PacketPipeTransportTraveler extends BuildCraftPacket { this.entityId = data.readShort(); - this.input = ForgeDirection.getOrientation(data.readByte()); - this.output = ForgeDirection.getOrientation(data.readByte()); + int flags = data.readUnsignedByte(); + + this.input = ForgeDirection.getOrientation((flags >> 3) & 7); + this.output = ForgeDirection.getOrientation(flags & 7); byte c = data.readByte(); if (c != -1) { @@ -83,7 +83,7 @@ public class PacketPipeTransportTraveler extends BuildCraftPacket { this.speed = data.readFloat(); - this.forceStackRefresh = data.readBoolean(); + this.forceStackRefresh = (flags & 0x40) > 0; } public int getTravelingEntityId() {