mirror of
https://github.com/GTNewHorizons/StorageDrawers.git
synced 2026-11-21 04:32:37 +00:00
Fix client controller not connecting with ExU pipes; Fix controller connected block sync issue.
This commit is contained in:
1 parent
b42b105fcf
commit
01a0065490
11 files changed
+183
-8
No files matched your search
Binary file not shown.
|
Before Width: | Height: | Size: 575 B After Width: | Height: | Size: 577 B |
@@ -7,6 +7,7 @@ import com.jaquadro.minecraft.storagedrawers.config.RecipeHandlerRegistry;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.*;
|
||||
import com.jaquadro.minecraft.storagedrawers.integration.IntegrationRegistry;
|
||||
import com.jaquadro.minecraft.storagedrawers.network.BlockClickMessage;
|
||||
import com.jaquadro.minecraft.storagedrawers.network.ControllerUpdateMessage;
|
||||
import com.jaquadro.minecraft.storagedrawers.network.CountUpdateMessage;
|
||||
import cpw.mods.fml.client.event.ConfigChangedEvent;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
@@ -56,10 +57,14 @@ public class StorageDrawers
|
||||
network = NetworkRegistry.INSTANCE.newSimpleChannel(MOD_ID);
|
||||
network.registerMessage(BlockClickMessage.Handler.class, BlockClickMessage.class, 0, Side.SERVER);
|
||||
|
||||
if (FMLCommonHandler.instance().getSide() == Side.CLIENT)
|
||||
if (FMLCommonHandler.instance().getSide() == Side.CLIENT) {
|
||||
network.registerMessage(CountUpdateMessage.Handler.class, CountUpdateMessage.class, 1, Side.CLIENT);
|
||||
else
|
||||
network.registerMessage(ControllerUpdateMessage.Handler.class, ControllerUpdateMessage.class, 2, Side.CLIENT);
|
||||
}
|
||||
else {
|
||||
network.registerMessage(CountUpdateMessage.HandlerStub.class, CountUpdateMessage.class, 1, Side.CLIENT);
|
||||
network.registerMessage(ControllerUpdateMessage.HandlerStub.class, ControllerUpdateMessage.class, 2, Side.CLIENT);
|
||||
}
|
||||
|
||||
compRegistry = new CompTierRegistry();
|
||||
oreDictRegistry = new OreDictRegistry();
|
||||
|
||||
@@ -30,4 +30,6 @@ public interface IDrawerInventory extends ISidedInventory
|
||||
boolean canInsertItem (int slot, ItemStack stack);
|
||||
|
||||
boolean canExtractItem (int slot, ItemStack stack);
|
||||
|
||||
boolean syncInventoryIfNeeded ();
|
||||
}
|
||||
@@ -7,4 +7,6 @@ public interface IInventoryAdapter
|
||||
ItemStack getInventoryStack (SlotType slotType);
|
||||
|
||||
void syncInventory ();
|
||||
|
||||
boolean syncInventoryIfNeeded ();
|
||||
}
|
||||
@@ -20,4 +20,6 @@ public interface IDrawerGroup
|
||||
boolean isDrawerEnabled (int slot);
|
||||
|
||||
IDrawerInventory getDrawerInventory ();
|
||||
|
||||
boolean markDirtyIfNeeded ();
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.block.tile;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.inventory.IDrawerInventory;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroupInteractive;
|
||||
import com.jaquadro.minecraft.storagedrawers.network.ControllerUpdateMessage;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -65,7 +69,6 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IS
|
||||
private int[] autoSides = new int[] { 0, 1 };
|
||||
private int direction;
|
||||
|
||||
private int inventorySize = 0;
|
||||
private int drawerSize = 0;
|
||||
|
||||
private long lastClickTime;
|
||||
@@ -87,7 +90,7 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IS
|
||||
}
|
||||
|
||||
public int interactPutItemsIntoInventory (EntityPlayer player) {
|
||||
if (inventorySize == 0)
|
||||
if (inventorySlots.length == 0)
|
||||
updateCache();
|
||||
|
||||
boolean dumpInventory = worldObj.getTotalWorldTime() - lastClickTime < 10 && player.getPersistentID().equals(lastClickUUID);
|
||||
@@ -128,7 +131,6 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IS
|
||||
invSlotList.clear();
|
||||
drawerBlockList.clear();
|
||||
drawerSlotList.clear();
|
||||
inventorySize = 0;
|
||||
drawerSize = 0;
|
||||
}
|
||||
|
||||
@@ -172,6 +174,9 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IS
|
||||
if (invBlockList.get(i) != null)
|
||||
inventorySlots[j++] = i;
|
||||
}
|
||||
|
||||
if (!worldObj.isRemote)
|
||||
syncClient();
|
||||
}
|
||||
|
||||
private void populateNode (int x, int y, int z, int depth) {
|
||||
@@ -216,7 +221,6 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IS
|
||||
drawerSlotList.add(i);
|
||||
}
|
||||
|
||||
inventorySize += invStorageSize.get(coord);
|
||||
drawerSize += drawerStorageSize.get(coord);
|
||||
|
||||
if (depth == DEPTH_LIMIT)
|
||||
@@ -315,6 +319,17 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IS
|
||||
getWorldObj().func_147479_m(xCoord, yCoord, zCoord); // markBlockForRenderUpdate
|
||||
}
|
||||
|
||||
private void syncClient () {
|
||||
IMessage message = new ControllerUpdateMessage(xCoord, yCoord, zCoord, inventorySlots);
|
||||
NetworkRegistry.TargetPoint targetPoint = new NetworkRegistry.TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 500);
|
||||
|
||||
StorageDrawers.network.sendToAllAround(message, targetPoint);
|
||||
}
|
||||
|
||||
public void clientUpdate (int[] inventorySlots) {
|
||||
this.inventorySlots = inventorySlots;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDrawerInventory getDrawerInventory () {
|
||||
return null;
|
||||
@@ -322,7 +337,7 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IS
|
||||
|
||||
@Override
|
||||
public int getDrawerCount () {
|
||||
if (inventorySize == 0)
|
||||
if (inventorySlots.length == 0)
|
||||
updateCache();
|
||||
|
||||
return drawerSlotList.size();
|
||||
@@ -346,6 +361,31 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IS
|
||||
return group.isDrawerEnabled(getDrawerSlotForGroup(slot));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty () {
|
||||
for (IDrawerGroup group : storage.values()) {
|
||||
if (group != null && group.getDrawerInventory() != null)
|
||||
group.markDirtyIfNeeded();
|
||||
}
|
||||
|
||||
super.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean markDirtyIfNeeded () {
|
||||
boolean synced = false;
|
||||
|
||||
for (IDrawerGroup group : storage.values()) {
|
||||
if (group != null && group.getDrawerInventory() != null)
|
||||
synced |= group.markDirtyIfNeeded();
|
||||
}
|
||||
|
||||
if (synced)
|
||||
super.markDirty();
|
||||
|
||||
return synced;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide (int side) {
|
||||
for (int aside : autoSides) {
|
||||
@@ -376,7 +416,7 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IS
|
||||
|
||||
@Override
|
||||
public int getSizeInventory () {
|
||||
return inventorySize;
|
||||
return inventorySlots.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -413,6 +453,7 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IS
|
||||
return;
|
||||
|
||||
inventory.setInventorySlotContents(getDrawerSlotForInv(slot), stack);
|
||||
inventory.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -309,6 +309,16 @@ public abstract class TileEntityDrawers extends TileEntity implements IDrawerGro
|
||||
super.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean markDirtyIfNeeded () {
|
||||
if (inventory.syncInventoryIfNeeded()) {
|
||||
super.markDirty();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void clientUpdateCount (int slot, int count) {
|
||||
IDrawer drawer = getDrawer(slot);
|
||||
if (drawer.getStoredItemCount() != count) {
|
||||
|
||||
@@ -50,6 +50,17 @@ public abstract class InventoryStack
|
||||
refresh();
|
||||
}
|
||||
|
||||
public boolean markDirtyIfNeeded () {
|
||||
int diff = getDiff();
|
||||
if (diff != 0) {
|
||||
applyDiff(diff);
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getDiff () {
|
||||
if (nativeStack == null)
|
||||
return 0;
|
||||
|
||||
@@ -268,6 +268,22 @@ public class StorageInventory implements IDrawerInventory
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean syncInventoryIfNeeded () {
|
||||
boolean synced = false;
|
||||
|
||||
for (int i = 0, n = group.getDrawerCount(); i < n; i++) {
|
||||
if (!group.isDrawerEnabled(i))
|
||||
continue;
|
||||
|
||||
IDrawer drawer = group.getDrawer(i);
|
||||
if (drawer instanceof IInventoryAdapter)
|
||||
synced |= ((IInventoryAdapter) drawer).syncInventoryIfNeeded();
|
||||
}
|
||||
|
||||
return synced;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer (EntityPlayer player) {
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.network;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityController;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
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 cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
public class ControllerUpdateMessage implements IMessage
|
||||
{
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
private int[] inventorySlots;
|
||||
|
||||
public ControllerUpdateMessage () { }
|
||||
|
||||
public ControllerUpdateMessage (int x, int y, int z, int[] inventorySlots) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.inventorySlots = inventorySlots;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes (ByteBuf buf) {
|
||||
x = buf.readInt();
|
||||
y = buf.readShort();
|
||||
z = buf.readInt();
|
||||
|
||||
int count = buf.readShort();
|
||||
inventorySlots = new int[count];
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
inventorySlots[i] = buf.readShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes (ByteBuf buf) {
|
||||
buf.writeInt(x);
|
||||
buf.writeShort(y);
|
||||
buf.writeInt(z);
|
||||
|
||||
buf.writeShort(inventorySlots.length);
|
||||
for (int i = 0; i < inventorySlots.length; i++)
|
||||
buf.writeShort(inventorySlots[i]);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static class Handler implements IMessageHandler<ControllerUpdateMessage, IMessage>
|
||||
{
|
||||
@Override
|
||||
public IMessage onMessage (ControllerUpdateMessage message, MessageContext ctx) {
|
||||
if (ctx.side == Side.CLIENT) {
|
||||
World world = Minecraft.getMinecraft().theWorld;
|
||||
TileEntity tileEntity = world.getTileEntity(message.x, message.y, message.z);
|
||||
if (tileEntity instanceof TileEntityController) {
|
||||
((TileEntityController) tileEntity).clientUpdate(message.inventorySlots);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class HandlerStub implements IMessageHandler<ControllerUpdateMessage, IMessage>
|
||||
{
|
||||
@Override
|
||||
public IMessage onMessage (ControllerUpdateMessage message, MessageContext ctx) {
|
||||
FMLLog.log(StorageDrawers.MOD_ID, Level.WARN, "ControllerUpdateMessage stub handler called.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,6 +85,10 @@ public abstract class BaseDrawerData implements IDrawer, IInventoryAdapter
|
||||
inventoryStack.markDirty();
|
||||
}
|
||||
|
||||
public boolean syncInventoryIfNeeded () {
|
||||
return inventoryStack.markDirtyIfNeeded();
|
||||
}
|
||||
|
||||
public static boolean areItemsEqual (ItemStack stack1, ItemStack stack2) {
|
||||
if (stack1 == null || stack2 == null)
|
||||
return false;
|
||||
|
||||
Reference in new issue
Block a user