mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-20 12:09:39 +00:00
Minor cleanup, tidy Imprinter networking
This commit is contained in:
1 parent
3e0cf7c302
commit
0ea878d7bc
8 files changed
+30
-117
No files matched your search
@@ -13,24 +13,19 @@ package forestry.apiculture.gui;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.apiculture.items.ItemImprinter.ImprinterInventory;
|
||||
import forestry.apiculture.network.PacketImprintSelectionRequest;
|
||||
import forestry.apiculture.network.PacketImprintSelectionResponse;
|
||||
import forestry.core.gui.ContainerItemInventory;
|
||||
import forestry.core.gui.IGuiSelectable;
|
||||
import forestry.core.gui.slots.SlotFiltered;
|
||||
import forestry.core.gui.slots.SlotOutput;
|
||||
import forestry.core.network.IForestryPacketServer;
|
||||
import forestry.core.network.PacketGuiSelectRequest;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
|
||||
public class ContainerImprinter extends ContainerItemInventory<ImprinterInventory> implements IGuiSelectable {
|
||||
|
||||
private boolean isNetSynced = false;
|
||||
|
||||
public ContainerImprinter(InventoryPlayer inventoryplayer, ImprinterInventory inventory) {
|
||||
super(inventory, inventoryplayer, 8, 103);
|
||||
|
||||
@@ -42,62 +37,29 @@ public class ContainerImprinter extends ContainerItemInventory<ImprinterInventor
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(EntityPlayer entityplayer) {
|
||||
|
||||
if (entityplayer.worldObj.isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Drop everything still in there.
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++) {
|
||||
ItemStack stack = inventory.getStackInSlot(i);
|
||||
if (stack == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Proxies.common.dropItemPlayer(entityplayer, stack);
|
||||
inventory.setInventorySlotContents(i, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void advanceSelection(int index) {
|
||||
sendSelectionChange(index, 0);
|
||||
}
|
||||
|
||||
public void regressSelection(int index) {
|
||||
sendSelectionChange(index, 1);
|
||||
}
|
||||
|
||||
public void updateContainer(World world) {
|
||||
if (!isNetSynced && world.isRemote) {
|
||||
isNetSynced = true;
|
||||
Proxies.net.sendToServer(new PacketImprintSelectionRequest());
|
||||
}
|
||||
}
|
||||
|
||||
private void sendSelectionChange(int index, int advance) {
|
||||
IForestryPacketServer packet = new PacketGuiSelectRequest(index, advance);
|
||||
Proxies.net.sendToServer(packet);
|
||||
isNetSynced = false;
|
||||
InventoryUtil.dropInventory(inventory, entityplayer.worldObj, entityplayer.posX, entityplayer.posY, entityplayer.posZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSelectionRequest(EntityPlayerMP player, PacketGuiSelectRequest packetRequest) {
|
||||
if (packetRequest.getSecondaryIndex() == 0) {
|
||||
if (packetRequest.getPrimaryIndex() == 0) {
|
||||
if (packetRequest.getPrimaryIndex() == 0) {
|
||||
if (packetRequest.getSecondaryIndex() == 0) {
|
||||
inventory.advancePrimary();
|
||||
} else {
|
||||
inventory.advanceSecondary();
|
||||
inventory.regressPrimary();
|
||||
}
|
||||
} else if (packetRequest.getPrimaryIndex() == 0) {
|
||||
inventory.regressPrimary();
|
||||
} else {
|
||||
inventory.regressSecondary();
|
||||
if (packetRequest.getSecondaryIndex() == 0) {
|
||||
inventory.advanceSecondary();
|
||||
} else {
|
||||
inventory.regressSecondary();
|
||||
}
|
||||
}
|
||||
|
||||
sendSelection(player);
|
||||
}
|
||||
|
||||
public void sendSelection(EntityPlayerMP player) {
|
||||
PacketImprintSelectionResponse packetResponse = new PacketImprintSelectionResponse(inventory.getPrimaryIndex(), inventory.getSecondaryIndex());
|
||||
Proxies.net.sendToPlayer(packetResponse, player);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import forestry.apiculture.items.ItemImprinter.ImprinterInventory;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.config.ForestryItem;
|
||||
import forestry.core.gui.GuiForestry;
|
||||
import forestry.core.network.PacketGuiSelectRequest;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.StringUtil;
|
||||
|
||||
@@ -54,7 +55,6 @@ public class GuiImprinter extends GuiForestry<ContainerImprinter, ImprinterInven
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) {
|
||||
container.updateContainer(Proxies.common.getRenderWorld());
|
||||
super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY);
|
||||
|
||||
int offset = (138 - fontRendererObj.getStringWidth(StringUtil.localize("gui.imprinter.name"))) / 2;
|
||||
@@ -106,9 +106,9 @@ public class GuiImprinter extends GuiForestry<ContainerImprinter, ImprinterInven
|
||||
}
|
||||
|
||||
if (k == 0) {
|
||||
container.advanceSelection(slot);
|
||||
advanceSelection(slot);
|
||||
} else {
|
||||
container.regressSelection(slot);
|
||||
regressSelection(slot);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,4 +119,16 @@ public class GuiImprinter extends GuiForestry<ContainerImprinter, ImprinterInven
|
||||
startX = (this.width - this.xSize) / 2;
|
||||
startY = (this.height - this.ySize) / 2;
|
||||
}
|
||||
|
||||
private static void advanceSelection(int index) {
|
||||
sendSelectionChange(index, 0);
|
||||
}
|
||||
|
||||
private static void regressSelection(int index) {
|
||||
sendSelectionChange(index, 1);
|
||||
}
|
||||
|
||||
private static void sendSelectionChange(int index, int advance) {
|
||||
Proxies.net.sendToServer(new PacketGuiSelectRequest(index, advance));
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* 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.apiculture.network;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
import forestry.apiculture.gui.ContainerImprinter;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.IForestryPacketServer;
|
||||
import forestry.core.network.PacketIdServer;
|
||||
|
||||
public class PacketImprintSelectionRequest extends ForestryPacket implements IForestryPacketServer {
|
||||
|
||||
public PacketImprintSelectionRequest() {
|
||||
super(PacketIdServer.IMPRINT_SELECTION_REQUEST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketData(DataInputStreamForestry data, EntityPlayerMP player) throws IOException {
|
||||
if (!(player.openContainer instanceof ContainerImprinter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
((ContainerImprinter) player.openContainer).sendSelection(player);
|
||||
}
|
||||
}
|
||||
@@ -42,9 +42,6 @@ public class PacketHandler {
|
||||
|
||||
try {
|
||||
byte packetIdOrdinal = data.readByte();
|
||||
if (packetIdOrdinal >= PacketIdClient.VALUES.length) {
|
||||
return;
|
||||
}
|
||||
PacketIdServer packetId = PacketIdServer.VALUES[packetIdOrdinal];
|
||||
IForestryPacketServer packetHandler = packetId.getPacketHandler();
|
||||
packetHandler.readData(data);
|
||||
@@ -61,9 +58,6 @@ public class PacketHandler {
|
||||
|
||||
try {
|
||||
byte packetIdOrdinal = data.readByte();
|
||||
if (packetIdOrdinal >= PacketIdClient.VALUES.length) {
|
||||
return;
|
||||
}
|
||||
PacketIdClient packetId = PacketIdClient.VALUES[packetIdOrdinal];
|
||||
IForestryPacketClient packetHandler = packetId.getPacketHandler();
|
||||
packetHandler.readData(data);
|
||||
|
||||
@@ -22,9 +22,6 @@ public enum PacketIdServer implements IPacketId {
|
||||
CHIPSET_CLICK(new PacketChipsetClick()),
|
||||
SOLDERING_IRON_CLICK(new PacketSolderingIronClick()),
|
||||
|
||||
// Apiculture
|
||||
IMPRINT_SELECTION_REQUEST,
|
||||
|
||||
// Factory
|
||||
WORKTABLE_NEI_SELECT,
|
||||
|
||||
|
||||
@@ -626,7 +626,7 @@ public abstract class InventoryUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void dropInventory(IInventory inventory, World world, int x, int y, int z) {
|
||||
public static void dropInventory(IInventory inventory, World world, double x, double y, double z) {
|
||||
if (inventory == null) {
|
||||
return;
|
||||
}
|
||||
@@ -639,7 +639,7 @@ public abstract class InventoryUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void dropSockets(ISocketable socketable, World world, int x, int y, int z) {
|
||||
public static void dropSockets(ISocketable socketable, World world, double x, double y, double z) {
|
||||
for (int slot = 0; slot < socketable.getSocketCount(); slot++) {
|
||||
ItemStack itemstack = socketable.getSocket(slot);
|
||||
dropItemStackFromInventory(itemstack, world, x, y, z);
|
||||
@@ -647,7 +647,7 @@ public abstract class InventoryUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void dropItemStackFromInventory(ItemStack itemStack, World world, int x, int y, int z) {
|
||||
public static void dropItemStackFromInventory(ItemStack itemStack, World world, double x, double y, double z) {
|
||||
if (itemStack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -12,12 +12,11 @@ package forestry.food.gui;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.core.gui.ContainerItemInventory;
|
||||
import forestry.core.gui.slots.SlotFiltered;
|
||||
import forestry.core.gui.slots.SlotOutput;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
import forestry.food.items.ItemInfuser.InfuserInventory;
|
||||
|
||||
public class ContainerInfuser extends ContainerItemInventory<InfuserInventory> {
|
||||
@@ -40,20 +39,10 @@ public class ContainerInfuser extends ContainerItemInventory<InfuserInventory> {
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(EntityPlayer entityplayer) {
|
||||
|
||||
if (entityplayer.worldObj.isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Drop everything still in there.
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++) {
|
||||
ItemStack stack = inventory.getStackInSlot(i);
|
||||
if (stack == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Proxies.common.dropItemPlayer(entityplayer, stack);
|
||||
inventory.setInventorySlotContents(i, null);
|
||||
}
|
||||
InventoryUtil.dropInventory(inventory, entityplayer.worldObj, entityplayer.posX, entityplayer.posY, entityplayer.posZ);
|
||||
}
|
||||
}
|
||||
@@ -120,7 +120,6 @@ import forestry.apiculture.network.PacketActiveUpdate;
|
||||
import forestry.apiculture.network.PacketBeekeepingLogicActive;
|
||||
import forestry.apiculture.network.PacketCandleUpdate;
|
||||
import forestry.apiculture.network.PacketHabitatBiomePointer;
|
||||
import forestry.apiculture.network.PacketImprintSelectionRequest;
|
||||
import forestry.apiculture.network.PacketImprintSelectionResponse;
|
||||
import forestry.apiculture.proxy.ProxyApiculture;
|
||||
import forestry.apiculture.tiles.TileApiaristChest;
|
||||
@@ -150,7 +149,6 @@ import forestry.core.items.ItemOverlay;
|
||||
import forestry.core.items.ItemOverlay.OverlayInfo;
|
||||
import forestry.core.items.ItemScoop;
|
||||
import forestry.core.network.PacketIdClient;
|
||||
import forestry.core.network.PacketIdServer;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.recipes.ShapedRecipeCustom;
|
||||
import forestry.core.tiles.MachineDefinition;
|
||||
@@ -501,8 +499,6 @@ public class PluginApiculture extends ForestryPlugin {
|
||||
|
||||
@Override
|
||||
public void registerPacketHandlers() {
|
||||
PacketIdServer.IMPRINT_SELECTION_REQUEST.setPacketHandler(new PacketImprintSelectionRequest());
|
||||
|
||||
PacketIdClient.IMPRINT_SELECTION_RESPONSE.setPacketHandler(new PacketImprintSelectionResponse());
|
||||
PacketIdClient.TILE_FORESTRY_ACTIVE.setPacketHandler(new PacketActiveUpdate());
|
||||
PacketIdClient.BEE_LOGIC_ACTIVE.setPacketHandler(new PacketBeekeepingLogicActive());
|
||||
|
||||
Reference in new issue
Block a user