Controller should bundle machines of the same type together when sending to GUI

This commit is contained in:
Raoul Van den Berge
2016-05-15 12:27:23 +02:00
parent b3aa2182de
commit a30c9bcb2e
4 changed files with 50 additions and 36 deletions

View File

@@ -2,7 +2,6 @@ package refinedstorage.gui;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.util.text.translation.I18n;
import refinedstorage.container.ContainerController; import refinedstorage.container.ContainerController;
import refinedstorage.gui.sidebutton.SideButtonRedstoneMode; import refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
import refinedstorage.tile.TileController; import refinedstorage.tile.TileController;
@@ -84,8 +83,8 @@ public class GuiController extends GuiBase {
float scale = 0.5f; float scale = 0.5f;
GlStateManager.scale(scale, scale, 1); GlStateManager.scale(scale, scale, 1);
drawString(calculateOffsetOnScale(x + 1, scale), calculateOffsetOnScale(y - 3, scale), machine.stack.getDisplayName()); drawString(calculateOffsetOnScale(x + 1, scale), calculateOffsetOnScale(y - 2, scale), machine.stack.getDisplayName());
drawString(calculateOffsetOnScale(x + 21, scale), calculateOffsetOnScale(y + 10, scale), t("misc.refinedstorage:energy_usage_minimal", machine.energyUsage)); drawString(calculateOffsetOnScale(x + 21, scale), calculateOffsetOnScale(y + 10, scale), t("gui.refinedstorage:controller.machine_amount", machine.amount));
GlStateManager.popMatrix(); GlStateManager.popMatrix();
@@ -105,11 +104,7 @@ public class GuiController extends GuiBase {
} }
if (machineHovering != null) { if (machineHovering != null) {
String message = I18n.translateToLocalFormatted("gui.refinedstorage:controller.machine_position.x", machineHovering.x); drawTooltip(mouseX, mouseY, t("misc.refinedstorage:energy_usage_minimal", machineHovering.energyUsage));
message += "\n" + I18n.translateToLocalFormatted("gui.refinedstorage:controller.machine_position.y", machineHovering.y);
message += "\n" + I18n.translateToLocalFormatted("gui.refinedstorage:controller.machine_position.z", machineHovering.z);
drawTooltip(mouseX, mouseY, message);
} }
if (inBounds(barX, barY, barWidth, barHeight, mouseX, mouseY)) { if (inBounds(barX, barY, barWidth, barHeight, mouseX, mouseY)) {

View File

@@ -41,10 +41,25 @@ import java.util.*;
public class TileController extends TileBase implements IEnergyReceiver, ISynchronizedContainer, IRedstoneModeConfig { public class TileController extends TileBase implements IEnergyReceiver, ISynchronizedContainer, IRedstoneModeConfig {
public class ClientSideMachine { public class ClientSideMachine {
public ItemStack stack; public ItemStack stack;
public int amount;
public int energyUsage; public int energyUsage;
public int x;
public int y; @Override
public int z; public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ClientSideMachine other = (ClientSideMachine) o;
return energyUsage == other.energyUsage && RefinedStorageUtils.compareStack(stack, other.stack);
}
@Override
public int hashCode() {
int result = stack.hashCode();
result = 31 * result + energyUsage;
return result;
}
} }
public static final int ENERGY_CAPACITY = 32000; public static final int ENERGY_CAPACITY = 32000;
@@ -583,18 +598,10 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
int size = buf.readInt(); int size = buf.readInt();
for (int i = 0; i < size; ++i) { for (int i = 0; i < size; ++i) {
int energyUsage = buf.readInt();
int x = buf.readInt();
int y = buf.readInt();
int z = buf.readInt();
ItemStack stack = ByteBufUtils.readItemStack(buf);
ClientSideMachine machine = new ClientSideMachine(); ClientSideMachine machine = new ClientSideMachine();
machine.x = x; machine.energyUsage = buf.readInt();
machine.y = y; machine.amount = buf.readInt();
machine.z = z; machine.stack = ByteBufUtils.readItemStack(buf);
machine.energyUsage = energyUsage;
machine.stack = stack;
machines.add(machine); machines.add(machine);
} }
@@ -608,18 +615,34 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
buf.writeInt(redstoneMode.id); buf.writeInt(redstoneMode.id);
buf.writeInt(machines.size()); List<ClientSideMachine> m = new ArrayList<ClientSideMachine>();
for (TileMachine machine : machines) { for (TileMachine machine : machines) {
buf.writeInt(machine.getEnergyUsage());
buf.writeInt(machine.getPos().getX());
buf.writeInt(machine.getPos().getY());
buf.writeInt(machine.getPos().getZ());
IBlockState state = worldObj.getBlockState(machine.getPos()); IBlockState state = worldObj.getBlockState(machine.getPos());
ByteBufUtils.writeItemStack(buf, new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state))); ClientSideMachine clientMachine = new ClientSideMachine();
clientMachine.energyUsage = machine.getEnergyUsage();
clientMachine.amount = 1;
clientMachine.stack = new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state));
if (m.contains(clientMachine)) {
for (ClientSideMachine other : m) {
if (other.equals(clientMachine)) {
other.amount++;
}
}
} else {
m.add(clientMachine);
}
}
buf.writeInt(m.size());
for (ClientSideMachine machine : m) {
buf.writeInt(machine.energyUsage);
buf.writeInt(machine.amount);
ByteBufUtils.writeItemStack(buf, machine.stack);
} }
} }

View File

@@ -2,9 +2,7 @@ itemGroup.refinedstorage=Refined Storage
gui.refinedstorage:controller.0=Controller gui.refinedstorage:controller.0=Controller
gui.refinedstorage:controller.1=Creative Controller gui.refinedstorage:controller.1=Creative Controller
gui.refinedstorage:controller.machine_position.x=X: %d gui.refinedstorage:controller.machine_amount=%dx
gui.refinedstorage:controller.machine_position.y=Y: %d
gui.refinedstorage:controller.machine_position.z=Z: %d
gui.refinedstorage:grid=Grid gui.refinedstorage:grid=Grid
gui.refinedstorage:grid.craft=Craft gui.refinedstorage:grid.craft=Craft
gui.refinedstorage:grid.pattern=Pattern gui.refinedstorage:grid.pattern=Pattern

View File

@@ -2,9 +2,7 @@ itemGroup.refinedstorage=Refined Storage
gui.refinedstorage:controller.0=Controller gui.refinedstorage:controller.0=Controller
gui.refinedstorage:controller.1=Creatieve Controller gui.refinedstorage:controller.1=Creatieve Controller
gui.refinedstorage:controller.machine_position.x=X: %d gui.refinedstorage:controller.machine_amount=%dx
gui.refinedstorage:controller.machine_position.y=Y: %d
gui.refinedstorage:controller.machine_position.z=Z: %d
gui.refinedstorage:grid=Rooster gui.refinedstorage:grid=Rooster
gui.refinedstorage:grid.craft=Craft gui.refinedstorage:grid.craft=Craft
gui.refinedstorage:grid.pattern=Patroon gui.refinedstorage:grid.pattern=Patroon