diff --git a/client/src/main/java/client/Client.java b/client/src/main/java/client/Client.java index 1c8c5eba..76202bd5 100755 --- a/client/src/main/java/client/Client.java +++ b/client/src/main/java/client/Client.java @@ -457,8 +457,6 @@ public class Client implements IThreadListener { public int fbY; public int mouseX; public int mouseY; - public int total; - public int progress = -1; private long lastTicked = 0L; private long debugUpdateTime = System.currentTimeMillis(); @@ -520,7 +518,6 @@ public class Client implements IThreadListener { public BlockPos pointedLiquid; public DisplayMode vidMode; public String dimensionName; - public String message; private ChunkClient emptyChunk; private ChunkClient outsideChunk; @@ -665,7 +662,7 @@ public class Client implements IThreadListener { } public void displayConnecting(ServerInfo server) { - this.show(GuiLoading.makeWaitTask("Verbinde zu " + (server.getAddress() == null ? "localhost" : server.getAddress()) + ":" + server.getPort() + " ...")); + this.show(new GuiLoading("Verbinde zu " + (server.getAddress() == null ? "localhost" : server.getAddress()) + ":" + server.getPort() + " ...")); } public void connect(final ServerInfo server) { diff --git a/client/src/main/java/client/gui/GuiConsole.java b/client/src/main/java/client/gui/GuiConsole.java index 5d46f2e1..09974757 100644 --- a/client/src/main/java/client/gui/GuiConsole.java +++ b/client/src/main/java/client/gui/GuiConsole.java @@ -97,7 +97,7 @@ public class GuiConsole extends Gui implements FieldCallback { } this.logBox = this.add(new ConsoleArea(0, this.full ? Element.BASE_HEIGHT : 0, width, height - Element.BASE_HEIGHT * (this.full ? 2 : 1), this.gm.getBuffer(), this.gm.world != null && !this.gm.charEditor)); if(this.full) - this.add(new Fill(640, 0, width - 640, 0)); + this.add(new Fill(640, 0, width - 640, 0, "")); this.inputField = this.add(new Field(0, height - Element.BASE_HEIGHT, width, 0, IPlayer.MAX_CMD_LENGTH, this, "")); this.inputField.setSelected(); this.sentHistoryCursor = this.sentMessages.size(); diff --git a/client/src/main/java/client/gui/GuiLoading.java b/client/src/main/java/client/gui/GuiLoading.java index 26f5b8a6..0fa70fe7 100644 --- a/client/src/main/java/client/gui/GuiLoading.java +++ b/client/src/main/java/client/gui/GuiLoading.java @@ -1,118 +1,19 @@ package client.gui; -import client.Client; -import client.gui.element.Bar; import client.gui.element.Label; public class GuiLoading extends Gui { - public static interface Callback { - void poll(Client gm, GuiLoading gui); - } - private final String message; - private final Callback callback; - private Label headerLabel; - private Label taskLabel; - private Bar progressBar1; - private Bar progressBar2; - - public static GuiLoading makeServerTask(String message) { - return new GuiLoading(message, new Callback() { - public void poll(Client gm, GuiLoading gui) { - int progress = gm.progress; - if(progress < 0) { - gui.resetBar(); - } - else { - gui.setBar(null, "Chunks", Math.max(1, gm.total)); - gui.setProgress(progress); - } - gui.setTask(gm.message); - } - }); - } - - public static GuiLoading makeWaitTask(String message) { - return new GuiLoading(message, new Callback() { - public void poll(Client gm, GuiLoading gui) { - } - }); - } - - public GuiLoading(String message, Callback callback) { + public GuiLoading(String message) { this.message = message; - this.callback = callback; } - + public void init(int width, int height) { - this.taskLabel = this.add(new Label(0, 40, 500, 0, "")); - this.progressBar1 = this.add(new Bar(0, 80, 500, 0)); - this.progressBar2 = this.add(new Bar(0, 120, 500, 0)); - this.shift(); - this.headerLabel = this.add(new Label(0, 40, width, 0, this.message)); - this.progressBar1.visible = false; - this.progressBar2.visible = false; + this.add(new Label(0, 40, width, 0, this.message)); } - + public String getTitle() { return this.message; } - - public void setTask(String task) { - this.taskLabel.setText(task == null ? "" : task); - } - - public void setBar(String desc) { - this.progressBar1.visible = true; - this.progressBar1.setDescription(desc); - } - - public void setBar(String desc, String unit, int total) { - this.progressBar1.visible = true; - this.progressBar1.setDescription(desc, unit, total); - } - - public void setBar(String desc, int total) { - this.progressBar1.visible = true; - this.progressBar1.setDescription(desc, total); - } - - public void setProgress(float progress) { - this.progressBar1.setProgress(progress); - } - - public void resetBar() { - this.progressBar1.resetProgress(); - this.progressBar1.visible = false; - } - - public void setSub(String desc) { - this.progressBar2.visible = true; - this.progressBar2.setDescription(desc); - } - - public void setSub(String desc, String unit, int total) { - this.progressBar2.visible = true; - this.progressBar2.setDescription(desc, unit, total); - } - - public void setSub(String desc, int total) { - this.progressBar2.visible = true; - this.progressBar2.setDescription(desc, total); - } - - public void setSubProgress(float progress) { - this.progressBar2.setProgress(progress); - } - - public void resetSub() { - this.progressBar2.resetProgress(); - this.progressBar2.visible = false; - } - - public void updateScreen() { - if(this.callback != null) - this.callback.poll(this.gm, this); - } } diff --git a/client/src/main/java/client/gui/character/GuiChar.java b/client/src/main/java/client/gui/character/GuiChar.java index 888bbac0..af880a77 100755 --- a/client/src/main/java/client/gui/character/GuiChar.java +++ b/client/src/main/java/client/gui/character/GuiChar.java @@ -390,7 +390,7 @@ public class GuiChar extends GuiList this.add(new ActButton(width - 195, height - 30, 193, 0, new ButtonCallback() { public void use(ActButton elem, PressType action) { if(GuiChar.this.gm.player != null) { - GuiChar.this.gm.show(GuiLoading.makeWaitTask("Lade Welt ...")); + GuiChar.this.gm.show(new GuiLoading("Lade Welt ...")); Dimension dim = GuiChar.this.dimensions.get(GuiChar.this.dimension); GuiChar.this.gm.player.client.addToSendQueue(new CPacketMessage(CPacketMessage.Type.INFO, descField.getText())); GuiChar.this.gm.player.client.addToSendQueue(new CPacketAction(CPacketAction.Action.CLOSE_EDITOR, DimensionMapping.getId(dim))); diff --git a/client/src/main/java/client/gui/container/GuiBrewing.java b/client/src/main/java/client/gui/container/GuiBrewing.java index e490576b..c521a204 100755 --- a/client/src/main/java/client/gui/container/GuiBrewing.java +++ b/client/src/main/java/client/gui/container/GuiBrewing.java @@ -26,7 +26,7 @@ public class GuiBrewing extends GuiContainer { } public void addElements() { - this.label(Blocks.brewing_stand.getDisplay(), 8, 6); - this.label("Inventar", 8, this.ySize - 96 + 2); + this.label(Blocks.brewing_stand.getDisplay(), 8, 16); + this.label("Inventar", 8, this.ySize - 96 + 12); } } diff --git a/client/src/main/java/client/gui/container/GuiChest.java b/client/src/main/java/client/gui/container/GuiChest.java index a033951c..27b6aec2 100755 --- a/client/src/main/java/client/gui/container/GuiChest.java +++ b/client/src/main/java/client/gui/container/GuiChest.java @@ -18,7 +18,7 @@ public class GuiChest extends GuiContainer { } public void addElements() { - this.label(this.block.getDisplay(), 8, 6); - this.label("Inventar", 8, this.ySize - 96 + 2); + this.label(this.block.getDisplay(), 8, 16); + this.label("Inventar", 8, this.ySize - 96 + 12); } } diff --git a/client/src/main/java/client/gui/container/GuiContainer.java b/client/src/main/java/client/gui/container/GuiContainer.java index 139dee62..07052148 100755 --- a/client/src/main/java/client/gui/container/GuiContainer.java +++ b/client/src/main/java/client/gui/container/GuiContainer.java @@ -14,10 +14,11 @@ import client.Client; import client.gui.Font; import client.gui.Gui; import client.gui.element.ActButton; +import client.gui.element.Bar; import client.gui.element.ButtonCallback; import client.gui.element.Field; import client.gui.element.FontLabel; -import client.gui.element.FontMultiLabel; +import client.gui.element.DisplayLabel; import client.gui.element.InventoryButton; import client.gui.element.Label; import client.gui.element.MultiLabel; @@ -199,7 +200,19 @@ public abstract class GuiContainer extends Gui public Label label(String text, int x, int y) { x = x * this.container_scale + this.container_x; y = y * this.container_scale + this.container_y; - return this.add(new FontLabel(x, y + 10 * this.container_scale, 300, this.container_scale > 1 ? Font.MEDIUM : Font.SMALL, text, true)); + return this.add(new FontLabel(x, y, 300, this.container_scale > 1 ? Font.LARGE : Font.SMALL, text, true)); + } + + public DisplayLabel display(String text, int x, int y, int w, int lines) { + x = x * this.container_scale + this.container_x; + y = y * this.container_scale + this.container_y; + return this.add(new DisplayLabel(x, y, w * this.container_scale, lines, this.container_scale > 1 ? Font.LARGE : Font.TINY, text)); + } + + public Bar bar(int x, int y, int w, int h) { + x = x * this.container_scale + this.container_x; + y = y * this.container_scale + this.container_y; + return this.add(new Bar(x, y, w * this.container_scale, h * this.container_scale, this.container_scale > 1 ? Font.LARGE : Font.TINY)); } public void rect(int x, int y, int width, int height, int color) { @@ -286,7 +299,7 @@ public abstract class GuiContainer extends Gui } if(this.gm.itemCheat) { this.cheatLabel = this.add(new FontLabel(this.cheatX, this.cheatY, this.cheatWidth * 18, Font.SMALL, "", true)); - this.cheatDesc = this.add(new FontMultiLabel(this.cheatX, this.cheatY + this.cheatHeight * 18 + 20 * ((CheatTab.values().length + (this.cheatWidth - 1)) / this.cheatWidth) + 4 + 18, this.cheatWidth * 18, 60, Font.SMALL, "Vorsicht: Schummeln\nwird mit Keule bestraft!!\n(Halte Strg beim Klick\nfür vollen Stapel)")); + this.cheatDesc = this.add(new DisplayLabel(this.cheatX, this.cheatY + this.cheatHeight * 18 + 20 * ((CheatTab.values().length + (this.cheatWidth - 1)) / this.cheatWidth) + 4 + 18, this.cheatWidth * 18, 4, Font.SMALL, "Vorsicht: Schummeln\nwird mit Keule bestraft!!\n(Halte Strg beim Klick\nfür vollen Stapel)")); this.cheatSearch = this.add(new Field(this.cheatX, this.cheatY + this.cheatHeight * 18 + 20 * ((CheatTab.values().length + (this.cheatWidth - 1)) / this.cheatWidth) + 4, this.cheatWidth * 18, 0, 128, null, "")); this.cheatLast = ""; for(CheatTab tab : CheatTab.values()) { diff --git a/client/src/main/java/client/gui/container/GuiCrafting.java b/client/src/main/java/client/gui/container/GuiCrafting.java index 578eaf00..294f0ea6 100755 --- a/client/src/main/java/client/gui/container/GuiCrafting.java +++ b/client/src/main/java/client/gui/container/GuiCrafting.java @@ -16,7 +16,7 @@ public class GuiCrafting extends GuiContainer { } public void addElements() { - this.label("Handwerk (" + this.type.getDisplay() + ")", 26, 6); - this.label("Inventar", 8, this.ySize - 96 + 2); + this.label(this.type.getDisplay(), 8, 16); + this.label("Inventar", 8, this.ySize - 96 + 12); } } diff --git a/client/src/main/java/client/gui/container/GuiDevice.java b/client/src/main/java/client/gui/container/GuiDevice.java index 59dbe0bf..9cd98771 100755 --- a/client/src/main/java/client/gui/container/GuiDevice.java +++ b/client/src/main/java/client/gui/container/GuiDevice.java @@ -1,10 +1,13 @@ package client.gui.container; +import client.gui.element.Bar; +import client.gui.element.DisplayLabel; import client.gui.element.Label; import common.inventory.ContainerTile; import common.inventory.IInventory; import common.entity.npc.EntityNPC; import common.tileentity.Device; +import common.tileentity.Device.Status; public class GuiDevice extends GuiContainer { private final IInventory playerInv; @@ -12,28 +15,47 @@ public class GuiDevice extends GuiContainer { private final Device tile; private Label header; - private Label temp; - private Label desc; + private DisplayLabel desc; + private Bar progress; + private Bar temperature; + private Bar[] resources; public GuiDevice(EntityNPC player, IInventory inv, Device tile) { super(new ContainerTile(player, tile, inv)); this.playerInv = player; this.tileInv = tile; - this.ySize = 153; + this.ySize = 194; this.tile = tile; } public void updateScreen() { super.updateScreen(); - this.header.setText(this.tile.getStatus().color + this.tile.getBlockType().getDisplay() + " - " + this.tile.getStatus().name); - this.temp.setText(String.format("Temperatur: %d °", this.tile.getTemperature())); + this.header.setText(this.tile.getStatus().color + this.tile.getBlockType().getDisplay()); this.desc.setText(this.tile.formatDisplay((ContainerTile)this.inventorySlots)); + if(this.progress != null) { + this.progress.setText(this.tile.getTotal() <= 0 || this.tile.getProgress() < 0 ? "" : String.format("%d/%d (%.1f %%)", + this.tile.getProgress(), this.tile.getTotal(), ((float)this.tile.getProgress() / (float)this.tile.getTotal()) * 100.0f)); + this.progress.setProgress(this.tile.getTotal(), this.tile.getProgress()); + } + if(this.temperature != null) { + this.temperature.setText(String.format("t: %d °C" + (this.tile.getMaxTemp() == Integer.MAX_VALUE ? "" : " (max. %d °C)"), this.tile.getTemperature(), this.tile.getMaxTemp())); + this.temperature.setProgress(this.tile.getMaxTemp() == Integer.MAX_VALUE ? (this.tile.getStatus() == Status.OFF || this.tile.getStatus() == Status.BROKEN ? 0 : this.tile.getTemperature()) : this.tile.getMaxTemp(), this.tile.getTemperature()); + } + for(int z = 0; z < this.resources.length; z++) { + this.resources[z].setText(this.tile.getResource(z).format()); + this.resources[z].setProgress(this.tile.getResource(z).getCapacity(), this.tile.getResource(z).getValue()); + } } public void addElements() { - this.header = this.label("", 8, 6); - this.label("Inventar", 8, this.ySize - 96 + 2); - this.temp = this.label("", 8, 18); - this.desc = this.label("", 8, 28); + this.header = this.label("", 8, 16); + this.label("Inventar", 8, this.ySize - 96 + 12); + this.desc = this.display("", 8, 18, 160, 4); + this.progress = this.tile.hasProgress() ? this.bar(7, 70, 162, 9) : null; + this.temperature = this.tile.hasTemperature() ? this.bar(7, this.progress == null ? 70 : 60, 162, 9) : null; + this.resources = new Bar[this.tile.getNumResources()]; + for(int z = 0; z < this.resources.length; z++) { + this.resources[z] = this.bar(7, 80 - (this.resources.length + (this.progress == null ? 0 : 1) + (this.temperature == null ? 0 : 1)) * 10 + z * 10, 162, 9); + } } } diff --git a/client/src/main/java/client/gui/container/GuiDispenser.java b/client/src/main/java/client/gui/container/GuiDispenser.java index a63d4627..ba21562d 100755 --- a/client/src/main/java/client/gui/container/GuiDispenser.java +++ b/client/src/main/java/client/gui/container/GuiDispenser.java @@ -14,7 +14,7 @@ public class GuiDispenser extends GuiContainer { } public void addElements() { - this.label(this.block.getDisplay(), 8, 6); - this.label("Inventar", 8, this.ySize - 96 + 2); + this.label(this.block.getDisplay(), 8, 16); + this.label("Inventar", 8, this.ySize - 96 + 12); } } diff --git a/client/src/main/java/client/gui/container/GuiEnchant.java b/client/src/main/java/client/gui/container/GuiEnchant.java index 661bbab6..a8b520e3 100755 --- a/client/src/main/java/client/gui/container/GuiEnchant.java +++ b/client/src/main/java/client/gui/container/GuiEnchant.java @@ -59,13 +59,13 @@ public class GuiEnchant extends GuiContainer implements ButtonCallback { } public void addElements() { - this.label(Blocks.enchanting_table.getDisplay(), 12, 5); - this.label("Inventar", 8, this.ySize - 96 + 2); + this.label(Blocks.enchanting_table.getDisplay(), 8, 16); + this.label("Inventar", 8, this.ySize - 96 + 12); for(int l = 0; l < 3; ++l) { int i1 = 60; int j1 = i1 + 2; - this.labels[l] = this.label("", j1, 16 + 19 * l); - this.mana[l] = this.label("", j1, 16 + 19 * l + 7); + this.labels[l] = this.label("", j1, 26 + 19 * l); + this.mana[l] = this.label("", j1, 26 + 19 * l + 7); } } diff --git a/client/src/main/java/client/gui/container/GuiEntity.java b/client/src/main/java/client/gui/container/GuiEntity.java index c4a2adb7..438648a4 100755 --- a/client/src/main/java/client/gui/container/GuiEntity.java +++ b/client/src/main/java/client/gui/container/GuiEntity.java @@ -14,7 +14,7 @@ public class GuiEntity extends GuiContainer { } public void addElements() { - this.label(this.title, 8, 6); - this.label("Inventar", 8, this.ySize - 96 + 2); + this.label(this.title, 8, 16); + this.label("Inventar", 8, this.ySize - 96 + 12); } } diff --git a/client/src/main/java/client/gui/container/GuiFurnace.java b/client/src/main/java/client/gui/container/GuiFurnace.java index b201e02f..2b7e1289 100755 --- a/client/src/main/java/client/gui/container/GuiFurnace.java +++ b/client/src/main/java/client/gui/container/GuiFurnace.java @@ -32,8 +32,8 @@ public class GuiFurnace extends GuiContainer { } public void addElements() { - this.label(this.block.getDisplay(), 8, 6); - this.label("Inventar", 8, this.ySize - 96 + 2); + this.label(this.block.getDisplay(), 8, 16); + this.label("Inventar", 8, this.ySize - 96 + 12); } private int getCookProgressScaled(int pixels) { diff --git a/client/src/main/java/client/gui/container/GuiHopper.java b/client/src/main/java/client/gui/container/GuiHopper.java index 962cc448..b7fe8bbb 100755 --- a/client/src/main/java/client/gui/container/GuiHopper.java +++ b/client/src/main/java/client/gui/container/GuiHopper.java @@ -13,7 +13,7 @@ public class GuiHopper extends GuiContainer { } public void addElements() { - this.label(Blocks.hopper.getDisplay(), 8, 6); - this.label("Inventar", 8, this.ySize - 96 + 2); + this.label(Blocks.hopper.getDisplay(), 8, 16); + this.label("Inventar", 8, this.ySize - 96 + 12); } } diff --git a/client/src/main/java/client/gui/container/GuiInventory.java b/client/src/main/java/client/gui/container/GuiInventory.java index 801d6c13..a6e4b44f 100755 --- a/client/src/main/java/client/gui/container/GuiInventory.java +++ b/client/src/main/java/client/gui/container/GuiInventory.java @@ -8,6 +8,5 @@ public class GuiInventory extends GuiContainer { } public void addElements() { - this.label("Handwerk", 86, 16); } } diff --git a/client/src/main/java/client/gui/container/GuiMerchant.java b/client/src/main/java/client/gui/container/GuiMerchant.java index 847cc6be..e8d56627 100755 --- a/client/src/main/java/client/gui/container/GuiMerchant.java +++ b/client/src/main/java/client/gui/container/GuiMerchant.java @@ -40,8 +40,8 @@ public class GuiMerchant extends GuiContainer implements ButtonCallback { } public void addElements() { - this.label(this.title, 8, 6); - this.label("Inventar", 8, this.ySize - 96 + 2); + this.label(this.title, 8, 16); + this.label("Inventar", 8, this.ySize - 96 + 12); } public void drawOverlays() { diff --git a/client/src/main/java/client/gui/container/GuiRepair.java b/client/src/main/java/client/gui/container/GuiRepair.java index c7633b5c..77a3d406 100755 --- a/client/src/main/java/client/gui/container/GuiRepair.java +++ b/client/src/main/java/client/gui/container/GuiRepair.java @@ -30,7 +30,8 @@ public class GuiRepair extends GuiContainer { } public void addElements() { - this.label("Amboss", 60, 6); - this.info = this.label("", 60, 67); + this.label("Amboss", 8, 16); + this.info = this.label("", 60, 77); + this.label("Inventar", 8, this.ySize - 96 + 12); } } diff --git a/client/src/main/java/client/gui/element/Bar.java b/client/src/main/java/client/gui/element/Bar.java index 649fb21e..3d7f72ac 100644 --- a/client/src/main/java/client/gui/element/Bar.java +++ b/client/src/main/java/client/gui/element/Bar.java @@ -1,26 +1,28 @@ package client.gui.element; +import client.gui.Font; import client.renderer.Drawing; import common.util.ExtMath; import common.util.Util; public class Bar extends Fill { - private int color = 0x00ff00; - private int progress = 0; - private int total = 0; - private String desc = ""; - private String unit = ""; + private final Font font; - public Bar(int x, int y, int w, int h, boolean top, boolean left) { - super(x, y, w, h, "", top, left); + private int color = 0x00ff00; + private int amount = 0; + + public Bar(int x, int y, int w, int h, Font font, boolean top, boolean left) { + super(x, y, w, h, top, left); + this.font = font; + this.setText(""); } - public Bar(int x, int y, int w, int h, boolean left) { - super(x, y, w, h, "", left); + public Bar(int x, int y, int w, int h, Font font, boolean left) { + this(x, y, w, h, font, false, left); } - public Bar(int x, int y, int w, int h) { - super(x, y, w, h, ""); + public Bar(int x, int y, int w, int h, Font font) { + this(x, y, w, h, font, false, false); } protected void drawBackground() { @@ -28,16 +30,24 @@ public class Bar extends Fill { Drawing.drawGradientBorder(this.pos_x, this.pos_y, this.size_x, this.size_y, this.gm.style.fill_btm, this.gm.style.fill_top, 0xff000000, this.gm.style.brdr_top, this.gm.style.brdr_btm); else Drawing.drawGradientBorder(this.pos_x, this.pos_y, this.size_x, this.size_y, Util.mulColor(this.gm.style.fill_btm, 0.5f), Util.mulColor(this.gm.style.fill_top, 0.5f), 0xff000000, Util.mulColor(this.gm.style.brdr_top, 0.5f), Util.mulColor(this.gm.style.brdr_btm, 0.5f)); - if(this.progress > 0) { + if(this.amount > 0) { if(this.enabled) - Drawing.drawGradient(this.pos_x + 2, this.pos_y + 2, this.progress, this.size_y - 4, this.color | 0xff000000, Util.mixColor(this.color | 0xff000000, 0xff000000)); + Drawing.drawGradient(this.pos_x + 2, this.pos_y + 2, this.amount, this.size_y - 4, this.color | 0xff000000, Util.mixColor(this.color | 0xff000000, 0xff000000)); else - Drawing.drawGradient(this.pos_x + 2, this.pos_y + 2, this.progress, this.size_y - 4, Util.mulColor(this.color | 0xff000000, 0.5f), Util.mulColor(Util.mixColor(this.color | 0xff000000, 0xff000000), 0.5f)); + Drawing.drawGradient(this.pos_x + 2, this.pos_y + 2, this.amount, this.size_y - 4, Util.mulColor(this.color | 0xff000000, 0.5f), Util.mulColor(Util.mixColor(this.color | 0xff000000, 0xff000000), 0.5f)); } } protected void drawForeground(int x1, int y1, int x2, int y2) { + Font.set(this.font); Drawing.drawText(this.text, x1 + this.text_x, y1 + this.text_y, this.enabled ? this.gm.style.text_label : Util.mulColor(this.gm.style.text_label, 0.5f)); + Font.unset(); + } + + public void updateText() { + Font.set(this.font); + super.updateText(); + Font.unset(); } protected int getMarginX() { @@ -48,50 +58,12 @@ public class Bar extends Fill { return 0; } - public Bar setDescription(String desc, String unit, int total) { - this.desc = desc == null ? "" : (desc + ": "); - this.unit = unit == null ? "" : (" " + unit); - this.total = total; - return this; - } - - public Bar setDescription(String desc, int total) { - return this.setDescription(desc, null, total); - } - - public Bar setDescription(String desc) { - this.desc = desc == null ? "" : (desc + ": "); - this.unit = ""; - this.total = 0; - return this; - } - - public Bar resetProgress() { - this.setText(""); - this.progress = 0; - this.setDescription(null); - return this; - } - - public Bar setProgressFill(int progress) { - this.progress = ExtMath.clampi(progress, 0, this.size_x - 4); - return this; - } - - public Bar setProgressFill(float progress) { - return this.setProgressFill((int)(progress * (float)(this.size_x - 4))); - } - - public Bar setProgress(float progress) { - if(this.total == 0) - this.setText(String.format("%s%.1f %%", this.desc, progress * 100.0f)); - else - this.setText(String.format("%s%d/%d%s (%.1f %%)", this.desc, (int)progress, this.total, this.unit, (progress / (float)this.total) * 100.0f)); - return this.setProgressFill(this.total == 0 ? progress : (progress / (float)this.total)); - } - public Bar setColor(int color) { this.color = color; return this; } + + public void setProgress(int total, int progress) { + this.amount = progress < 0 || total <= 0 ? 0 : ExtMath.clampi((int)(((float)progress / (float)total) * (float)(this.size_x - 4)), 0, this.size_x - 4); + } } diff --git a/client/src/main/java/client/gui/element/DisplayLabel.java b/client/src/main/java/client/gui/element/DisplayLabel.java new file mode 100644 index 00000000..6304fbaf --- /dev/null +++ b/client/src/main/java/client/gui/element/DisplayLabel.java @@ -0,0 +1,41 @@ +package client.gui.element; + +import client.gui.Font; +import client.renderer.Drawing; +import common.util.Util; + +public class DisplayLabel extends MultiLabel { + private final Font font; + + public DisplayLabel(int x, int y, int w, int lines, Font font, String text) { + super(x, y, w, lines * font.getHeight() + 2, true); + this.font = font; + this.setText(text); + } + + protected void drawBackground() { + Drawing.drawRect(this.pos_x, this.pos_y, this.size_x, this.size_y, 0xff000000, 0xff2f2f2f, 0xff5f5f5f); + } + + protected void drawForeground(int x1, int y1, int x2, int y2) { + Font.set(this.font); + for(int z = 0; z < this.lines.length; z++) { + Drawing.drawText(z == this.lines.length - 1 && Util.ftime() % 1.0f < 0.5f ? this.lines[z] + "_" : this.lines[z], x1, y1 + z * Font.HEIGHT, 0xff00ff00); + } + Font.unset(); + } + + public void updateText() { + Font.set(this.font); + super.updateText(); + Font.unset(); + } + + protected int getMarginX() { + return 2; + } + + protected int getMarginY() { + return 1; + } +} diff --git a/client/src/main/java/client/gui/element/Fill.java b/client/src/main/java/client/gui/element/Fill.java index 7067dcf9..37fbf4a2 100644 --- a/client/src/main/java/client/gui/element/Fill.java +++ b/client/src/main/java/client/gui/element/Fill.java @@ -22,16 +22,10 @@ public class Fill extends Element { this(x, y, w, h, text, false, false); } - public Fill(int x, int y, int w, int h, boolean top, boolean left) { - this(x, y, w, h, "", top, left); - } - - public Fill(int x, int y, int w, int h, boolean left) { - this(x, y, w, h, "", false, left); - } - - public Fill(int x, int y, int w, int h) { - this(x, y, w, h, "", false, false); + protected Fill(int x, int y, int w, int h, boolean top, boolean left) { + super(x, y, w, h, null); + this.top = top; + this.left = left; } diff --git a/client/src/main/java/client/gui/element/FontLabel.java b/client/src/main/java/client/gui/element/FontLabel.java index 1ea49acd..56ad961f 100644 --- a/client/src/main/java/client/gui/element/FontLabel.java +++ b/client/src/main/java/client/gui/element/FontLabel.java @@ -6,13 +6,15 @@ public class FontLabel extends Label { private final Font font; public FontLabel(int x, int y, int w, int h, Font font, String text, boolean left) { - super(x, y, w, h <= 0 ? font.getHeight() : h, text, left); + super(x, y, w, h <= 0 ? font.getHeight() : h, false, left); this.font = font; + this.setText(text); } public FontLabel(int x, int y, int w, Font font, String text, boolean left) { - super(x, y - font.getHeight(), w, font.getHeight(), text, left); + super(x, y - font.getHeight(), w, font.getHeight(), false, left); this.font = font; + this.setText(text); } protected void drawForeground(int x1, int y1, int x2, int y2) { @@ -20,4 +22,10 @@ public class FontLabel extends Label { super.drawForeground(x1, y1, x2, y2); Font.unset(); } + + public void updateText() { + Font.set(this.font); + super.updateText(); + Font.unset(); + } } diff --git a/client/src/main/java/client/gui/element/FontMultiLabel.java b/client/src/main/java/client/gui/element/FontMultiLabel.java deleted file mode 100644 index c81d89bf..00000000 --- a/client/src/main/java/client/gui/element/FontMultiLabel.java +++ /dev/null @@ -1,18 +0,0 @@ -package client.gui.element; - -import client.gui.Font; - -public class FontMultiLabel extends MultiLabel { - private final Font font; - - public FontMultiLabel(int x, int y, int w, int h, Font font, String text) { - super(x, y, w, h, text); - this.font = font; - } - - protected void drawForeground(int x1, int y1, int x2, int y2) { - Font.set(this.font); - super.drawForeground(x1, y1, x2, y2); - Font.unset(); - } -} diff --git a/client/src/main/java/client/gui/element/Label.java b/client/src/main/java/client/gui/element/Label.java index b371741c..cdde59ab 100644 --- a/client/src/main/java/client/gui/element/Label.java +++ b/client/src/main/java/client/gui/element/Label.java @@ -29,6 +29,10 @@ public class Label extends Fill { public Label(int x, int y, int w, String text) { super(x, y - LABEL_HEIGHT, w, LABEL_HEIGHT, text); } + + protected Label(int x, int y, int w, int h, boolean top, boolean left) { + super(x, y, w, h <= 0 ? LABEL_HEIGHT : h, top, left); + } protected void drawBackground() { } diff --git a/client/src/main/java/client/gui/element/MultiLabel.java b/client/src/main/java/client/gui/element/MultiLabel.java index 69898278..44b87c85 100644 --- a/client/src/main/java/client/gui/element/MultiLabel.java +++ b/client/src/main/java/client/gui/element/MultiLabel.java @@ -5,7 +5,7 @@ import client.renderer.Drawing; import common.util.Util; public class MultiLabel extends Fill { - private String[] lines; + protected String[] lines; public MultiLabel(int x, int y, int w, int h, String text, boolean top) { super(x, y, w, h, text, top, true); @@ -15,6 +15,10 @@ public class MultiLabel extends Fill { super(x, y, w, h, text, false, true); } + protected MultiLabel(int x, int y, int w, int h, boolean top) { + super(x, y, w, h, top, true); + } + public void setText(String str) { super.setText(str); this.lines = str.split("\n", -1); diff --git a/client/src/main/java/client/network/ClientPlayer.java b/client/src/main/java/client/network/ClientPlayer.java index 47b8acc7..07aa6a33 100755 --- a/client/src/main/java/client/network/ClientPlayer.java +++ b/client/src/main/java/client/network/ClientPlayer.java @@ -5,7 +5,6 @@ import java.util.Map.Entry; import client.Client; import client.gui.Gui; import client.gui.GuiConsole; -import client.gui.GuiLoading; import client.gui.character.GuiChar; import client.gui.character.GuiCharacters; import client.gui.container.GuiBrewing; @@ -110,7 +109,6 @@ import common.packet.SPacketEntityVelocity; import common.packet.SPacketHeldItemChange; import common.packet.SPacketJoinGame; import common.packet.SPacketKeepAlive; -import common.packet.SPacketLoading; import common.packet.SPacketMapChunkBulk; import common.packet.SPacketMessage; import common.packet.SPacketMultiBlockChange; @@ -827,25 +825,6 @@ public class ClientPlayer implements IClientPlayer // } } - public void handleLoading(SPacketLoading packet) { - NetHandler.checkThread(packet, this, this.gm); - - if(packet.getMessage() == null) { - if(packet.getTask() != null) - this.gm.message = packet.getTask(); - if(packet.getTotal() >= 0) - this.gm.total = packet.getTotal(); - if(packet.getProgress() >= -1) - this.gm.progress = packet.getProgress(); - } - else { - this.gm.message = ""; - this.gm.total = 0; - this.gm.progress = -1; - this.gm.show(GuiLoading.makeServerTask(packet.getMessage())); - } - } - // public void handleMessage(SPacketMessage packetIn) // { // NetHandler.checkThread(packetIn, this, this.gameController); diff --git a/common/src/main/java/common/init/SmeltingRegistry.java b/common/src/main/java/common/init/SmeltingRegistry.java index 557ecfca..c83f6d44 100755 --- a/common/src/main/java/common/init/SmeltingRegistry.java +++ b/common/src/main/java/common/init/SmeltingRegistry.java @@ -12,52 +12,50 @@ import java.util.Set; public abstract class SmeltingRegistry { private static final Map smeltingList = Maps.newHashMap(); - private static final Map experienceList = Maps.newHashMap(); private static boolean compareItemStacks(ItemStack stack1, ItemStack stack2) { return stack2.getItem() == stack1.getItem(); } static void register() { - add(Items.sand, Items.glass, 0.1F); - add(Items.red_sand, Items.glass, 0.1F); - add(Items.porkchop, Items.cooked_porkchop, 0.35F); - add(Items.beef, Items.cooked_beef, 0.35F); - add(Items.chicken, Items.cooked_chicken, 0.35F); - add(Items.cobblestone, Items.stone, 0.1F); - add(Items.stonebrick, Items.cracked_stonebrick, 0.1F); - add(Items.clay_lump, Items.brick, 0.3F); - add(Items.clay, Items.hardened_clay, 0.35F); - add(Items.hellrock, Items.bloodbrick, 0.1F); + add(Items.sand, Items.glass); + add(Items.red_sand, Items.glass); + add(Items.porkchop, Items.cooked_porkchop); + add(Items.beef, Items.cooked_beef); + add(Items.chicken, Items.cooked_chicken); + add(Items.cobblestone, Items.stone); + add(Items.stonebrick, Items.cracked_stonebrick); + add(Items.clay_lump, Items.brick); + add(Items.clay, Items.hardened_clay); + add(Items.hellrock, Items.bloodbrick); for(ItemFishFood.FishType fish : ItemFishFood.FishType.values()) { - add(ItemRegistry.byName(fish.getName()), ItemRegistry.byName("cooked_" + fish.getName()), 0.35F); + add(ItemRegistry.byName(fish.getName()), ItemRegistry.byName("cooked_" + fish.getName())); } for(OreType ore : OreType.values()) { Item item = ItemRegistry.byName(ore.item); - add(ItemRegistry.byName(ore.name + "_ore"), item, ((float)ore.experience) / 3.0F); + add(ItemRegistry.byName(ore.name + "_ore"), item); } for(MetalType metal : MetalType.values()) { Item item = ItemRegistry.byName(metal.isPowder ? (metal.name + "_powder") : (metal.name + "_ingot")); - add(ItemRegistry.byName(metal.name + "_ore"), item, 0.7F); + add(ItemRegistry.byName(metal.name + "_ore"), item); } for(WoodType wood : WoodType.values()) { - add(ItemRegistry.byName(wood.getName() + "_log"), Items.charcoal, 0.15F); + add(ItemRegistry.byName(wood.getName() + "_log"), Items.charcoal); } for(MineralType mineral : MineralType.values()) { Item item = ItemRegistry.byName(mineral.name); - add(ItemRegistry.byName(mineral.name + "_ore"), item, ((float)mineral.experience) / 10.0F); + add(ItemRegistry.byName(mineral.name + "_ore"), item); } } - private static void add(Item input, Item output, float experience) { - add(new ItemStack(input), new ItemStack(output), experience); + private static void add(Item input, Item output) { + add(new ItemStack(input), new ItemStack(output)); } - private static void add(ItemStack input, ItemStack stack, float experience) { + private static void add(ItemStack input, ItemStack stack) { smeltingList.put(input, stack); - experienceList.put(stack, Float.valueOf(experience)); } public static ItemStack getResult(ItemStack stack) { @@ -70,16 +68,6 @@ public abstract class SmeltingRegistry { return null; } - public static float getExperience(ItemStack stack) { - for(Entry entry : experienceList.entrySet()) { - if(compareItemStacks(stack, (ItemStack)entry.getKey())) { - return ((Float)entry.getValue()).floatValue(); - } - } - - return 0.0F; - } - public static void getSmeltingList(Set set) { for(ItemStack itemstack : smeltingList.values()) { set.add(itemstack.getItem()); diff --git a/common/src/main/java/common/inventory/ContainerFurnace.java b/common/src/main/java/common/inventory/ContainerFurnace.java index 348eabc1..6513c25d 100755 --- a/common/src/main/java/common/inventory/ContainerFurnace.java +++ b/common/src/main/java/common/inventory/ContainerFurnace.java @@ -19,7 +19,7 @@ public class ContainerFurnace extends Container this.tileFurnace = furnaceInventory; this.addSlotToContainer(new Slot(furnaceInventory, 0, 56, 17)); this.addSlotToContainer(new SlotFurnaceFuel(furnaceInventory, 1, 56, 53)); - this.addSlotToContainer(new SlotFurnaceOutput(playerInventory, furnaceInventory, 2, 116, 35)); + this.addSlotToContainer(new SlotOutput(furnaceInventory, 2, 116, 35)); for (int i = 0; i < 3; ++i) { diff --git a/common/src/main/java/common/inventory/ContainerTile.java b/common/src/main/java/common/inventory/ContainerTile.java index 1106221f..8ded1013 100755 --- a/common/src/main/java/common/inventory/ContainerTile.java +++ b/common/src/main/java/common/inventory/ContainerTile.java @@ -11,6 +11,8 @@ public class ContainerTile extends Container private final IInventory tileInv; private final Device tile; private int temperature; + private int progress; + private int total; private Status status = Status.OFF; private final int[] resources; @@ -20,17 +22,27 @@ public class ContainerTile extends Container this.tile = tile; this.resources = new int[tile.getNumResources()]; tileInv.openInventory(player); - int i = 71; + int i = 112; - for (int j = 0; j < tileInv.getSizeInventory(); ++j) + int input = 0; + int output = 0; + for (int idx = 0; idx < tileInv.getSizeInventory(); ++idx) { - final int index = j; - this.addSlotToContainer(new Slot(tileInv, j, 8 + j * 18, 40) { + final int index = idx; + this.addSlotToContainer(new Slot(tileInv, idx, 8 + (this.tile.isInput(index) ? input : 8 - output) * 18, 81) { public boolean isItemValid(ItemStack stack) { return ContainerTile.this.tile.isItemValidForSlot(index, stack); } + + public boolean canCheatItem() { + return ContainerTile.this.tile.isInput(index); + } }); + if(this.tile.isInput(index)) + ++input; + else + ++output; } for (int l = 0; l < 3; ++l) @@ -101,7 +113,9 @@ public class ContainerTile extends Container { super.onCraftGuiOpened(listener); listener.sendProperty(this, this.resources.length, this.tile.getTemperature()); - listener.sendProperty(this, this.resources.length + 1, this.tile.getStatus().ordinal()); + listener.sendProperty(this, this.resources.length + 1, this.tile.getProgress()); + listener.sendProperty(this, this.resources.length + 2, this.tile.getTotal()); + listener.sendProperty(this, this.resources.length + 3, this.tile.getStatus().ordinal()); for(int z = 0; z < this.resources.length; z++) { listener.sendProperty(this, z, this.tile.getResource(z).getValue()); } @@ -112,6 +126,10 @@ public class ContainerTile extends Container if(id == this.resources.length) this.tile.setTemperature(data); else if(id == this.resources.length + 1) + this.tile.setProgress(data); + else if(id == this.resources.length + 2) + this.tile.setTotal(data); + else if(id == this.resources.length + 3) this.tile.setStatus(Status.values()[data % Status.values().length]); else this.tile.getResource(id).setValue(data); @@ -126,15 +144,21 @@ public class ContainerTile extends Container IPlayer listener = this.crafters.get(i); if(this.temperature != this.tile.getTemperature()) listener.sendProperty(this, this.resources.length, this.tile.getTemperature()); + if(this.progress != this.tile.getProgress()) + listener.sendProperty(this, this.resources.length + 1, this.tile.getProgress()); + if(this.total != this.tile.getTotal()) + listener.sendProperty(this, this.resources.length + 2, this.tile.getTotal()); if(this.status != this.tile.getStatus()) - listener.sendProperty(this, this.resources.length + 1, this.tile.getStatus().ordinal()); + listener.sendProperty(this, this.resources.length + 3, this.tile.getStatus().ordinal()); for(int z = 0; z < this.resources.length; z++) { if(this.resources[z] != this.tile.getResource(z).getValue()) listener.sendProperty(this, z, this.tile.getResource(z).getValue()); } } - + this.temperature = this.tile.getTemperature(); + this.progress = this.tile.getProgress(); + this.total = this.tile.getTotal(); this.status = this.tile.getStatus(); for(int z = 0; z < this.resources.length; z++) { this.resources[z] = this.tile.getResource(z).getValue(); diff --git a/common/src/main/java/common/inventory/SlotFurnaceFuel.java b/common/src/main/java/common/inventory/SlotFurnaceFuel.java index 23edd126..00aa8788 100755 --- a/common/src/main/java/common/inventory/SlotFurnaceFuel.java +++ b/common/src/main/java/common/inventory/SlotFurnaceFuel.java @@ -11,9 +11,6 @@ public class SlotFurnaceFuel extends Slot super(inventoryIn, slotIndex, xPosition, yPosition); } - /** - * Check if the stack is a valid item for this slot. Always true beside for the armor slots. - */ public boolean isItemValid(ItemStack stack) { return TileEntityFurnace.isItemFuel(stack) || isBucket(stack); diff --git a/common/src/main/java/common/inventory/SlotFurnaceOutput.java b/common/src/main/java/common/inventory/SlotFurnaceOutput.java deleted file mode 100755 index e9cd2686..00000000 --- a/common/src/main/java/common/inventory/SlotFurnaceOutput.java +++ /dev/null @@ -1,112 +0,0 @@ -package common.inventory; - -import common.entity.item.EntityXp; -import common.entity.npc.EntityNPC; -import common.init.SmeltingRegistry; -import common.item.ItemStack; -import common.util.ExtMath; -import common.vars.Vars; - -public class SlotFurnaceOutput extends Slot -{ - /** The player that is using the GUI where this slot resides. */ - private EntityNPC thePlayer; - private int smelted; - - public SlotFurnaceOutput(EntityNPC player, IInventory inventoryIn, int slotIndex, int xPosition, int yPosition) - { - super(inventoryIn, slotIndex, xPosition, yPosition); - this.thePlayer = player; - } - - /** - * Check if the stack is a valid item for this slot. Always true beside for the armor slots. - */ - public boolean isItemValid(ItemStack stack) - { - return false; - } - - /** - * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new - * stack. - */ - public ItemStack decrStackSize(int amount) - { - if (this.getHasStack()) - { - this.smelted += Math.min(amount, this.getStack().getSize()); - } - - return super.decrStackSize(amount); - } - - public void onPickupFromSlot(EntityNPC playerIn, ItemStack stack) - { - this.onCrafting(stack); - super.onPickupFromSlot(playerIn, stack); - } - - /** - * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an - * internal count then calls onCrafting(item). - */ - protected void onCrafting(ItemStack stack, int amount) - { - this.smelted += amount; - this.onCrafting(stack); - } - - /** - * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. - */ - protected void onCrafting(ItemStack stack) - { -// stack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.smelted); - - if (!this.thePlayer.worldObj.client && Vars.smeltingXP) - { - int xp = this.smelted; - float smeltXp = SmeltingRegistry.getExperience(stack); - - if (smeltXp == 0.0F) - { - xp = 0; - } - else if (smeltXp < 1.0F) - { - int mxp = ExtMath.floorf((float)xp * smeltXp); - - if (mxp < ExtMath.ceilf((float)xp * smeltXp) && Math.random() < (double)((float)xp * smeltXp - (float)mxp)) - { - ++mxp; - } - - xp = mxp; - } - - while (xp > 0) - { - int split = EntityXp.getXPSplit(xp); - xp -= split; - this.thePlayer.worldObj.spawnEntityInWorld(new EntityXp(this.thePlayer.worldObj, this.thePlayer.posX, this.thePlayer.posY + 0.5D, this.thePlayer.posZ + 0.5D, split)); - } - } - - this.smelted = 0; - -// if (stack.getItem() == Items.iron_ingot) -// { -// this.thePlayer.triggerAchievement(AchievementList.acquireIron); -// } -// -// if (stack.getItem() == Items.cooked_fish) -// { -// this.thePlayer.triggerAchievement(AchievementList.cookFish); -// } - } - - public boolean canCheatItem() { - return false; - } -} diff --git a/common/src/main/java/common/inventory/SlotOutput.java b/common/src/main/java/common/inventory/SlotOutput.java new file mode 100755 index 00000000..6c585436 --- /dev/null +++ b/common/src/main/java/common/inventory/SlotOutput.java @@ -0,0 +1,17 @@ +package common.inventory; + +import common.item.ItemStack; + +public class SlotOutput extends Slot { + public SlotOutput(IInventory inventoryIn, int slotIndex, int xPosition, int yPosition) { + super(inventoryIn, slotIndex, xPosition, yPosition); + } + + public boolean isItemValid(ItemStack stack) { + return false; + } + + public boolean canCheatItem() { + return false; + } +} diff --git a/common/src/main/java/common/network/IClientPlayer.java b/common/src/main/java/common/network/IClientPlayer.java index 55b0cd82..5934134c 100644 --- a/common/src/main/java/common/network/IClientPlayer.java +++ b/common/src/main/java/common/network/IClientPlayer.java @@ -46,7 +46,6 @@ import common.packet.SPacketEntityVelocity; import common.packet.SPacketHeldItemChange; import common.packet.SPacketJoinGame; import common.packet.SPacketKeepAlive; -import common.packet.SPacketLoading; import common.packet.SPacketMapChunkBulk; import common.packet.SPacketMessage; import common.packet.SPacketMultiBlockChange; @@ -97,7 +96,6 @@ public interface IClientPlayer extends NetHandler { void handleDisconnect(SPacketDisconnect packet); void handleCollectItem(SPacketCollectItem packet); void handleMessage(SPacketMessage packet); - void handleLoading(SPacketLoading packet); void handleAnimation(SPacketAnimation packet); void handleSpawnMob(SPacketSpawnMob packet); void handleTimeUpdate(SPacketTimeUpdate packet); diff --git a/common/src/main/java/common/network/PacketRegistry.java b/common/src/main/java/common/network/PacketRegistry.java index a7865673..ea42e88e 100755 --- a/common/src/main/java/common/network/PacketRegistry.java +++ b/common/src/main/java/common/network/PacketRegistry.java @@ -83,7 +83,6 @@ import common.packet.SPacketEntityVelocity; import common.packet.SPacketHeldItemChange; import common.packet.SPacketJoinGame; import common.packet.SPacketKeepAlive; -import common.packet.SPacketLoading; import common.packet.SPacketMapChunkBulk; import common.packet.SPacketMessage; import common.packet.SPacketMultiBlockChange; @@ -181,7 +180,6 @@ public enum PacketRegistry { this.server(SPacketDimensionName.class); this.server(SPacketCharacterList.class); this.server(SPacketServerTick.class); - this.server(SPacketLoading.class); this.server(SPacketDisplayForm.class); this.server(SPacketServerConfig.class); this.server(SPacketCelestials.class); diff --git a/common/src/main/java/common/packet/SPacketLoading.java b/common/src/main/java/common/packet/SPacketLoading.java deleted file mode 100644 index 2a090f94..00000000 --- a/common/src/main/java/common/packet/SPacketLoading.java +++ /dev/null @@ -1,70 +0,0 @@ -package common.packet; - -import java.io.IOException; - -import common.network.IClientPlayer; -import common.network.Packet; -import common.network.PacketBuffer; - -public class SPacketLoading implements Packet { - private String message; - private String task; - private int total = -1; - private int progress = -2; - - public SPacketLoading() { - } - - public SPacketLoading(String message) { - this.message = message; - } - - public SPacketLoading(String task, int total) { - this.task = task; - this.total = total; - } - - public SPacketLoading(int progress) { - this.progress = progress; - } - - public void readPacketData(PacketBuffer buf) throws IOException { - this.message = buf.readString(128); - this.message = this.message != null && this.message.isEmpty() ? null : this.message; - if(this.message == null) { - this.task = buf.readString(128); - this.task = this.task != null && this.task.isEmpty() ? null : this.task; - this.total = buf.readInt(); - this.progress = buf.readInt(); - } - } - - public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeString(this.message == null ? "" : this.message); - if(this.message == null) { - buf.writeString(this.task == null ? "" : this.task); - buf.writeInt(this.total); - buf.writeInt(this.progress); - } - } - - public void processPacket(IClientPlayer handler) { - handler.handleLoading(this); - } - - public String getMessage() { - return this.message; - } - - public String getTask() { - return this.task; - } - - public int getTotal() { - return this.total; - } - - public int getProgress() { - return this.progress; - } -} diff --git a/common/src/main/java/common/tileentity/Device.java b/common/src/main/java/common/tileentity/Device.java index fb1d9aaf..a998802f 100755 --- a/common/src/main/java/common/tileentity/Device.java +++ b/common/src/main/java/common/tileentity/Device.java @@ -15,7 +15,7 @@ import common.util.Color; public abstract class Device extends TileEntity implements IInventory, ITickable { public static enum Status { - OFF(Color.DARK_GRAY, "Inaktiv"), + OFF(Color.GRAY, "Inaktiv"), COOLING(Color.YELLOW, "Abkühlen ..."), RUNNING(Color.GREEN, "Aktiv"), OVERHEAT(Color.RED, "Überhitzt!"), @@ -33,11 +33,15 @@ public abstract class Device extends TileEntity implements IInventory, ITickable protected final ItemStack[] inventory; protected final MachineResource[] resources; protected final Random rand = new Random(); + protected final int inputs; protected int temperature; + protected int progress = -1; + protected int total; protected Status status = Status.OFF; - protected Device(int slots, MachineResource ... resources) { - this.inventory = new ItemStack[slots]; + protected Device(int inputs, int outputs, MachineResource ... resources) { + this.inventory = new ItemStack[inputs + outputs]; + this.inputs = inputs; this.resources = resources; } @@ -49,10 +53,14 @@ public abstract class Device extends TileEntity implements IInventory, ITickable return -1; } - protected int getMaxTemp() { + public int getMaxTemp() { return Integer.MAX_VALUE; } + public boolean hasTemperature() { + return false; + } + protected abstract boolean executeFunction(); public MachineResource getResource(int slot) { @@ -71,6 +79,26 @@ public abstract class Device extends TileEntity implements IInventory, ITickable this.temperature = temp; } + public int getProgress() { + return this.progress; + } + + public void setProgress(int progress) { + this.progress = progress; + } + + public int getTotal() { + return this.total; + } + + public void setTotal(int total) { + this.total = total; + } + + public boolean hasProgress() { + return false; + } + public Status getStatus() { return this.status; } @@ -101,7 +129,12 @@ public abstract class Device extends TileEntity implements IInventory, ITickable this.resources[i].fromTag(list.get(i)); } - this.temperature = tag.getInt("Temperature"); + if(this.hasTemperature()) + this.temperature = tag.getInt("Temperature"); + if(this.hasProgress()) { + this.progress = tag.getInt("Progress"); + this.total = tag.getInt("Total"); + } this.status = Status.values()[(int)tag.getByte("Status") % Status.values().length]; } @@ -127,7 +160,12 @@ public abstract class Device extends TileEntity implements IInventory, ITickable } tag.setList("Resources", list); - tag.setInt("Temperature", this.temperature); + if(this.hasTemperature()) + tag.setInt("Temperature", this.temperature); + if(this.hasProgress()) { + tag.setInt("Progress", this.progress); + tag.setInt("Total", this.total); + } tag.setByte("Status", (byte)this.status.ordinal()); } @@ -196,7 +234,7 @@ public abstract class Device extends TileEntity implements IInventory, ITickable } public boolean isItemValidForSlot(int index, ItemStack stack) { - return true; + return index < this.inputs; } public void detonate() { @@ -208,83 +246,75 @@ public abstract class Device extends TileEntity implements IInventory, ITickable if(this.worldObj != null && !this.worldObj.client && this.status != Status.BROKEN) { int envTemp = (int)this.worldObj.getTemperatureC(this.getPos()); if(this.executeFunction()) { - if(this.getTempIncrement() < 0) - this.temperature = envTemp; - else - this.temperature += this.getTempIncrement(); - this.status = this.temperature >= (this.getMaxTemp() * 9) / 10 ? Status.OVERHEAT : Status.RUNNING; - if(this.temperature > this.getMaxTemp()) { - this.status = Status.BROKEN; - this.markDirty(); - this.detonate(); - return; + if(this.hasTemperature()) { + if(this.getTempIncrement() < 0) + this.temperature = envTemp; + else + this.temperature += this.getTempIncrement(); + this.status = this.temperature >= (this.getMaxTemp() * 9) / 10 ? Status.OVERHEAT : Status.RUNNING; + if(this.temperature > this.getMaxTemp()) { + this.status = Status.BROKEN; + this.markDirty(); + this.detonate(); + return; + } + else { + this.markDirty(); + } } else { + this.status = Status.RUNNING; this.markDirty(); } } else { - int dec = this.getTempDecrement(); - if(dec != 0) { - int prev = this.temperature; - if(dec < 0) - this.temperature = envTemp; - else - this.temperature -= dec; - this.temperature = ExtMath.clampi(this.temperature, envTemp, Integer.MAX_VALUE); - if(prev != this.temperature) + if(this.hasTemperature()) { + int dec = this.getTempDecrement(); + if(dec != 0) { + int prev = this.temperature; + if(dec < 0) + this.temperature = envTemp; + else + this.temperature -= dec; + this.temperature = ExtMath.clampi(this.temperature, envTemp, Integer.MAX_VALUE); + if(prev != this.temperature) + this.markDirty(); + else + dec = 0; + } + Status prev = this.status; + this.status = this.temperature >= (this.getMaxTemp() * 9) / 10 ? Status.OVERHEAT : + (this.temperature == envTemp ? Status.OFF : Status.COOLING); + if(dec == 0 && prev != this.status) { this.markDirty(); - else - dec = 0; + } } - Status prev = this.status; - this.status = this.temperature >= (this.getMaxTemp() * 9) / 10 ? Status.OVERHEAT : - (this.temperature == envTemp ? Status.OFF : Status.COOLING); - if(dec == 0 && prev != this.status) { + else if(this.status != Status.OFF) { + this.status = Status.OFF; this.markDirty(); } } - if(this.temperature < envTemp) { + if(this.hasTemperature() && this.temperature < envTemp) { this.temperature = envTemp; this.markDirty(); } } } - public boolean isEmpty(int slot) { - if(slot == -1) { - for(ItemStack itemstack : this.inventory) { - if(itemstack != null) - return false; - } - return true; - } - else { - return this.inventory[slot] == null || this.inventory[slot].isEmpty(); - } + public boolean isInput(int slot) { + return slot < this.inputs; } - public boolean hasAmount(int slot, int amount) { - if(slot == -1) { - int n = 0; - for(ItemStack itemstack : this.inventory) { - if(itemstack != null && !itemstack.isEmpty()) - n += itemstack.getSize(); - } - return n >= amount; - } - else { - return this.inventory[slot] != null && this.inventory[slot].getSize() >= amount; - } + public boolean isInputEmpty(int slot) { + return this.inventory[slot] == null || this.inventory[slot].isEmpty(); } - public boolean isFull() { - for(ItemStack itemstack : this.inventory) { - if(itemstack == null || !itemstack.isFull()) { - return false; - } - } - return true; + public boolean hasInput(int slot, int amount) { + return this.inventory[slot] != null && this.inventory[slot].getSize() >= amount; + } + + public boolean isOutputFull(int slot) { + return this.inventory[slot - this.inputs] != null && this.inventory[slot - this.inputs].isFull(); } public int getField(int id) { @@ -312,5 +342,7 @@ public abstract class Device extends TileEntity implements IInventory, ITickable return 0x8080ff; } - public abstract String formatDisplay(ContainerTile inv); + public String formatDisplay(ContainerTile inv) { + return ""; + } } diff --git a/common/src/main/java/common/tileentity/DeviceEffectGenerator.java b/common/src/main/java/common/tileentity/DeviceEffectGenerator.java index 5d30133a..87b4cc26 100755 --- a/common/src/main/java/common/tileentity/DeviceEffectGenerator.java +++ b/common/src/main/java/common/tileentity/DeviceEffectGenerator.java @@ -13,18 +13,18 @@ import common.world.World; public class DeviceEffectGenerator extends Device { public DeviceEffectGenerator() { - super(2); + super(2, 0); } public boolean isItemValidForSlot(int index, ItemStack stack) { - return index == 0 ? stack.getItem() instanceof ItemPotion : (index == 1 ? stack.getItem() == Items.blazing_powder : false); + return index == 0 ? stack.getItem() instanceof ItemPotion potion && potion.getEffect() != null : (index == 1 ? stack.getItem() == Items.blazing_powder : false); } protected boolean executeFunction() { - if(!this.hasAmount(0, 1) || !this.hasAmount(1, 1) || !(this.getStackInSlot(0).getItem() instanceof ItemPotion potion)) + if(!this.hasInput(0, 1) || !this.hasInput(1, 1) || !(this.getStackInSlot(0).getItem() instanceof ItemPotion potion)) return false; StatusEffect effect = potion.getEffect(); - if(effect == null || !this.hasAmount(1, effect.getAmplifier() + 1)) + if(effect == null || !this.hasInput(1, effect.getAmplifier() + 1)) return false; int levels = 4; // TODO: energy + selector (MachineControl) double r = (double)(levels * 10 + 10); @@ -37,7 +37,7 @@ public class DeviceEffectGenerator extends Device { if(!entity.hasEffect(effect.getPotion()) || entity.getEffect(effect.getPotion()).getAmplifier() < effect.getAmplifier() || entity.getEffect(effect.getPotion()).getRemaining() < 40) { entity.addEffect(new StatusEffect(effect.getPotion(), 180, effect.getAmplifier())); this.decrStackSize(1, effect.getAmplifier() + 1); - if(!this.hasAmount(1, effect.getAmplifier() + 1)) + if(!this.hasInput(1, effect.getAmplifier() + 1)) break; } } @@ -51,8 +51,7 @@ public class DeviceEffectGenerator extends Device { public String formatDisplay(ContainerTile inv) { ItemStack stack = inv.getSlot(0).getStack(); if(stack == null) - return "Kein Trank vorhanden"; - return String.format("Effekt: %s", - stack.getItem() instanceof ItemPotion potion ? (potion.getEffect() != null ? potion.getEffect().getEffectName() : "Keiner") : ""); + return "Trank einlegen"; + return "Gebe Effekt " + (stack.getItem() instanceof ItemPotion potion && potion.getEffect() != null ? potion.getEffect().getEffectName() : ""); } } diff --git a/common/src/main/java/common/tileentity/DeviceMobSpawner.java b/common/src/main/java/common/tileentity/DeviceMobSpawner.java index 16d3dcd5..aec785cc 100755 --- a/common/src/main/java/common/tileentity/DeviceMobSpawner.java +++ b/common/src/main/java/common/tileentity/DeviceMobSpawner.java @@ -12,13 +12,17 @@ import common.vars.Vars; public class DeviceMobSpawner extends Device implements ITickable { public DeviceMobSpawner() { - super(1); + super(1, 0); } private int spawnDelay = 20; private int minSpawnDelay = 200; private int maxSpawnDelay = 800; private int spawnRange = 4; + + public boolean hasProgress() { + return true; + } public boolean isItemValidForSlot(int index, ItemStack stack) { return index == 0 ? stack.getItem() instanceof ItemMobTemplate || stack.getItem() instanceof ItemCharTemplate : false; @@ -27,12 +31,12 @@ public class DeviceMobSpawner extends Device implements ITickable public String formatDisplay(ContainerTile inv) { ItemStack stack = inv.getSlot(0).getStack(); if(stack == null) - return "Keine DNA-Probe vorhanden"; - return String.format("Erschaffe: %s", stack.getItem() instanceof ItemMobTemplate egg ? EntityRegistry.getEntityName(egg.getSpawnedId()) : ((stack.getItem() instanceof ItemCharTemplate egg ? egg.getCharName() : ""))); + return "DNA-Probe einlegen"; + return "Erzeuge " + (stack.getItem() instanceof ItemMobTemplate egg ? EntityRegistry.getEntityName(egg.getSpawnedId()) : ((stack.getItem() instanceof ItemCharTemplate egg ? egg.getCharName() : ""))); } protected boolean executeFunction() { - if(!Vars.mobs || !Vars.spawners || !this.hasAmount(0, 1)) + if(!Vars.mobs || !Vars.spawners || !this.hasInput(0, 1)) return false; if (this.spawnDelay == -1) this.resetTimer(); diff --git a/common/src/main/java/common/tileentity/DeviceTianReactor.java b/common/src/main/java/common/tileentity/DeviceTianReactor.java index a06cfe0c..779591b4 100755 --- a/common/src/main/java/common/tileentity/DeviceTianReactor.java +++ b/common/src/main/java/common/tileentity/DeviceTianReactor.java @@ -4,14 +4,15 @@ import common.init.Items; import common.inventory.ContainerTile; import common.item.ItemStack; import common.tileentity.MachineResource.Type; +import common.util.Color; public class DeviceTianReactor extends Device { public DeviceTianReactor() { - super(2, new MachineResource(Type.OUTPUT, "output.energy", 1024, 0, 0)); + super(2, 0, new MachineResource(Type.OUTPUT, "Gespeichert: $amount/$capacity TF", 1024, 0, 0)); } protected boolean executeFunction() { - if(!this.hasAmount(0, 2)) + if(!this.hasInput(0, 2)) return false; if(this.rand.rarity(5)) return true; @@ -20,29 +21,37 @@ public class DeviceTianReactor extends Device { this.getResource(0).add(this.rand.range(this.temperature / 200, this.temperature / 50), 20, false); return true; } + + public boolean hasTemperature() { + return true; + } protected int getTempIncrement() { - return this.isEmpty(1) ? this.rand.range(20, 50) : (this.temperature >= this.rand.range(4200, 4250) ? 0 : this.rand.range(10, 15)); + return this.isInputEmpty(1) ? this.rand.range(20, 50) : (this.temperature >= this.rand.range(4200, 4250) ? 0 : this.rand.range(10, 15)); } protected int getTempDecrement() { - return this.isEmpty(1) ? this.rand.chance(0, 1, 3) : this.rand.range(1, 3); + return this.isInputEmpty(1) ? this.rand.chance(0, 1, 3) : this.rand.range(1, 3); + } + + public boolean hasProgress() { + return true; } public boolean isItemValidForSlot(int index, ItemStack stack) { return index == 0 ? stack.getItem() == Items.aluminium_ingot : (index == 1 ? stack.getItem() == Items.lead_block : false); } - protected int getMaxTemp() { + public int getMaxTemp() { return 8200; } - public String formatDisplay(ContainerTile inv) { - return String.format("Gespeicherte Energie: %d TF", this.getResource(0).getValue()); - } - public void detonate() { this.worldObj.setBlockToAir(getPos()); this.worldObj.newExplosion(this.getXPos(), this.getYPos(), this.getZPos(), 120); } + + public String formatDisplay(ContainerTile inv) { + return this.status == Status.OVERHEAT ? Color.RED + "!!! GEFAHR !!! Reaktor ist\n" + Color.RED + "überhitzt und muss sofort\n" + Color.RED + "heruntergekühlt werden,\n" + Color.RED + "sonst droht Detonation!" : ""; + } } diff --git a/common/src/main/java/common/tileentity/MachineResource.java b/common/src/main/java/common/tileentity/MachineResource.java index bcae164e..db6f2c35 100755 --- a/common/src/main/java/common/tileentity/MachineResource.java +++ b/common/src/main/java/common/tileentity/MachineResource.java @@ -105,4 +105,8 @@ public class MachineResource { public boolean isAtCapacity(boolean over) { return this.amount >= (this.capacity + (over ? this.overcharge : 0)); } + + public String format() { + return this.name.replace("$amount", "" + this.amount).replace("$undercharge", "" + this.undercharge).replace("$overcharge", "" + this.overcharge).replace("$capacity", "" + this.capacity).replace("$entropy", "" + this.entropy); + } } diff --git a/common/src/main/java/common/vars/Vars.java b/common/src/main/java/common/vars/Vars.java index 689356ad..791e2e44 100755 --- a/common/src/main/java/common/vars/Vars.java +++ b/common/src/main/java/common/vars/Vars.java @@ -25,8 +25,6 @@ public abstract class Vars { public static boolean blockXP = true; @Var(name = "dropBreedingXP") public static boolean breedingXP = true; - @Var(name = "dropSmeltingXP") - public static boolean smeltingXP = true; @Var(name = "dropFishingXP") public static boolean fishingXP = true; @Var(name = "dropMobXP") diff --git a/server/src/main/java/server/network/Player.java b/server/src/main/java/server/network/Player.java index d3abbf02..6b768a31 100755 --- a/server/src/main/java/server/network/Player.java +++ b/server/src/main/java/server/network/Player.java @@ -93,7 +93,6 @@ import common.packet.SPacketDestroyEntities; import common.packet.SPacketDisconnect; import common.packet.SPacketDisplayForm; import common.packet.SPacketKeepAlive; -import common.packet.SPacketLoading; import common.packet.SPacketMapChunkBulk; import common.packet.SPacketMessage; import common.packet.SPacketPlayerPosLook; @@ -281,18 +280,6 @@ public class Player extends User implements Executor, IPlayer return true; } - public void displayLoading(String message) { - this.sendPacket(new SPacketLoading(message)); - } - - public void sendTask(String task, int total) { - this.sendPacket(new SPacketLoading(task, total)); - } - - public void sendProgress(int progress) { - this.sendPacket(new SPacketLoading(progress)); - } - public void onEntityDeath() { this.deathPos = this.entity.getPos(); this.entity.sendDeathMessage();