mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-23 21:39:51 +00:00
Fix network sync of item floating over Escritoire
This commit is contained in:
1 parent
8617c4a79f
commit
9f5f5e7812
4 files changed
+51
-8
No files matched your search
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.network.packets;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -30,8 +31,8 @@ public class PacketItemStackDisplay extends PacketCoordinates implements IForest
|
||||
|
||||
public PacketItemStackDisplay() {
|
||||
}
|
||||
|
||||
public <T extends TileForestry & IItemStackDisplay> PacketItemStackDisplay(T tile, ItemStack itemStack) {
|
||||
|
||||
public <T extends TileForestry & IItemStackDisplay> PacketItemStackDisplay(T tile, @Nullable ItemStack itemStack) {
|
||||
super(tile);
|
||||
this.itemStack = itemStack;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import net.minecraft.world.World;
|
||||
|
||||
import forestry.core.blocks.BlockBase;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.inventory.InventoryEscritoire;
|
||||
import forestry.core.models.ModelEscritoire;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.tiles.TileEscritoire;
|
||||
@@ -46,7 +45,7 @@ public class RenderEscritoire extends TileEntitySpecialRenderer<TileEscritoire>
|
||||
IBlockState blockState = world.getBlockState(escritoire.getPos());
|
||||
if (blockState != null && blockState.getBlock() instanceof BlockBase) {
|
||||
EnumFacing facing = blockState.getValue(BlockBase.FACING);
|
||||
render(escritoire.getStackInSlot(InventoryEscritoire.SLOT_ANALYZE), world, facing, x, y, z);
|
||||
render(escritoire.getIndividualOnDisplay(), world, facing, x, y, z);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,16 +25,20 @@ import forestry.api.genetics.IAlleleSpecies;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.core.gui.ContainerEscritoire;
|
||||
import forestry.core.gui.GuiEscritoire;
|
||||
import forestry.core.inventory.InventoryAnalyzer;
|
||||
import forestry.core.inventory.InventoryEscritoire;
|
||||
import forestry.core.inventory.watchers.ISlotPickupWatcher;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IStreamableGui;
|
||||
import forestry.core.network.packets.PacketItemStackDisplay;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
|
||||
public class TileEscritoire extends TileBase implements ISidedInventory, ISlotPickupWatcher, IStreamableGui {
|
||||
public class TileEscritoire extends TileBase implements ISidedInventory, ISlotPickupWatcher, IStreamableGui, IItemStackDisplay {
|
||||
|
||||
private final EscritoireGame game = new EscritoireGame();
|
||||
private ItemStack individualOnDisplayClient;
|
||||
|
||||
public TileEscritoire() {
|
||||
super("escritoire");
|
||||
@@ -116,15 +120,39 @@ public class TileEscritoire extends TileBase implements ISidedInventory, ISlotPi
|
||||
public void readGuiData(DataInputStreamForestry data) throws IOException {
|
||||
game.readData(data);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
super.writeData(data);
|
||||
ItemStack displayStack = getIndividualOnDisplay();
|
||||
data.writeItemStack(displayStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
super.readData(data);
|
||||
individualOnDisplayClient = data.readItemStack();
|
||||
}
|
||||
|
||||
/* ISlotPickupWatcher */
|
||||
@Override
|
||||
public void onPickupFromSlot(int slotIndex, EntityPlayer player) {
|
||||
if (slotIndex == InventoryEscritoire.SLOT_ANALYZE) {
|
||||
game.reset();
|
||||
PacketItemStackDisplay packet = new PacketItemStackDisplay(this, getIndividualOnDisplay());
|
||||
Proxies.net.sendNetworkPacket(packet, worldObj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slotIndex, ItemStack itemstack) {
|
||||
super.setInventorySlotContents(slotIndex, itemstack);
|
||||
if (slotIndex == InventoryEscritoire.SLOT_ANALYZE) {
|
||||
PacketItemStackDisplay packet = new PacketItemStackDisplay(this, getIndividualOnDisplay());
|
||||
Proxies.net.sendNetworkPacket(packet, worldObj);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getGui(EntityPlayer player, int data) {
|
||||
return new GuiEscritoire(player, this);
|
||||
@@ -134,4 +162,19 @@ public class TileEscritoire extends TileBase implements ISidedInventory, ISlotPi
|
||||
public Object getContainer(EntityPlayer player, int data) {
|
||||
return new ContainerEscritoire(player, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItemStackForDisplay(ItemStack itemStack) {
|
||||
if (!ItemStack.areItemStacksEqual(itemStack, individualOnDisplayClient)) {
|
||||
individualOnDisplayClient = itemStack;
|
||||
worldObj.markBlockRangeForRenderUpdate(getPos(), getPos());
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack getIndividualOnDisplay() {
|
||||
if (worldObj.isRemote) {
|
||||
return individualOnDisplayClient;
|
||||
}
|
||||
return getStackInSlot(InventoryAnalyzer.SLOT_ANALYZE);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user