mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-26 23:13:21 +00:00
return area can be toggled into storage area - should solve client/server desync issues
This commit is contained in:
1 parent
971cd290c8
commit
8f9cca470b
7 files changed
+164
-4
No files matched your search
@@ -33,6 +33,8 @@ public class BlockInventoryPanel extends AbstractMachineBlock<TileInventoryPanel
|
||||
PacketHandler.INSTANCE.registerMessage(PacketDatabaseReset.class, PacketDatabaseReset.class, PacketHandler.nextID(), Side.CLIENT);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketGuiSettings.class, PacketGuiSettings.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketStoredCraftingRecipe.class, PacketStoredCraftingRecipe.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketSetExtractionDisabled.class, PacketSetExtractionDisabled.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketUpdateExtractionDisabled.class, PacketUpdateExtractionDisabled.class, PacketHandler.nextID(), Side.CLIENT);
|
||||
|
||||
BlockInventoryPanel panel = new BlockInventoryPanel();
|
||||
panel.init();
|
||||
|
||||
@@ -47,6 +47,8 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
|
||||
private static final Rectangle btnRefill = new Rectangle(24+85, 32, 20, 20);
|
||||
|
||||
private static final Rectangle btnReturnArea = new Rectangle(24+6, 72, 5 * 18, 8);
|
||||
|
||||
private static final int ID_SORT = 9876;
|
||||
private static final int ID_CLEAR = 9877;
|
||||
|
||||
@@ -66,6 +68,7 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
|
||||
private final String headerCrafting;
|
||||
private final String headerReturn;
|
||||
private final String headerStorage;
|
||||
private final String headerInventory;
|
||||
private final String infoTextFilter;
|
||||
private final String infoTextOffline;
|
||||
@@ -125,13 +128,28 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
|
||||
headerCrafting = Lang.localize("gui.inventorypanel.header.crafting");
|
||||
headerReturn = Lang.localize("gui.inventorypanel.header.return");
|
||||
headerStorage = Lang.localize("gui.inventorypanel.header.storage");
|
||||
headerInventory = Lang.localize("container.inventory", false);
|
||||
infoTextFilter = Lang.localize("gui.inventorypanel.info.filter");
|
||||
infoTextOffline = Lang.localize("gui.inventorypanel.info.offline");
|
||||
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
TooltipAddera.addTooltipFromResources(list, "enderio.gui.inventorypanel.tooltip.return.line");
|
||||
addToolTip(new GuiToolTip(new Rectangle(24+6, 72, 5 * 18, 8), list));
|
||||
addToolTip(new GuiToolTip(btnReturnArea, list) {
|
||||
@Override
|
||||
public boolean shouldDraw() {
|
||||
return super.shouldDraw() && !getTileEntity().isExtractionDisabled();
|
||||
}
|
||||
});
|
||||
|
||||
list.clear();
|
||||
TooltipAddera.addTooltipFromResources(list, "enderio.gui.inventorypanel.tooltip.storage.line");
|
||||
addToolTip(new GuiToolTip(btnReturnArea, list) {
|
||||
@Override
|
||||
public boolean shouldDraw() {
|
||||
return super.shouldDraw() && getTileEntity().isExtractionDisabled();
|
||||
}
|
||||
});
|
||||
|
||||
list.clear();
|
||||
TooltipAddera.addTooltipFromResources(list, "enderio.gui.inventorypanel.tooltip.filterslot.line");
|
||||
@@ -276,9 +294,11 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
}
|
||||
|
||||
int headerColor = 0x404040;
|
||||
int focusedColor = 0x648494;
|
||||
FontRenderer fr = getFontRenderer();
|
||||
fr.drawString(headerCrafting, sx + 24 + 7, sy + 6, headerColor);
|
||||
fr.drawString(headerReturn, sx + 24 + 7, sy + 72, headerColor);
|
||||
fr.drawString(te.isExtractionDisabled() ? headerStorage : headerReturn, sx + 24 + 7, sy + 72,
|
||||
btnReturnArea.contains(mouseX - sx, mouseY - sy) ? focusedColor : headerColor);
|
||||
fr.drawString(headerInventory, sx + 24 + 38, sy + 120, headerColor);
|
||||
|
||||
SmartTank fuelTank = te.fuelTank;
|
||||
@@ -472,6 +492,12 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(btnReturnArea.contains(x, y)) {
|
||||
TileInventoryPanel te = getTileEntity();
|
||||
playClickSound();
|
||||
te.setExtractionDisabled(!te.isExtractionDisabled());
|
||||
}
|
||||
}
|
||||
|
||||
private void playClickSound() {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package crazypants.enderio.machine.invpanel;
|
||||
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.network.MessageTileEntity;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class PacketSetExtractionDisabled extends MessageTileEntity<TileInventoryPanel> implements IMessageHandler<PacketSetExtractionDisabled, IMessage> {
|
||||
|
||||
private boolean extractionDisabled;
|
||||
|
||||
public PacketSetExtractionDisabled() {
|
||||
}
|
||||
|
||||
public PacketSetExtractionDisabled(TileInventoryPanel tile, boolean extractionDisabled) {
|
||||
super(tile);
|
||||
this.extractionDisabled = extractionDisabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
super.fromBytes(buf);
|
||||
extractionDisabled = buf.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
super.toBytes(buf);
|
||||
buf.writeBoolean(extractionDisabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketSetExtractionDisabled message, MessageContext ctx) {
|
||||
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
TileEntity te = player.worldObj.getTileEntity(message.x, message.y, message.z);
|
||||
if(te instanceof TileInventoryPanel) {
|
||||
TileInventoryPanel teInvPanel = (TileInventoryPanel) te;
|
||||
teInvPanel.setExtractionDisabled(message.extractionDisabled);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package crazypants.enderio.machine.invpanel;
|
||||
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.network.MessageTileEntity;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class PacketUpdateExtractionDisabled extends MessageTileEntity<TileInventoryPanel> implements IMessageHandler<PacketUpdateExtractionDisabled, IMessage> {
|
||||
|
||||
private boolean extractionDisabled;
|
||||
|
||||
public PacketUpdateExtractionDisabled() {
|
||||
}
|
||||
|
||||
public PacketUpdateExtractionDisabled(TileInventoryPanel tile, boolean extractionDisabled) {
|
||||
super(tile);
|
||||
this.extractionDisabled = extractionDisabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
super.fromBytes(buf);
|
||||
extractionDisabled = buf.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
super.toBytes(buf);
|
||||
buf.writeBoolean(extractionDisabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketUpdateExtractionDisabled message, MessageContext ctx) {
|
||||
EntityPlayer player = EnderIO.proxy.getClientPlayer();
|
||||
TileEntity te = player.worldObj.getTileEntity(message.x, message.y, message.z);
|
||||
if(te instanceof TileInventoryPanel) {
|
||||
TileInventoryPanel teInvPanel = (TileInventoryPanel) te;
|
||||
teInvPanel.updateExtractionDisabled(message.extractionDisabled);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -47,6 +47,7 @@ public class TileInventoryPanel extends AbstractMachineEntity implements IFluidH
|
||||
private InventoryDatabaseClient dbClient;
|
||||
|
||||
private boolean active;
|
||||
private boolean extractionDisabled;
|
||||
|
||||
public InventoryPanelContainer eventHandler;
|
||||
private IItemFilter itemFilter;
|
||||
@@ -86,6 +87,11 @@ public class TileInventoryPanel extends AbstractMachineEntity implements IFluidH
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canExtractItem(int slot, ItemStack itemstack) {
|
||||
return !extractionDisabled && super.canExtractItem(slot, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isMachineItemValidForSlot(int slot, ItemStack stack) {
|
||||
if(slot == SLOT_VIEW_FILTER && stack != null) {
|
||||
@@ -260,12 +266,36 @@ public class TileInventoryPanel extends AbstractMachineEntity implements IFluidH
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isExtractionDisabled() {
|
||||
return extractionDisabled;
|
||||
}
|
||||
|
||||
public void setExtractionDisabled(boolean extractionDisabled) {
|
||||
if(worldObj != null) {
|
||||
if(worldObj.isRemote) {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketSetExtractionDisabled(this, extractionDisabled));
|
||||
} else if(this.extractionDisabled != extractionDisabled) {
|
||||
this.extractionDisabled = extractionDisabled;
|
||||
PacketHandler.INSTANCE.sendToDimension(new PacketUpdateExtractionDisabled(this, extractionDisabled), worldObj.provider.dimensionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called by PacketUpdateExtractionDisabled on the client side
|
||||
* @param extractionDisabled if extraction is disabled
|
||||
*/
|
||||
void updateExtractionDisabled(boolean extractionDisabled) {
|
||||
this.extractionDisabled = extractionDisabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCommon(NBTTagCompound nbtRoot) {
|
||||
super.writeCommon(nbtRoot);
|
||||
fuelTank.writeCommon("fuelTank", nbtRoot);
|
||||
nbtRoot.setInteger("guiSortMode", guiSortMode);
|
||||
nbtRoot.setString("guiFilterString", guiFilterString);
|
||||
nbtRoot.setBoolean("extractionDisabled", extractionDisabled);
|
||||
|
||||
if(!storedCraftingRecipes.isEmpty()) {
|
||||
NBTTagList recipesNBT = new NBTTagList();
|
||||
@@ -284,6 +314,7 @@ public class TileInventoryPanel extends AbstractMachineEntity implements IFluidH
|
||||
fuelTank.readCommon("fuelTank", nbtRoot);
|
||||
guiSortMode = nbtRoot.getInteger("guiSortMode");
|
||||
guiFilterString = nbtRoot.getString("guiFilterString");
|
||||
extractionDisabled = nbtRoot.getBoolean("extractionDisabled");
|
||||
faceModes = null;
|
||||
|
||||
storedCraftingRecipes.clear();
|
||||
|
||||
@@ -187,7 +187,9 @@ public class CraftingHelper {
|
||||
}
|
||||
Candidate candidate = new Candidate(stack);
|
||||
InventoryPanelContainer container = gui.getContainer();
|
||||
findCandidates(candidate, stack, container.getReturnAreaSlots());
|
||||
if(container.getInventoryPanel().isExtractionDisabled()) {
|
||||
findCandidates(candidate, stack, container.getReturnAreaSlots());
|
||||
}
|
||||
findCandidates(candidate, stack, container.getPlayerInventorySlots());
|
||||
findCandidates(candidate, stack, container.getPlayerHotbarSlots());
|
||||
if (candidate.available == 0 && db != null) {
|
||||
|
||||
Reference in new issue
Block a user