mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
watz fixes, most remaining functionality, NBT and IO
This commit is contained in:
parent
8f20e77338
commit
ba02c7fa9e
@ -1,6 +1,7 @@
|
||||
package com.hbm.blocks.machine;
|
||||
|
||||
import com.hbm.blocks.BlockDummyable;
|
||||
import com.hbm.handler.MultiblockHandlerXR;
|
||||
import com.hbm.tileentity.TileEntityProxyCombo;
|
||||
import com.hbm.tileentity.machine.TileEntityWatz;
|
||||
|
||||
@ -31,7 +32,7 @@ public class Watz extends BlockDummyable {
|
||||
|
||||
@Override
|
||||
public int[] getDimensions() {
|
||||
return new int[] {2, 0, 3, 3, 3, 3};
|
||||
return new int[] {2, 0, 3, 3, 1, 1};
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -41,13 +42,22 @@ public class Watz extends BlockDummyable {
|
||||
|
||||
@Override
|
||||
protected boolean checkRequirement(World world, int x, int y, int z, ForgeDirection dir, int o) {
|
||||
return super.checkRequirement(world, x, y, z, dir, o); //TODO
|
||||
return super.checkRequirement(world, x, y, z, dir, o) &&
|
||||
MultiblockHandlerXR.checkSpace(world, x + dir.offsetX * o, y + dir.offsetY * o, z + dir.offsetZ * o, new int[]{2, 0, 2, 2, 2, -2}, x, y, z, dir) &&
|
||||
MultiblockHandlerXR.checkSpace(world, x + dir.offsetX * o, y + dir.offsetY * o, z + dir.offsetZ * o, new int[]{2, 0, 2, 2, -2, 2}, x, y, z, dir) &&
|
||||
MultiblockHandlerXR.checkSpace(world, x + dir.offsetX * o, y + dir.offsetY * o, z + dir.offsetZ * o, new int[]{2, 0, 1, 1, 3, -3}, x, y, z, dir) &&
|
||||
MultiblockHandlerXR.checkSpace(world, x + dir.offsetX * o, y + dir.offsetY * o, z + dir.offsetZ * o, new int[]{2, 0, 1, 1, -3, 3}, x, y, z, dir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillSpace(World world, int x, int y, int z, ForgeDirection dir, int o) {
|
||||
super.fillSpace(world, x, y, z, dir, o);
|
||||
|
||||
MultiblockHandlerXR.fillSpace(world, x + dir.offsetX * o, y + dir.offsetY * o, z + dir.offsetZ * o, new int[]{2, 0, 2, 2, 2, -2}, this, dir);
|
||||
MultiblockHandlerXR.fillSpace(world, x + dir.offsetX * o, y + dir.offsetY * o, z + dir.offsetZ * o, new int[]{2, 0, 2, 2, -2, 2}, this, dir);
|
||||
MultiblockHandlerXR.fillSpace(world, x + dir.offsetX * o, y + dir.offsetY * o, z + dir.offsetZ * o, new int[]{2, 0, 1, 1, 3, -3}, this, dir);
|
||||
MultiblockHandlerXR.fillSpace(world, x + dir.offsetX * o, y + dir.offsetY * o, z + dir.offsetZ * o, new int[]{2, 0, 1, 1, -3, 3}, this, dir);
|
||||
|
||||
x += dir.offsetX * o;
|
||||
z += dir.offsetZ * o;
|
||||
|
||||
|
||||
@ -4,11 +4,18 @@ import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.hbm.inventory.container.ContainerWatz;
|
||||
import com.hbm.lib.RefStrings;
|
||||
import com.hbm.packet.NBTControlPacket;
|
||||
import com.hbm.packet.PacketDispatcher;
|
||||
import com.hbm.render.util.GaugeUtil;
|
||||
import com.hbm.render.util.GaugeUtil.Gauge;
|
||||
import com.hbm.tileentity.machine.TileEntityWatz;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class GUIWatz extends GuiInfoContainer {
|
||||
@ -40,16 +47,31 @@ public class GUIWatz extends GuiInfoContainer {
|
||||
protected void drawGuiContainerForegroundLayer(int i, int j) {
|
||||
this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 93, 4210752);
|
||||
|
||||
String flux = "" + ((int)(watz.fluxDisplay * 10)) / 10.0D;
|
||||
this.fontRendererObj.drawString(flux, 159 - this.fontRendererObj.getStringWidth(flux), 105, 0x00ff00);
|
||||
double scale = 1.25;
|
||||
String flux = String.format("%,.1f", watz.fluxDisplay);
|
||||
GL11.glScaled(1 / scale, 1 / scale, 1);
|
||||
this.fontRendererObj.drawString(flux, (int) (161 * scale - this.fontRendererObj.getStringWidth(flux)), (int)(107 * scale), 0x00ff00);
|
||||
GL11.glScaled(scale, scale, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int x, int y, int i) {
|
||||
super.mouseClicked(x, y, i);
|
||||
|
||||
if(guiLeft + 142 <= x && guiLeft + 142 + 18 > x && guiTop + 70 < y && guiTop + 70 + 18 >= y) {
|
||||
NBTTagCompound control = new NBTTagCompound();
|
||||
control.setBoolean("lock", true);
|
||||
PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(control, watz.xCoord, watz.yCoord, watz.zCoord));
|
||||
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1F));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float interp, int x, int y) {
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
//float col = (float) (Math.sin(System.currentTimeMillis() / 500D) * 0.5 + 0.5);
|
||||
//GL11.glColor4f(1.0F, col, col, 1.0F);
|
||||
float col = MathHelper.clamp_float(1 - (float) Math.log(watz.heat / 100_000D + 1) * 0.4F, 0F, 1F);
|
||||
GL11.glColor4f(1.0F, col, col, 1.0F);
|
||||
drawTexturedModalRect(guiLeft, guiTop, 0, 0, 131, 122);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
@ -59,6 +81,11 @@ public class GUIWatz extends GuiInfoContainer {
|
||||
drawTexturedModalRect(guiLeft + 105, guiTop + 96, 185, 26, 30, 26);
|
||||
drawTexturedModalRect(guiLeft + 9, guiTop + 96, 184, 0, 26, 26);
|
||||
|
||||
if(watz.isOn) drawTexturedModalRect(guiLeft + 147, guiTop + 8, 176, 0, 8, 8);
|
||||
if(watz.isLocked) drawTexturedModalRect(guiLeft + 142, guiTop + 70, 210, 0, 18, 18);
|
||||
|
||||
GaugeUtil.renderGauge(Gauge.ROUND_SMALL, guiLeft + 13, guiTop + 100, this.zLevel, 1 - col);
|
||||
|
||||
watz.tanks[0].renderTank(guiLeft + 143, guiTop + 69, this.zLevel, 4, 43);
|
||||
watz.tanks[1].renderTank(guiLeft + 149, guiTop + 69, this.zLevel, 4, 43);
|
||||
watz.tanks[2].renderTank(guiLeft + 155, guiTop + 69, this.zLevel, 4, 43);
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.hbm.items.machine;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.hbm.items.ItemEnumMulti;
|
||||
import com.hbm.items.ModItems;
|
||||
@ -123,6 +124,8 @@ public class ItemWatzPellet extends ItemEnumMulti {
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool) {
|
||||
EnumWatzType num = EnumUtil.grabEnumSafely(EnumWatzType.class, stack.getItemDamage());
|
||||
|
||||
list.add(EnumChatFormatting.GREEN + "Depletion: " + String.format(Locale.US, "%.1f", getDurabilityForDisplay(stack) * 100D) + "%");
|
||||
|
||||
String color = EnumChatFormatting.GOLD + "";
|
||||
String reset = EnumChatFormatting.RESET + "";
|
||||
|
||||
|
||||
@ -29,6 +29,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.World;
|
||||
@ -41,6 +42,7 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand
|
||||
public double fluxLastBase; //flux created by the previous passive emission, only used for display
|
||||
public double fluxLastReaction; //flux created by the previous reaction, used for the next reaction
|
||||
public double fluxDisplay;
|
||||
public boolean isOn;
|
||||
|
||||
/* lock types for item IO */
|
||||
public boolean isLocked = false;
|
||||
@ -106,22 +108,23 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand
|
||||
segment.updateReaction(above, sharedTanks, turnedOn);
|
||||
}
|
||||
|
||||
/* send sync packets (order doesn't matter) */
|
||||
for(TileEntityWatz segment : segments) {
|
||||
segment.isOn = turnedOn;
|
||||
segment.sendPacket(sharedTanks);
|
||||
segment.heat *= 0.99; //cool 1% per tick
|
||||
}
|
||||
|
||||
/* re-distribute fluid from shared tanks back into actual tanks, bottom to top */
|
||||
for(int i = segments.size() - 1; i >= 0; i--) {
|
||||
TileEntityWatz segment = segments.get(i);
|
||||
for(int j = 0; j < 3; j++) {
|
||||
int min = Math.min(segment.tanks[j].getMaxFill(), sharedTanks[j].getFill());
|
||||
segment.tanks[j].setFill(min);
|
||||
sharedTanks[j].setFill(sharedTanks[j].getFill() - min);
|
||||
segment.tanks[j].setFill(min);
|
||||
}
|
||||
}
|
||||
|
||||
/* send sync packets (order doesn't matter) */
|
||||
for(TileEntityWatz segment : segments) {
|
||||
segment.sendPacket(sharedTanks);
|
||||
segment.heat *= 0.99; //cool 1% per tick
|
||||
}
|
||||
|
||||
segments.get(segments.size() - 1).sendOutBottom();
|
||||
}
|
||||
}
|
||||
@ -150,8 +153,8 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand
|
||||
|
||||
int cycles = Math.min(heatCycles, Math.min(hotCycles, coolCycles));
|
||||
this.heat -= cycles * step.heatReq;
|
||||
tanks[0].setFill(tanks[0].getFill() - coolCycles * step.amountReq);
|
||||
tanks[1].setFill(tanks[1].getFill() + hotCycles * step.amountProduced);
|
||||
tanks[0].setFill(tanks[0].getFill() - cycles * step.amountReq);
|
||||
tanks[1].setFill(tanks[1].getFill() + cycles * step.amountProduced);
|
||||
}
|
||||
|
||||
/** enforces strict top to bottom update order (instead of semi-random based on placement) */
|
||||
@ -244,12 +247,25 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand
|
||||
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setInteger("heat", this.heat);
|
||||
data.setBoolean("isOn", isOn);
|
||||
data.setBoolean("lock", isLocked);
|
||||
data.setDouble("flux", this.fluxLastReaction + this.fluxLastBase);
|
||||
for(int i = 0; i < tanks.length; i++) {
|
||||
tanks[i].writeToNBT(data, "t" + i);
|
||||
}
|
||||
this.networkPack(data, 25);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void networkUnpack(NBTTagCompound nbt) {
|
||||
this.heat = nbt.getInteger("heat");
|
||||
this.isOn = nbt.getBoolean("isOn");
|
||||
this.isLocked = nbt.getBoolean("lock");
|
||||
this.fluxDisplay = nbt.getDouble("flux");
|
||||
for(int i = 0; i < tanks.length; i++) {
|
||||
tanks[i].readFromNBT(nbt, "t" + i);
|
||||
}
|
||||
}
|
||||
|
||||
/** Prevent manual updates when another segment is above this one */
|
||||
public boolean updateLock() {
|
||||
@ -281,14 +297,49 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand
|
||||
new DirPos(xCoord, yCoord - 1, zCoord - 2, ForgeDirection.DOWN)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void networkUnpack(NBTTagCompound nbt) {
|
||||
this.heat = nbt.getInteger("heat");
|
||||
this.fluxDisplay = nbt.getDouble("flux");
|
||||
for(int i = 0; i < tanks.length; i++) {
|
||||
tanks[i].readFromNBT(nbt, "t" + i);
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
NBTTagList list = nbt.getTagList("locks", 10);
|
||||
|
||||
for(int i = 0; i < list.tagCount(); i++) {
|
||||
NBTTagCompound nbt1 = list.getCompoundTagAt(i);
|
||||
byte b0 = nbt1.getByte("slot");
|
||||
if(b0 >= 0 && b0 < slots.length) {
|
||||
locks[b0] = ItemStack.loadItemStackFromNBT(nbt1);
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < tanks.length; i++) tanks[i].readFromNBT(nbt, "t" + i);
|
||||
this.fluxLastBase = nbt.getDouble("lastFluxB");
|
||||
this.fluxLastReaction = nbt.getDouble("lastFluxR");
|
||||
|
||||
this.isLocked = nbt.getBoolean("isLocked");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
NBTTagList list = new NBTTagList();
|
||||
|
||||
for(int i = 0; i < locks.length; i++) {
|
||||
if(locks[i] != null) {
|
||||
NBTTagCompound nbt1 = new NBTTagCompound();
|
||||
nbt1.setByte("slot", (byte) i);
|
||||
locks[i].writeToNBT(nbt1);
|
||||
list.appendTag(nbt1);
|
||||
}
|
||||
}
|
||||
nbt.setTag("locks", list);
|
||||
|
||||
for(int i = 0; i < tanks.length; i++) tanks[i].writeToNBT(nbt, "t" + i);
|
||||
nbt.setDouble("lastFluxB", fluxLastBase);
|
||||
nbt.setDouble("lastFluxR", fluxLastReaction);
|
||||
|
||||
nbt.setBoolean("isLocked", isLocked);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.5 KiB |
Loading…
x
Reference in New Issue
Block a user