More salivation plant work

This commit is contained in:
Aidan C. Brady 2014-01-14 18:30:26 -05:00
parent e726e5039e
commit 98f3f544cd
5 changed files with 388 additions and 75 deletions

View file

@ -1,38 +1,171 @@
package mekanism.client.gui;
import java.util.List;
import java.util.ArrayList;
import mekanism.api.ListUtils;
import mekanism.client.gui.GuiEnergyInfo.IInfoHandler;
import mekanism.api.Coord4D;
import mekanism.api.gas.GasStack;
import mekanism.client.render.MekanismRenderer;
import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.inventory.container.ContainerSalinationController;
import mekanism.common.network.PacketTileEntity;
import mekanism.common.tile.TileEntitySalinationController;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.opengl.GL11;
public class GuiSalinationController extends GuiMekanism
{
TileEntitySalinationController tileEntity;
public TileEntitySalinationController tileEntity;
public GuiSalinationController(InventoryPlayer inventory, TileEntitySalinationController tentity)
{
super(tentity, new ContainerSalinationController(inventory, tentity));
tileEntity = tentity;
}
public GuiSalinationController(InventoryPlayer inventory, TileEntitySalinationController tentity)
{
super(tentity, new ContainerSalinationController(inventory, tentity));
tileEntity = tentity;
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY)
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
int xAxis = (mouseX - (width - xSize) / 2);
int yAxis = (mouseY - (height - ySize) / 2);
fontRenderer.drawString(tileEntity.getInvName(), 5, 5, 0x404040);
fontRenderer.drawString(MekanismUtils.localize("container.inventory"), 8, (ySize - 96) + 4, 0x404040);
if(xAxis >= 7 && xAxis <= 23 && yAxis >= 14 && yAxis <= 72)
{
drawCreativeTabHoveringText(tileEntity.waterTank.getFluid() != null ? tileEntity.waterTank.getFluid().getFluid().getLocalizedName() + ": " + tileEntity.waterTank.getFluidAmount() : MekanismUtils.localize("gui.empty"), xAxis, yAxis);
}
if(xAxis >= 153 && xAxis <= 169 && yAxis >= 14 && yAxis <= 72)
{
drawCreativeTabHoveringText(tileEntity.brineTank.getFluid() != null ? tileEntity.brineTank.getFluid().getFluid().getLocalizedName() + ": " + tileEntity.brineTank.getFluidAmount() : MekanismUtils.localize("gui.empty"), xAxis, yAxis);
}
if(xAxis >= 49 && xAxis <= 127 && yAxis >= 64 && yAxis <= 72)
{
drawCreativeTabHoveringText(getTemp(), xAxis, yAxis);
}
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
}
public String getTemp()
{
float temp = (float)Math.round((tileEntity.getTemperature()*200)*100)/100F;
return temp + " F";
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY)
{
super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY);
mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiSalinationController.png"));
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
int guiWidth = (width - xSize) / 2;
int guiHeight = (height - ySize) / 2;
drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize);
int xAxis = mouseX - guiWidth;
int yAxis = mouseY - guiHeight;
int displayInt;
if(tileEntity.getScaledWaterLevel(58) > 0)
{
displayGauge(7, 14, tileEntity.getScaledWaterLevel(58), tileEntity.waterTank.getFluid(), null);
}
if(tileEntity.getScaledBrineLevel(58) > 0)
{
displayGauge(153, 14, tileEntity.getScaledBrineLevel(58), tileEntity.brineTank.getFluid(), null);
}
displayInt = tileEntity.getScaledTempLevel(78);
drawTexturedModalRect(guiWidth + 49, guiHeight + 64, 176, 59, displayInt, 8);
}
@Override
protected void mouseClicked(int x, int y, int button)
{
super.mouseClicked(x, y, button);
if(button == 0)
{
int xAxis = (x - (width - xSize) / 2);
int yAxis = (y - (height - ySize) / 2);
if(xAxis > 44 && xAxis < 62 && yAxis > 13 && yAxis < 21)
{
ArrayList data = new ArrayList();
data.add(0);
PacketHandler.sendPacket(Transmission.SERVER, new PacketTileEntity().setParams(Coord4D.get(tileEntity), data));
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
}
else if(xAxis > 114 && xAxis < 132 && yAxis > 13 && yAxis < 21)
{
ArrayList data = new ArrayList();
data.add(1);
PacketHandler.sendPacket(Transmission.SERVER, new PacketTileEntity().setParams(Coord4D.get(tileEntity), data));
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
}
}
}
public void displayGauge(int xPos, int yPos, int scale, FluidStack fluid, GasStack gas)
{
super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY);
if(fluid == null && gas == null)
{
return;
}
int guiWidth = (width - xSize) / 2;
int guiHeight = (height - ySize) / 2;
int start = 0;
while(true)
{
int renderRemaining = 0;
if(scale > 16)
{
renderRemaining = 16;
scale -= 16;
}
else {
renderRemaining = scale;
scale = 0;
}
mc.renderEngine.bindTexture(MekanismRenderer.getBlocksTexture());
if(fluid != null)
{
drawTexturedModelRectFromIcon(guiWidth + xPos, guiHeight + yPos + 58 - renderRemaining - start, fluid.getFluid().getIcon(), 16, 16 - (16 - renderRemaining));
}
else if(gas != null)
{
drawTexturedModelRectFromIcon(guiWidth + xPos, guiHeight + yPos + 58 - renderRemaining - start, gas.getGas().getIcon(), 16, 16 - (16 - renderRemaining));
}
start+=16;
if(renderRemaining == 0 || scale == 0)
{
break;
}
}
mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiSalinationController.png"));
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
int guiWidth = (width - xSize) / 2;
int guiHeight = (height - ySize) / 2;
drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize);
drawTexturedModalRect(guiWidth + xPos, guiHeight + yPos, 176, 0, 16, 59);
}
}

