One pipe can now extract from multiple machines
parent
374855f901
commit
249eed4fb3
|
@ -30,6 +30,7 @@ import steamcraft.common.tiles.container.ContainerPipeConnections;
|
|||
public class GuiPipeConnections extends BaseContainerGui
|
||||
{
|
||||
private static ResourceLocation guitexture = new ResourceLocation(ModInfo.PREFIX + "textures/gui/changeextractions.png");
|
||||
private static String[] buttonNames = new String[]{"Insert", "Extract"};
|
||||
|
||||
private InventoryPlayer player;
|
||||
private TileCopperPipe tile;
|
||||
|
@ -48,12 +49,12 @@ public class GuiPipeConnections extends BaseContainerGui
|
|||
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_)
|
||||
{
|
||||
this.fontRendererObj.drawString("Change Extraction", 60, 6, 4210752);
|
||||
this.fontRendererObj.drawString("North:", 20, 26, 4210752);
|
||||
this.fontRendererObj.drawString("South:", 115, 26, 4210752);
|
||||
this.fontRendererObj.drawString("West:", 20, 56, 4210752);
|
||||
this.fontRendererObj.drawString("East:", 115, 56, 4210752);
|
||||
this.fontRendererObj.drawString("Up:", 20, 86, 4210752);
|
||||
this.fontRendererObj.drawString("Down:", 115, 86, 4210752);
|
||||
this.fontRendererObj.drawString("Up:", 20, 26, 4210752);
|
||||
this.fontRendererObj.drawString("Down:", 115, 26, 4210752);
|
||||
this.fontRendererObj.drawString("North:", 20, 56, 4210752);
|
||||
this.fontRendererObj.drawString("South:", 115, 56, 4210752);
|
||||
this.fontRendererObj.drawString("West:", 20, 86, 4210752);
|
||||
this.fontRendererObj.drawString("East:", 115, 86, 4210752);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,34 +66,24 @@ public class GuiPipeConnections extends BaseContainerGui
|
|||
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
super.initGui();
|
||||
buttonList.clear();
|
||||
|
||||
ForgeDirection[] connections = tile.getConnections();
|
||||
ForgeDirection[] connections = tile.getExtractableConnections();
|
||||
ForgeDirection[] extractions = tile.getExtractions();
|
||||
|
||||
GuiButton north = new GuiButton(0, guiLeft + 55, guiTop + 20, 44, 20, "Insert");
|
||||
GuiButton south = new GuiButton(4, guiLeft + 150, guiTop + 20, 44, 20, "Insert");
|
||||
if (connections[2] == null)
|
||||
north.enabled = false;
|
||||
if (connections[3] == null)
|
||||
south.enabled = false;
|
||||
GuiButton up = this.createGuiButton(0, guiLeft + 55, guiTop + 20, 44, 20, connections, extractions);
|
||||
GuiButton down = this.createGuiButton(1, guiLeft + 150, guiTop + 20, 44, 20, connections, extractions);
|
||||
|
||||
GuiButton west = new GuiButton(2, guiLeft + 55, guiTop + 50, 44, 20, "Insert");
|
||||
GuiButton east = new GuiButton(3, guiLeft + 150, guiTop + 50, 44, 20, "Insert");
|
||||
if (connections[4] == null)
|
||||
west.enabled = false;
|
||||
if (connections[5] == null)
|
||||
east.enabled = false;
|
||||
GuiButton north = this.createGuiButton(2, guiLeft + 55, guiTop + 50, 44, 20, connections, extractions);
|
||||
GuiButton south = this.createGuiButton(3, guiLeft + 150, guiTop + 50, 44, 20, connections, extractions);
|
||||
|
||||
GuiButton up = new GuiButton(1, guiLeft + 55, guiTop + 80, 44, 20, "Insert");
|
||||
GuiButton down = new GuiButton(5, guiLeft + 150, guiTop + 80, 44, 20, "Insert");
|
||||
if (connections[0] == null)
|
||||
up.enabled = false;
|
||||
if (connections[1] == null)
|
||||
down.enabled = false;
|
||||
GuiButton west = this.createGuiButton(4, guiLeft + 55, guiTop + 80, 44, 20, connections, extractions);
|
||||
GuiButton east = this.createGuiButton(5, guiLeft + 150, guiTop + 80, 44, 20, connections, extractions);
|
||||
|
||||
buttonList.add(north);
|
||||
buttonList.add(south);
|
||||
|
@ -102,6 +93,16 @@ public class GuiPipeConnections extends BaseContainerGui
|
|||
buttonList.add(down);
|
||||
}
|
||||
|
||||
private GuiButton createGuiButton(int index, int x, int y, int xx, int yy, ForgeDirection[] connections, ForgeDirection[] extractions)
|
||||
{
|
||||
GuiButton button = new GuiButton(index, x, y, xx, yy, extractions[index] == null ? buttonNames[0] : buttonNames[1]);
|
||||
|
||||
if (connections[index] == null)
|
||||
button.enabled = false;
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button)
|
||||
{
|
||||
|
|
|
@ -50,20 +50,31 @@ public class TileCopperPipeRenderer extends TileEntitySpecialRenderer
|
|||
|
||||
TileCopperPipe pipe = (TileCopperPipe) tile;
|
||||
|
||||
ForgeDirection opposite = pipe.onlyOneOpposite();
|
||||
boolean isStraight = true;
|
||||
for (ForgeDirection dir : pipe.extractions)
|
||||
if (dir != null)
|
||||
{
|
||||
isStraight = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((opposite != null) && (pipe.extract == null) && pipe.isPipe(opposite) && pipe.isPipe(opposite.getOpposite()))
|
||||
ForgeDirection opposite = null;
|
||||
|
||||
if (isStraight && ((opposite = pipe.onlyOneOpposite()) != null) && pipe.isPipe(opposite) && pipe.isPipe(opposite.getOpposite()))
|
||||
this.drawStraightConnection(opposite, pipe);
|
||||
else
|
||||
{
|
||||
this.drawCore(pipe);
|
||||
|
||||
for (ForgeDirection dir : pipe.connections)
|
||||
for (int i = 0;i < 6;i++)
|
||||
{
|
||||
ForgeDirection dir = pipe.connections[i];
|
||||
if (dir != null)
|
||||
if (pipe.extract == dir)
|
||||
if (pipe.extractions[i] != null)
|
||||
this.drawAlternateConnection(dir, pipe);
|
||||
else
|
||||
this.drawConnection(dir, pipe);
|
||||
}
|
||||
}
|
||||
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
|
|
|
@ -34,19 +34,19 @@ public class CopperPipePacket implements IMessage
|
|||
{
|
||||
private int x, y, z;
|
||||
ForgeDirection[] connections;
|
||||
ForgeDirection extract;
|
||||
ForgeDirection[] extractions;
|
||||
|
||||
public CopperPipePacket()
|
||||
{
|
||||
} // REQUIRED
|
||||
|
||||
public CopperPipePacket(int x, int y, int z, ForgeDirection[] connections, ForgeDirection extract)
|
||||
public CopperPipePacket(int x, int y, int z, ForgeDirection[] connections, ForgeDirection[] extractions)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.connections = connections;
|
||||
this.extract = extract;
|
||||
this.extractions = extractions;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -66,9 +66,15 @@ public class CopperPipePacket implements IMessage
|
|||
this.connections[i] = null;
|
||||
}
|
||||
|
||||
this.extract = ForgeDirection.getOrientation(buf.readByte());
|
||||
if (this.extract == ForgeDirection.UNKNOWN)
|
||||
this.extract = null;
|
||||
this.extractions = new ForgeDirection[6];
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
this.extractions[i] = ForgeDirection.getOrientation(buf.readByte());
|
||||
|
||||
if (this.extractions[i] == ForgeDirection.UNKNOWN)
|
||||
this.extractions[i] = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -77,9 +83,12 @@ public class CopperPipePacket implements IMessage
|
|||
buf.writeInt(this.x);
|
||||
buf.writeInt(this.y);
|
||||
buf.writeInt(this.z);
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
buf.writeByte(directionToByte(this.connections[i]));
|
||||
buf.writeByte(directionToByte(this.extract));
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
buf.writeByte(directionToByte(this.extractions[i]));
|
||||
}
|
||||
|
||||
public static byte directionToByte(ForgeDirection dir)
|
||||
|
@ -128,7 +137,7 @@ public class CopperPipePacket implements IMessage
|
|||
TileCopperPipe pipe = (TileCopperPipe) world.getTileEntity(message.x, message.y, message.z);
|
||||
|
||||
pipe.connections = message.connections;
|
||||
pipe.extract = message.extract;
|
||||
pipe.extractions = message.extractions;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -26,6 +26,7 @@ import net.minecraft.network.Packet;
|
|||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
@ -46,8 +47,7 @@ import steamcraft.common.tiles.container.ContainerPipeConnections;
|
|||
*/
|
||||
public class TileCopperPipe extends TileEntity implements IFluidHandler, ISpannerTile, IOpenableGUI
|
||||
{
|
||||
private static int ticksTillFluidUpdate = 200; // update the fluid in pipe
|
||||
// every 10 seconds
|
||||
private static int ticksTillFluidUpdate = 200; // update the fluid in pipe every 10 seconds
|
||||
|
||||
private static int copperPipeCapacity = 500;
|
||||
private static int copperPipeExtract = 50;
|
||||
|
@ -62,11 +62,10 @@ public class TileCopperPipe extends TileEntity implements IFluidHandler, ISpanne
|
|||
|
||||
public Fluid fluidInPipe;
|
||||
public float fluidScaled = 0;
|
||||
private int ticksSinceUpdate = ticksTillFluidUpdate / 2; // first time
|
||||
// update faster
|
||||
private int ticksSinceUpdate = ticksTillFluidUpdate / 2; // first time update faster
|
||||
|
||||
public ForgeDirection[] connections = new ForgeDirection[6];
|
||||
public ForgeDirection extract = null;
|
||||
public ForgeDirection[] extractions = new ForgeDirection[6];
|
||||
private Coords masterCoords = null;
|
||||
|
||||
private static float pixel = 1F / 16f;
|
||||
|
@ -125,8 +124,19 @@ public class TileCopperPipe extends TileEntity implements IFluidHandler, ISpanne
|
|||
{
|
||||
super.writeToNBT(tag);
|
||||
|
||||
writeDirectionToNBT(tag, this.extract);
|
||||
NBTTagList extractions = new NBTTagList();
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
if (this.extractions[i] != null)
|
||||
{
|
||||
NBTTagCompound conn = new NBTTagCompound();
|
||||
conn.setByte("index", (byte) i);
|
||||
writeDirectionToNBT(conn, this.extractions[i]);
|
||||
|
||||
extractions.appendTag(conn);
|
||||
}
|
||||
|
||||
tag.setTag("extractions", extractions);
|
||||
tag.setBoolean("master", this.isMaster);
|
||||
|
||||
if (this.isMaster)
|
||||
|
@ -171,7 +181,14 @@ public class TileCopperPipe extends TileEntity implements IFluidHandler, ISpanne
|
|||
{
|
||||
super.readFromNBT(tag);
|
||||
|
||||
this.extract = readDirectionFromNBT(tag);
|
||||
NBTTagList extractions = tag.getTagList("extractions", Constants.NBT.TAG_LIST);
|
||||
|
||||
for (int i = 0; i < extractions.tagCount(); i++)
|
||||
{
|
||||
NBTTagCompound dirTag = extractions.getCompoundTagAt(i);
|
||||
|
||||
this.extractions[dirTag.getByte("index")] = readDirectionFromNBT(dirTag);
|
||||
}
|
||||
|
||||
this.isMaster = tag.getBoolean("master");
|
||||
|
||||
|
@ -199,7 +216,17 @@ public class TileCopperPipe extends TileEntity implements IFluidHandler, ISpanne
|
|||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
|
||||
writeDirectionToNBT(tag, this.extract);
|
||||
NBTTagList extractions = new NBTTagList();
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
if (this.extractions[i] != null)
|
||||
{
|
||||
NBTTagCompound conn = new NBTTagCompound();
|
||||
conn.setByte("index", (byte) i);
|
||||
writeDirectionToNBT(conn, this.extractions[i]);
|
||||
|
||||
extractions.appendTag(conn);
|
||||
}
|
||||
|
||||
NBTTagList connections = new NBTTagList();
|
||||
|
||||
|
@ -213,6 +240,7 @@ public class TileCopperPipe extends TileEntity implements IFluidHandler, ISpanne
|
|||
connections.appendTag(conn);
|
||||
}
|
||||
|
||||
tag.setTag("extractions", extractions);
|
||||
tag.setTag("connections", connections);
|
||||
|
||||
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, tag);
|
||||
|
@ -221,7 +249,16 @@ public class TileCopperPipe extends TileEntity implements IFluidHandler, ISpanne
|
|||
@Override
|
||||
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet)
|
||||
{
|
||||
this.extract = readDirectionFromNBT(packet.func_148857_g());
|
||||
this.extractions = new ForgeDirection[6];
|
||||
|
||||
NBTTagList extractions = (NBTTagList) packet.func_148857_g().getTag("extractions");
|
||||
|
||||
for (int i = 0; i < extractions.tagCount(); i++)
|
||||
{
|
||||
NBTTagCompound tag = extractions.getCompoundTagAt(i);
|
||||
|
||||
this.extractions[tag.getByte("index")] = readDirectionFromNBT(tag);
|
||||
}
|
||||
|
||||
this.connections = new ForgeDirection[6];
|
||||
|
||||
|
@ -240,39 +277,58 @@ public class TileCopperPipe extends TileEntity implements IFluidHandler, ISpanne
|
|||
{
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
if (this.extract != null)
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
Coords temp = new Coords(this.xCoord + this.extract.offsetX, this.yCoord + this.extract.offsetY, this.zCoord + this.extract.offsetZ,
|
||||
this.extract.getOpposite());
|
||||
ForgeDirection dir = this.connections[i];
|
||||
|
||||
this.network.inputs.remove(temp);
|
||||
if (!this.network.outputs.contains(temp))
|
||||
this.network.outputs.add(temp);
|
||||
if ((dir != null) && this.isFluidHandler(dir))
|
||||
{
|
||||
Coords temp = new Coords(this.xCoord + dir.offsetX, this.yCoord + dir.offsetY,
|
||||
this.zCoord + dir.offsetZ, dir.getOpposite());
|
||||
|
||||
this.extract = null;
|
||||
}
|
||||
else
|
||||
for (ForgeDirection dir : this.connections)
|
||||
if ((dir != null) && this.isFluidHandler(dir))
|
||||
if (this.extractions[i] == null)
|
||||
{
|
||||
this.extract = dir;
|
||||
|
||||
Coords temp = new Coords(this.xCoord + this.extract.offsetX, this.yCoord + this.extract.offsetY,
|
||||
this.zCoord + this.extract.offsetZ, this.extract.getOpposite());
|
||||
this.extractions[i] = dir;
|
||||
|
||||
this.network.outputs.remove(temp);
|
||||
|
||||
if (!this.network.inputs.contains(temp))
|
||||
this.network.inputs.add(temp);
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.extractions[i] = null;
|
||||
|
||||
this.network.inputs.remove(temp);
|
||||
|
||||
if (!this.network.outputs.contains(temp))
|
||||
this.network.outputs.add(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.updateClientConnections();
|
||||
}
|
||||
}
|
||||
|
||||
public ForgeDirection[] getConnections()
|
||||
public ForgeDirection[] getExtractableConnections()
|
||||
{
|
||||
return this.connections;
|
||||
ForgeDirection[] extractableConnections = new ForgeDirection[6];
|
||||
|
||||
for(int i = 0;i < 6;i++)
|
||||
{
|
||||
ForgeDirection dir = this.connections[i];
|
||||
if (dir != null && this.isFluidHandler(dir))
|
||||
extractableConnections[i] = dir;
|
||||
}
|
||||
|
||||
return extractableConnections;
|
||||
}
|
||||
|
||||
public ForgeDirection[] getExtractions()
|
||||
{
|
||||
return this.extractions;
|
||||
}
|
||||
|
||||
private void removeConnections(int i)
|
||||
|
@ -284,14 +340,10 @@ public class TileCopperPipe extends TileEntity implements IFluidHandler, ISpanne
|
|||
Coords temp = new Coords(this.xCoord + dir.offsetX, this.yCoord + dir.offsetY, this.zCoord + dir.offsetZ, dir.getOpposite());
|
||||
|
||||
this.network.outputs.remove(temp);
|
||||
|
||||
if (this.connections[i] == this.extract)
|
||||
this.network.inputs.remove(temp);
|
||||
this.network.inputs.remove(temp);
|
||||
}
|
||||
|
||||
if (this.extract == this.connections[i])
|
||||
this.extract = null;
|
||||
|
||||
this.extractions[i] = null;
|
||||
this.connections[i] = null;
|
||||
}
|
||||
|
||||
|
@ -372,12 +424,14 @@ public class TileCopperPipe extends TileEntity implements IFluidHandler, ISpanne
|
|||
this.setMaster(this);
|
||||
}
|
||||
|
||||
for (ForgeDirection dir : this.connections)
|
||||
for (int i = 0;i < 6;i++)
|
||||
{
|
||||
ForgeDirection dir = this.connections[i];
|
||||
if ((dir != null) && this.isFluidHandler(dir))
|
||||
{
|
||||
Coords temp = new Coords(this.xCoord + dir.offsetX, this.yCoord + dir.offsetY, this.zCoord + dir.offsetZ, dir.getOpposite());
|
||||
|
||||
if (this.extract != dir)
|
||||
if (this.extractions[i] == null)
|
||||
{
|
||||
if (!this.network.outputs.contains(temp))
|
||||
this.network.outputs.add(temp);
|
||||
|
@ -385,6 +439,7 @@ public class TileCopperPipe extends TileEntity implements IFluidHandler, ISpanne
|
|||
else if (!this.network.inputs.contains(temp))
|
||||
this.network.inputs.add(temp);
|
||||
}
|
||||
}
|
||||
|
||||
this.updateClientConnections();
|
||||
}
|
||||
|
@ -394,7 +449,7 @@ public class TileCopperPipe extends TileEntity implements IFluidHandler, ISpanne
|
|||
{
|
||||
if (this.network != null)
|
||||
{
|
||||
InitPackets.network.sendToAllAround(new CopperPipePacket(this.xCoord, this.yCoord, this.zCoord, this.connections, this.extract),
|
||||
InitPackets.network.sendToAllAround(new CopperPipePacket(this.xCoord, this.yCoord, this.zCoord, this.connections, this.extractions),
|
||||
new TargetPoint(this.worldObj.provider.dimensionId, this.xCoord, this.yCoord, this.zCoord, 100));
|
||||
}
|
||||
}
|
||||
|
@ -626,21 +681,38 @@ public class TileCopperPipe extends TileEntity implements IFluidHandler, ISpanne
|
|||
@Override
|
||||
public boolean canDrain(ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
return (from != this.extract) && (this.network != null)
|
||||
for (ForgeDirection dir : this.extractions)
|
||||
if (dir == from)
|
||||
return false;
|
||||
|
||||
return (this.network != null)
|
||||
&& ((this.network.tank.getFluid() == null) || (this.network.tank.getFluid().getFluid() == fluid));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill(ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
return (from == this.extract) && (this.network != null)
|
||||
boolean canFill = false;
|
||||
for (ForgeDirection dir : this.extractions)
|
||||
if (dir == from)
|
||||
{
|
||||
canFill = true;
|
||||
break;
|
||||
}
|
||||
|
||||
return canFill && (this.network != null)
|
||||
&& ((this.network.tank.getFluid() == null) || (this.network.tank.getFluid().getFluid() == fluid));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
|
||||
{
|
||||
if ((from != this.extract) && (this.network != null) && (this.network.tank.getFluid() != null)
|
||||
for (ForgeDirection dir : this.extractions)
|
||||
if (dir == from)
|
||||
return null;
|
||||
|
||||
|
||||
if ((this.network != null) && (this.network.tank.getFluid() != null)
|
||||
&& this.network.tank.getFluid().isFluidEqual(resource))
|
||||
{
|
||||
int amount = Math.min(resource.amount, this.pipeTransfer);
|
||||
|
@ -654,7 +726,11 @@ public class TileCopperPipe extends TileEntity implements IFluidHandler, ISpanne
|
|||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
|
||||
{
|
||||
if ((from != this.extract) && (this.network != null) && (this.network.tank.getFluid() != null))
|
||||
for (ForgeDirection dir : this.extractions)
|
||||
if (dir == from)
|
||||
return null;
|
||||
|
||||
if ((this.network != null) && (this.network.tank.getFluid() != null))
|
||||
{
|
||||
int amount = Math.min(maxDrain, this.pipeTransfer);
|
||||
|
||||
|
@ -667,7 +743,15 @@ public class TileCopperPipe extends TileEntity implements IFluidHandler, ISpanne
|
|||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
|
||||
{
|
||||
if ((this.extract == from) && (this.network != null))
|
||||
boolean canFill = false;
|
||||
for (ForgeDirection dir : this.extractions)
|
||||
if (dir == from)
|
||||
{
|
||||
canFill = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (canFill && (this.network != null))
|
||||
{
|
||||
int amount = Math.min(resource.amount, this.pipeExtract);
|
||||
|
||||
|
|
Loading…
Reference in New Issue