mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-28 07:35:47 +00:00
Fix #295 Display energy stored on machines correctly
This commit is contained in:
1 parent
797b794214
commit
3488a39016
13 files changed
+135
-37
No files matched your search
@@ -92,7 +92,7 @@ public class Config {
|
||||
// Hints
|
||||
public static boolean disableHints = false;
|
||||
public static final HashMap<String, String[]> hints = new HashMap<String, String[]>();
|
||||
public static boolean disableEnergyStat = false;
|
||||
public static boolean enableEnergyStat = true;
|
||||
|
||||
public static boolean isStructureEnabled(String uid) {
|
||||
return !Config.disabledStructures.contains(uid);
|
||||
@@ -237,10 +237,10 @@ public class Config {
|
||||
Config.disableHints = Boolean.parseBoolean(property.value);
|
||||
property = config.get("tweaks.energystat.disabled", CATEGORY_COMMON, true);
|
||||
property.comment = "set to true to disable energy statistics on energy consumers.";
|
||||
Config.disableEnergyStat = !isDebug && Boolean.parseBoolean(property.value);
|
||||
Config.enableEnergyStat = !Boolean.parseBoolean(property.value);
|
||||
property = config.get("tweaks.tooltip.liquidamount.disabled", CATEGORY_COMMON, false);
|
||||
property.comment = "set to true to disable displaying liquid amounts in tank tooltips.";
|
||||
Config.tooltipLiquidAmount = isDebug || !Boolean.parseBoolean(property.value);
|
||||
Config.tooltipLiquidAmount = !Boolean.parseBoolean(property.value);
|
||||
|
||||
property = config.get("tweaks.permissions.disabled", CATEGORY_COMMON, false);
|
||||
property.comment = "set to true to disable access restrictions on forestry machines.";
|
||||
|
||||
@@ -37,7 +37,7 @@ import net.minecraftforge.fluids.IFluidHandler;
|
||||
import forestry.core.fluids.tanks.FakeTank;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.inventory.ITileFilter;
|
||||
import forestry.core.network.PacketGuiInteger;
|
||||
import forestry.core.network.PacketProgressBarUpdate;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.NBTUtil;
|
||||
import forestry.core.utils.NBTUtil.NBTList;
|
||||
@@ -177,7 +177,7 @@ public class TankManager extends ForwardingList<StandardTank> implements IFluidH
|
||||
}
|
||||
|
||||
player.sendProgressBarUpdate(container, tankIndex * NETWORK_DATA, fluidId);
|
||||
PacketGuiInteger packet = new PacketGuiInteger(container.windowId, tankIndex * NETWORK_DATA + 1, fluidAmount);
|
||||
PacketProgressBarUpdate packet = new PacketProgressBarUpdate(container.windowId, tankIndex * NETWORK_DATA + 1, fluidAmount);
|
||||
Proxies.net.sendToPlayer(packet, (EntityPlayerMP) player);
|
||||
}
|
||||
|
||||
@@ -203,18 +203,18 @@ public class TankManager extends ForwardingList<StandardTank> implements IFluidH
|
||||
fluidAmount = fluidStack.amount;
|
||||
}
|
||||
player.sendProgressBarUpdate(container, tankIndex * NETWORK_DATA, fluidId);
|
||||
PacketGuiInteger packet = new PacketGuiInteger(container.windowId, tankIndex * NETWORK_DATA + 1, fluidAmount);
|
||||
PacketProgressBarUpdate packet = new PacketProgressBarUpdate(container.windowId, tankIndex * NETWORK_DATA + 1, fluidAmount);
|
||||
Proxies.net.sendToPlayer(packet, player);
|
||||
} else if (fluidStack != null && prev != null) {
|
||||
if (fluidStack.getFluid() != prev.getFluid()) {
|
||||
player.sendProgressBarUpdate(container, tankIndex * NETWORK_DATA, fluidStack.getFluid().getID());
|
||||
}
|
||||
if (fluidStack.amount != prev.amount) {
|
||||
PacketGuiInteger packet = new PacketGuiInteger(container.windowId, tankIndex * NETWORK_DATA + 1, fluidStack.amount);
|
||||
PacketProgressBarUpdate packet = new PacketProgressBarUpdate(container.windowId, tankIndex * NETWORK_DATA + 1, fluidStack.amount);
|
||||
Proxies.net.sendToPlayer(packet, player);
|
||||
}
|
||||
if (color != pColor) {
|
||||
PacketGuiInteger packet = new PacketGuiInteger(container.windowId, tankIndex * NETWORK_DATA + 2, color);
|
||||
PacketProgressBarUpdate packet = new PacketProgressBarUpdate(container.windowId, tankIndex * NETWORK_DATA + 2, color);
|
||||
Proxies.net.sendToPlayer(packet, player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,7 +248,7 @@ public abstract class TileForestry extends TileEntity implements IStreamable, IR
|
||||
Proxies.net.sendToPlayer(packet, player);
|
||||
}
|
||||
|
||||
public final void writeGuiData(DataOutputStreamForestry data) throws IOException {
|
||||
public void writeGuiData(DataOutputStreamForestry data) throws IOException {
|
||||
writeErrorData(data);
|
||||
|
||||
if (owner == null) {
|
||||
@@ -261,7 +261,7 @@ public abstract class TileForestry extends TileEntity implements IStreamable, IR
|
||||
}
|
||||
}
|
||||
|
||||
public final void readGuiData(DataInputStreamForestry data) throws IOException {
|
||||
public void readGuiData(DataInputStreamForestry data) throws IOException {
|
||||
readErrorData(data);
|
||||
|
||||
byte accessOrdinal = data.readByte();
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.gadgets;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
@@ -19,6 +21,8 @@ import cpw.mods.fml.common.Optional;
|
||||
import forestry.core.EnumErrorCode;
|
||||
import forestry.core.interfaces.IPowerHandler;
|
||||
import forestry.core.interfaces.IRenderableMachine;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.utils.EnumTankLevel;
|
||||
import forestry.energy.EnergyManager;
|
||||
|
||||
@@ -92,6 +96,18 @@ public abstract class TilePowered extends TileBase implements IRenderableMachine
|
||||
energyManager.readFromNBT(nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeGuiData(DataOutputStreamForestry data) throws IOException {
|
||||
super.writeGuiData(data);
|
||||
energyManager.writeData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readGuiData(DataInputStreamForestry data) throws IOException {
|
||||
super.readGuiData(data);
|
||||
energyManager.readData(data);
|
||||
}
|
||||
|
||||
// / ADDITIONAL LIQUID HANDLING
|
||||
@Override
|
||||
public EnumTankLevel getPrimaryLevel() {
|
||||
|
||||
@@ -17,6 +17,8 @@ import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.core.gui.slots.SlotForestry;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.SlotHelper;
|
||||
|
||||
public abstract class ContainerForestry extends Container {
|
||||
@@ -62,4 +64,12 @@ public abstract class ContainerForestry extends Container {
|
||||
}
|
||||
|
||||
protected abstract boolean canAccess(EntityPlayer player);
|
||||
|
||||
protected final void sendPacketToCrafters(ForestryPacket packet) {
|
||||
for (Object crafter : crafters) {
|
||||
if (crafter instanceof EntityPlayer) {
|
||||
Proxies.net.sendToPlayer(packet, (EntityPlayer) crafter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,10 @@ import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
import forestry.api.core.IErrorState;
|
||||
import forestry.core.gadgets.TileForestry;
|
||||
import forestry.core.interfaces.IPowerHandler;
|
||||
import forestry.core.network.PacketErrorUpdate;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.network.PacketGuiEnergy;
|
||||
import forestry.energy.EnergyManager;
|
||||
|
||||
public class ContainerTile<T extends TileForestry> extends ContainerForestry {
|
||||
|
||||
@@ -41,6 +43,7 @@ public class ContainerTile<T extends TileForestry> extends ContainerForestry {
|
||||
}
|
||||
|
||||
private ImmutableSet<IErrorState> previousErrorStates;
|
||||
private int previousEnergyManagerData = 0;
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
@@ -50,13 +53,27 @@ public class ContainerTile<T extends TileForestry> extends ContainerForestry {
|
||||
|
||||
if ((previousErrorStates != null) && !errorStates.equals(previousErrorStates)) {
|
||||
PacketErrorUpdate packet = new PacketErrorUpdate(tile);
|
||||
for (Object crafter : crafters) {
|
||||
if (crafter instanceof EntityPlayer) {
|
||||
Proxies.net.sendToPlayer(packet, (EntityPlayer) crafter);
|
||||
}
|
||||
}
|
||||
sendPacketToCrafters(packet);
|
||||
}
|
||||
|
||||
previousErrorStates = errorStates;
|
||||
|
||||
if (tile instanceof IPowerHandler) {
|
||||
EnergyManager energyManager = ((IPowerHandler) tile).getEnergyManager();
|
||||
int energyManagerData = energyManager.toGuiInt();
|
||||
if (energyManagerData != previousEnergyManagerData) {
|
||||
PacketGuiEnergy packet = new PacketGuiEnergy(windowId, energyManagerData);
|
||||
sendPacketToCrafters(packet);
|
||||
|
||||
previousEnergyManagerData = energyManagerData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onGuiEnergy(int energyStored) {
|
||||
if (tile instanceof IPowerHandler) {
|
||||
EnergyManager energyManager = ((IPowerHandler) tile).getEnergyManager();
|
||||
energyManager.fromGuiInt(energyStored);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,7 +89,7 @@ public abstract class GuiForestry<C extends Container, I extends IInventory> ext
|
||||
ledgerManager.add(new ClimateLedger(ledgerManager, (IClimatised) inventory));
|
||||
}
|
||||
|
||||
if (!Config.disableEnergyStat && inventory instanceof IPowerHandler && ((IPowerHandler) inventory).getEnergyManager().getMaxEnergyStored() > 0) {
|
||||
if (Config.enableEnergyStat && inventory instanceof IPowerHandler && ((IPowerHandler) inventory).getEnergyManager().getMaxEnergyStored() > 0) {
|
||||
ledgerManager.add(new PowerLedger(ledgerManager, (IPowerHandler) inventory));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.network;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
|
||||
import forestry.core.gui.ContainerTile;
|
||||
|
||||
public class PacketGuiEnergy extends ForestryPacket {
|
||||
|
||||
private int windowId;
|
||||
private int value;
|
||||
|
||||
public static void onPacketData(DataInputStreamForestry data) throws IOException {
|
||||
new PacketGuiEnergy(data);
|
||||
}
|
||||
|
||||
public PacketGuiEnergy(DataInputStreamForestry data) throws IOException {
|
||||
super(data);
|
||||
}
|
||||
|
||||
public PacketGuiEnergy(int windowId, int value) {
|
||||
super(PacketId.GUI_ENERGY);
|
||||
this.windowId = windowId;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
data.writeVarInt(windowId);
|
||||
data.writeVarInt(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readData(DataInputStreamForestry data) throws IOException {
|
||||
windowId = data.readVarInt();
|
||||
value = data.readVarInt();
|
||||
|
||||
EntityClientPlayerMP player = FMLClientHandler.instance().getClient().thePlayer;
|
||||
|
||||
if (player.openContainer instanceof ContainerTile && player.openContainer.windowId == windowId) {
|
||||
((ContainerTile) player.openContainer).onGuiEnergy(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,14 +145,18 @@ public class PacketHandler {
|
||||
onGenomeTrackerUpdate(packet);
|
||||
return true;
|
||||
}
|
||||
case GUI_INTEGER: {
|
||||
PacketGuiInteger packet = new PacketGuiInteger(data);
|
||||
case GUI_PROGRESS_BAR: {
|
||||
PacketProgressBarUpdate.onPacketData(data);
|
||||
return true;
|
||||
}
|
||||
case GUI_ITEMSTACK: {
|
||||
PacketItemStackDisplay.onPacketData(data);
|
||||
return true;
|
||||
}
|
||||
case GUI_ENERGY: {
|
||||
PacketGuiEnergy.onPacketData(data);
|
||||
return true;
|
||||
}
|
||||
default: {
|
||||
for (IPacketHandler handler : PluginManager.packetHandlers) {
|
||||
if (handler.onPacketData(packetId, data, player)) {
|
||||
|
||||
@@ -28,8 +28,9 @@ public enum PacketId {
|
||||
IMPRINT_SELECTION_GET,
|
||||
GUI_SELECTION_SET,
|
||||
GUI_LAYOUT_SELECT,
|
||||
GUI_INTEGER,
|
||||
GUI_PROGRESS_BAR,
|
||||
GUI_ITEMSTACK,
|
||||
GUI_ENERGY,
|
||||
|
||||
PIPETTE_CLICK,
|
||||
|
||||
|
||||
+8
-4
@@ -20,16 +20,20 @@ import cpw.mods.fml.client.FMLClientHandler;
|
||||
* @author CovertJaguar <http://www.railcraft.info>
|
||||
*/
|
||||
|
||||
public class PacketGuiInteger extends ForestryPacket {
|
||||
public class PacketProgressBarUpdate extends ForestryPacket {
|
||||
|
||||
private int windowId, dataId, value;
|
||||
|
||||
public PacketGuiInteger(DataInputStreamForestry data) throws IOException {
|
||||
public static void onPacketData(DataInputStreamForestry data) throws IOException {
|
||||
new PacketProgressBarUpdate(data);
|
||||
}
|
||||
|
||||
public PacketProgressBarUpdate(DataInputStreamForestry data) throws IOException {
|
||||
super(data);
|
||||
}
|
||||
|
||||
public PacketGuiInteger(int windowId, int dataId, int value) {
|
||||
super(PacketId.GUI_INTEGER);
|
||||
public PacketProgressBarUpdate(int windowId, int dataId, int value) {
|
||||
super(PacketId.GUI_PROGRESS_BAR);
|
||||
this.windowId = windowId;
|
||||
this.dataId = dataId;
|
||||
this.value = value;
|
||||
@@ -10,7 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.factory.gui;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
@@ -23,7 +22,6 @@ import forestry.core.gui.slots.SlotLocked;
|
||||
import forestry.core.gui.slots.SlotOutput;
|
||||
import forestry.core.interfaces.IContainerCrafting;
|
||||
import forestry.core.network.PacketItemStackDisplay;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.factory.gadgets.MachineCarpenter;
|
||||
|
||||
public class ContainerCarpenter extends ContainerLiquidTanks<MachineCarpenter> implements IContainerCrafting {
|
||||
@@ -74,11 +72,7 @@ public class ContainerCarpenter extends ContainerLiquidTanks<MachineCarpenter> i
|
||||
oldCraftPreview = newCraftPreview;
|
||||
|
||||
PacketItemStackDisplay packet = new PacketItemStackDisplay(tile, newCraftPreview);
|
||||
for (Object crafter : crafters) {
|
||||
if (crafter instanceof EntityPlayer) {
|
||||
Proxies.net.sendToPlayer(packet, (EntityPlayer) crafter);
|
||||
}
|
||||
}
|
||||
sendPacketToCrafters(packet);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ import forestry.core.gui.slots.SlotCrafter;
|
||||
import forestry.core.interfaces.IContainerCrafting;
|
||||
import forestry.core.network.PacketGuiSelect;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.network.PacketTileStream;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.factory.gadgets.TileWorktable;
|
||||
@@ -72,11 +71,7 @@ public class ContainerWorktable extends ContainerTile<TileWorktable> implements
|
||||
lastUpdate = tile.getMemory().getLastUpdate();
|
||||
|
||||
PacketWorktableMemoryUpdate packet = new PacketWorktableMemoryUpdate(tile);
|
||||
for (Object crafter : crafters) {
|
||||
if (crafter instanceof EntityPlayer) {
|
||||
Proxies.net.sendToPlayer(packet, (EntityPlayer) crafter);
|
||||
}
|
||||
}
|
||||
sendPacketToCrafters(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user