View file

@ -158,11 +158,11 @@ public class BlockBasic extends Block
}
else if(metadata == 14)
{
TileEntityBasicBlock tileEntity = (TileEntityBasicBlock)world.getBlockTileEntity(x, y, z);
TileEntitySalinationController tileEntity = (TileEntitySalinationController)world.getBlockTileEntity(x, y, z);
if(side == tileEntity.facing)
{
return icons[14][0];
return tileEntity.structured ? icons[14][1] : icons[14][0];
}
else {
return icons[12][0];

View file

@ -1,44 +1,154 @@
package mekanism.common.inventory.container;
import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge;
import mekanism.common.inventory.slot.SlotOutput;
import mekanism.common.tile.TileEntitySalinationController;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
public class ContainerSalinationController extends Container
{
private TileEntitySalinationController tileEntity;
private TileEntitySalinationController tileEntity;
public ContainerSalinationController(InventoryPlayer inventory, TileEntitySalinationController tile)
{
tileEntity = tile;
public ContainerSalinationController(InventoryPlayer inventory, TileEntitySalinationController tentity)
{
tileEntity = tentity;
int slotX;
addSlotToContainer(new Slot(tentity, 0, 28, 20));
addSlotToContainer(new SlotOutput(tentity, 1, 28, 51));
addSlotToContainer(new Slot(tentity, 2, 132, 20));
addSlotToContainer(new SlotOutput(tentity, 3, 132, 51));
for(slotX = 0; slotX < 3; slotX++)
{
for(int slotY = 0; slotY < 9; slotY++)
{
addSlotToContainer(new Slot(inventory, slotY + slotX * 9 + 9, 8 + slotY * 18, 84 + slotX * 18));
}
}
int slotY;
for(slotX = 0; slotX < 9; ++slotX)
{
addSlotToContainer(new Slot(inventory, slotX, 8 + slotX * 18, 142));
}
for(slotY = 0; slotY < 3; ++slotY)
{
for(int slotX = 0; slotX < 9; ++slotX)
{
addSlotToContainer(new Slot(inventory, slotX + slotY * 9 + 9, 8 + slotX * 18, 84 + slotY * 18));
}
}
tileEntity.open(inventory.player);
tileEntity.openChest();
}
for(slotY = 0; slotY < 9; ++slotY)
{
addSlotToContainer(new Slot(inventory, slotY, 8 + slotY * 18, 142));
}
tileEntity.open(inventory.player);
tileEntity.openChest();
}
@Override
public void onContainerClosed(EntityPlayer entityplayer)
{
super.onContainerClosed(entityplayer);
tileEntity.close(entityplayer);
tileEntity.closeChest();
}
@Override
public boolean canInteractWith(EntityPlayer entityplayer)
public boolean canInteractWith(EntityPlayer entityplayer)
{
return tileEntity.isUseableByPlayer(entityplayer);
}
return tileEntity.isUseableByPlayer(entityplayer);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotID)
{
ItemStack stack = null;
Slot currentSlot = (Slot)inventorySlots.get(slotID);
if(currentSlot != null && currentSlot.getHasStack())
{
ItemStack slotStack = currentSlot.getStack();
stack = slotStack.copy();
if(slotID == 1 || slotID == 3)
{
if(!mergeItemStack(slotStack, 4, inventorySlots.size(), true))
{
return null;
}
}
else if(FluidContainerRegistry.isEmptyContainer(slotStack))
{
if(slotID != 2)
{
if(!mergeItemStack(slotStack, 2, 3, false))
{
return null;
}
}
else if(slotID == 2)
{
if(!mergeItemStack(slotStack, 4, inventorySlots.size(), true))
{
return null;
}
}
}
else if(FluidContainerRegistry.isFilledContainer(slotStack) && FluidContainerRegistry.getFluidForFilledItem(slotStack).getFluid() == FluidRegistry.WATER)
{
if(slotID != 0)
{
if(!mergeItemStack(slotStack, 0, 1, false))
{
return null;
}
}
else if(slotID == 0)
{
if(!mergeItemStack(slotStack, 4, inventorySlots.size(), true))
{
return null;
}
}
}
else {
if(slotID >= 4 && slotID <= 30)
{
if(!mergeItemStack(slotStack, 31, inventorySlots.size(), false))
{
return null;
}
}
else if(slotID > 30)
{
if(!mergeItemStack(slotStack, 4, 30, false))
{
return null;
}
}
else {
if(!mergeItemStack(slotStack, 4, inventorySlots.size(), true))
{
return null;
}
}
}
if(slotStack.stackSize == 0)
{
currentSlot.putStack((ItemStack)null);
}
else {
currentSlot.onSlotChanged();
}
if(slotStack.stackSize == stack.stackSize)
{
return null;
}
currentSlot.onPickupFromSlot(player, slotStack);
}
return stack;
}
}

View file

@ -6,13 +6,13 @@ import java.util.Set;
import mekanism.api.Coord4D;
import mekanism.common.IConfigurable;
import mekanism.common.IRedstoneControl.RedstoneControl;
import mekanism.common.tank.TankUpdateProtocol;
import mekanism.common.util.MekanismUtils;
import mekanism.generators.common.tile.TileEntityAdvancedSolarGenerator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatMessageComponent;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
@ -22,8 +22,11 @@ import com.google.common.io.ByteArrayDataInput;
public class TileEntitySalinationController extends TileEntitySalinationTank implements IConfigurable
{
public static int MAX_WATER = 100000;
public static int MAX_BRINE = 1000;
public static final int MAX_WATER = 100000;
public static final int MAX_BRINE = 1000;
public static final int MAX_SOLARS = 4;
public static final int WARMUP = 300;
public FluidTank waterTank = new FluidTank(MAX_WATER);
public FluidTank brineTank = new FluidTank(MAX_BRINE);
@ -36,7 +39,7 @@ public class TileEntitySalinationController extends TileEntitySalinationTank imp
public double partialWater = 0;
public double partialBrine = 0;
public float baseTemperature = 0;
public float temperature = 0;
public int height = 0;
@ -51,6 +54,8 @@ public class TileEntitySalinationController extends TileEntitySalinationTank imp
public TileEntitySalinationController()
{
super("SalinationController");
inventory = new ItemStack[4];
}
@Override
@ -65,11 +70,14 @@ public class TileEntitySalinationController extends TileEntitySalinationTank imp
refresh();
}
setTemperature();
updateTemperature();
if(canOperate())
{
partialWater += baseTemperature * (height + 7)/8;
int brineNeeded = brineTank.getCapacity()-brineTank.getFluidAmount();
int waterStored = waterTank.getFluidAmount();
double waterUse = Math.min(brineTank.getFluidAmount(), getTemperature()*100);
if(partialWater >= 1)
{
@ -111,11 +119,18 @@ public class TileEntitySalinationController extends TileEntitySalinationTank imp
{
if(!updatedThisTick)
{
clearStructure();
structured = buildStructure();
if(!structured)
{
clearStructure();
temperature = Math.min(getMaxTemperature(), getTemperature());
}
else {
if(waterTank.getFluid() != null)
{
waterTank.getFluid().amount = Math.min(waterTank.getFluid().amount, getMaxWater());
}
}
}
}
@ -123,34 +138,61 @@ public class TileEntitySalinationController extends TileEntitySalinationTank imp
public boolean canOperate()
{
if(!structured || height < 1 || waterTank.getFluid() == null || !waterTank.getFluid().containsFluid(FluidRegistry.getFluidStack("water", 100)))
if(!structured || height < 3 || height > 18 || waterTank.getFluid() == null)
{
return false;
}
boolean solarsActive = true;
for(TileEntityAdvancedSolarGenerator solarPanel : solars)
if(!waterTank.getFluid().containsFluid(FluidRegistry.getFluidStack("water", 1)) || brineTank.getCapacity()-brineTank.getFluidAmount() == 0)
{
if(solarPanel == null || solarPanel.isInvalid())
{
clearStructure();
return false;
}
solarsActive &= solarPanel.seesSun;
return false;
}
return solarsActive;
return true;
}
public void setTemperature()
public void updateTemperature()
{
if(!temperatureSet)
float max = getMaxTemperature();
float incr = (max/WARMUP)*getTempMultiplier();
if(getTempMultiplier() == 0)
{
baseTemperature = worldObj.getBiomeGenForCoordsBody(xCoord, zCoord).getFloatTemperature();
temperatureSet = true;
temperature = Math.max(0, getTemperature()-(incr*2));
}
else {
temperature = Math.min(max, getTemperature()+incr);
}
}
public float getTemperature()
{
return temperature;
}
public float getMaxTemperature()
{
return 1 + (height-3)*0.5F;
}
public float getTempMultiplier()
{
return worldObj.getBiomeGenForCoordsBody(xCoord, zCoord).getFloatTemperature()*(getActiveSolars()/MAX_SOLARS);
}
public int getActiveSolars()
{
int ret = 0;
for(TileEntityAdvancedSolarGenerator solar : solars)
{
if(solar.seesSun)
{
ret++;
}
}
return ret;
}
public boolean buildStructure()
@ -180,7 +222,7 @@ public class TileEntitySalinationController extends TileEntitySalinationTank imp
middle++;
}
if(middle != height-2)
if(height < 3 || height > 18 || middle != height-2)
{
height = 0;
return false;
@ -255,6 +297,11 @@ public class TileEntitySalinationController extends TileEntitySalinationTank imp
return true;
}
public int getMaxWater()
{
return height*4*TankUpdateProtocol.FLUID_PER_TANK;
}
public int getCorner(int x, int z)
{
if(x == 0 && z == 0)
@ -400,6 +447,21 @@ public class TileEntitySalinationController extends TileEntitySalinationTank imp
}
}
public int getScaledWaterLevel(int i)
{
return waterTank.getFluid() != null ? waterTank.getFluid().amount*i / 10000 : 0;
}
public int getScaledBrineLevel(int i)
{
return brineTank.getFluid() != null ? brineTank.getFluid().amount*i / 10000 : 0;
}
public int getScaledTempLevel(int i)
{
return (int)(getMaxTemperature() == 0 ? 0 : getTemperature()*i/getMaxTemperature());
}
@Override
public boolean onSneakRightClick(EntityPlayer player, int side)
{
@ -436,6 +498,7 @@ public class TileEntitySalinationController extends TileEntitySalinationTank imp
structured = dataStream.readBoolean();
controllerConflict = dataStream.readBoolean();
clientSolarAmount = dataStream.readInt();
height = dataStream.readInt();
MekanismUtils.updateBlock(worldObj, xCoord, yCoord, zCoord);
}
@ -468,6 +531,7 @@ public class TileEntitySalinationController extends TileEntitySalinationTank imp
data.add(structured);
data.add(controllerConflict);
data.add(getSolarAmount());
data.add(height);
return data;
}
@ -494,6 +558,9 @@ public class TileEntitySalinationController extends TileEntitySalinationTank imp
waterTank.readFromNBT(nbtTags.getCompoundTag("waterTank"));
brineTank.readFromNBT(nbtTags.getCompoundTag("brineTank"));
partialWater = nbtTags.getDouble("partialWater");
partialBrine = nbtTags.getDouble("partialBrine");
}
@Override
@ -503,6 +570,9 @@ public class TileEntitySalinationController extends TileEntitySalinationTank imp
nbtTags.setCompoundTag("waterTank", waterTank.writeToNBT(new NBTTagCompound()));
nbtTags.setCompoundTag("brineTank", brineTank.writeToNBT(new NBTTagCompound()));
nbtTags.setDouble("partialWater", partialWater);
nbtTags.setDouble("partialBrine", partialBrine);
}
public void clearStructure()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB