mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-18 11:19:23 +00:00
add gzip support
fix terminal sometime drop network packet
This commit is contained in:
1 parent
8331159519
commit
6b7c53879a
13 files changed
+168
-297
No files matched your search
@@ -13,7 +13,6 @@ import com.glodblock.github.loader.ChannelLoader;
|
||||
import com.glodblock.github.loader.ItemAndBlockHolder;
|
||||
import com.glodblock.github.loader.RecipeLoader;
|
||||
import com.glodblock.github.loader.filter.FluidFilter;
|
||||
import com.glodblock.github.network.SPacketMEUpdateBuffer;
|
||||
import com.glodblock.github.proxy.CommonProxy;
|
||||
import com.glodblock.github.util.ModAndClassUtil;
|
||||
|
||||
@@ -25,8 +24,6 @@ import cpw.mods.fml.common.event.FMLLoadCompleteEvent;
|
||||
import cpw.mods.fml.common.event.FMLMissingMappingsEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerStartingEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerStoppedEvent;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
|
||||
@Mod(
|
||||
@@ -96,16 +93,6 @@ public class FluidCraft {
|
||||
proxy.onLoadComplete(event);
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onServerStart(FMLServerStartingEvent event) {
|
||||
SPacketMEUpdateBuffer.init();
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onServerStop(FMLServerStoppedEvent event) {
|
||||
SPacketMEUpdateBuffer.disable();
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void missingMappings(FMLMissingMappingsEvent event) {
|
||||
if (!ModAndClassUtil.EC2 && Config.replaceEC2) {
|
||||
|
||||
@@ -27,15 +27,13 @@ public class GuiFluidMonitor extends FCGuiMonitor<IAEFluidStack> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postUpdate(final List<IAEFluidStack> list, boolean resort) {
|
||||
public void postUpdate(final List<IAEFluidStack> list) {
|
||||
for (final IAEFluidStack is : list) {
|
||||
IAEItemStack stack = AEItemStack.create(ItemFluidDrop.newDisplayStack(is.getFluidStack()));
|
||||
stack.setStackSize(is.getStackSize());
|
||||
this.repo.postUpdate(stack);
|
||||
}
|
||||
if (resort) {
|
||||
this.repo.updateView();
|
||||
}
|
||||
this.repo.updateView();
|
||||
this.setScrollBar();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,13 +23,11 @@ public class GuiItemMonitor extends FCGuiMonitor<IAEItemStack> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postUpdate(final List<IAEItemStack> list, boolean resort) {
|
||||
public void postUpdate(final List<IAEItemStack> list) {
|
||||
for (final IAEItemStack is : list) {
|
||||
this.repo.postUpdate(is);
|
||||
}
|
||||
if (resort) {
|
||||
this.repo.updateView();
|
||||
}
|
||||
this.repo.updateView();
|
||||
this.setScrollBar();
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
|
||||
offsetY = y;
|
||||
}
|
||||
|
||||
public abstract void postUpdate(final List<T> list, boolean resort);
|
||||
public abstract void postUpdate(final List<T> list);
|
||||
|
||||
protected void setScrollBar() {
|
||||
this.getScrollBar().setTop(18).setLeft(175).setHeight(this.rows * 18 - 2);
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.glodblock.github.client.gui.container.base.FCContainerMonitor;
|
||||
import com.glodblock.github.common.item.ItemFluidPacket;
|
||||
import com.glodblock.github.network.CPacketFluidUpdate;
|
||||
import com.glodblock.github.network.SPacketFluidUpdate;
|
||||
import com.glodblock.github.network.SPacketMEUpdateBuffer;
|
||||
import com.glodblock.github.network.SPacketMEFluidInvUpdate;
|
||||
import com.glodblock.github.util.Util;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
@@ -143,9 +143,11 @@ public class ContainerFluidMonitor extends FCContainerMonitor<IAEFluidStack> {
|
||||
toSend.add(is);
|
||||
}
|
||||
}
|
||||
SPacketMEFluidInvUpdate piu = new SPacketMEFluidInvUpdate();
|
||||
piu.addAll(toSend);
|
||||
for (final Object c : this.crafters) {
|
||||
if (c instanceof EntityPlayerMP) {
|
||||
SPacketMEUpdateBuffer.scheduleFluidUpdate((EntityPlayerMP) c, toSend);
|
||||
FluidCraft.proxy.netHandler.sendTo(piu, (EntityPlayerMP) c);
|
||||
}
|
||||
}
|
||||
this.fluids.resetStatus();
|
||||
@@ -160,7 +162,9 @@ public class ContainerFluidMonitor extends FCContainerMonitor<IAEFluidStack> {
|
||||
for (final IAEFluidStack is : monitorCache) {
|
||||
toSend.add(is);
|
||||
}
|
||||
SPacketMEUpdateBuffer.scheduleFluidUpdate((EntityPlayerMP) c, toSend);
|
||||
SPacketMEFluidInvUpdate piu = new SPacketMEFluidInvUpdate();
|
||||
piu.addAll(toSend);
|
||||
FluidCraft.proxy.netHandler.sendTo(piu, (EntityPlayerMP) c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,9 @@ import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.client.gui.container.base.FCContainerMonitor;
|
||||
import com.glodblock.github.network.SPacketMEUpdateBuffer;
|
||||
import com.glodblock.github.network.SPacketMEItemInvUpdate;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.implementations.tiles.IViewCellStorage;
|
||||
@@ -105,9 +106,11 @@ public class ContainerItemMonitor extends FCContainerMonitor<IAEItemStack> {
|
||||
toSend.add(is);
|
||||
}
|
||||
}
|
||||
SPacketMEItemInvUpdate piu = new SPacketMEItemInvUpdate();
|
||||
piu.addAll(toSend);
|
||||
for (final Object c : this.crafters) {
|
||||
if (c instanceof EntityPlayer) {
|
||||
SPacketMEUpdateBuffer.scheduleItemUpdate((EntityPlayerMP) c, toSend);
|
||||
FluidCraft.proxy.netHandler.sendTo(piu, (EntityPlayerMP) c);
|
||||
}
|
||||
}
|
||||
this.items.resetStatus();
|
||||
@@ -122,7 +125,9 @@ public class ContainerItemMonitor extends FCContainerMonitor<IAEItemStack> {
|
||||
for (final IAEItemStack is : monitorCache) {
|
||||
toSend.add(is);
|
||||
}
|
||||
SPacketMEUpdateBuffer.scheduleItemUpdate((EntityPlayerMP) c, toSend);
|
||||
SPacketMEItemInvUpdate piu = new SPacketMEItemInvUpdate();
|
||||
piu.addAll(toSend);
|
||||
FluidCraft.proxy.netHandler.sendTo(piu, (EntityPlayerMP) c);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,9 +136,6 @@ public class ContainerItemMonitor extends FCContainerMonitor<IAEItemStack> {
|
||||
super.removeCraftingFromCrafters(c);
|
||||
if (this.crafters.isEmpty() && this.monitor != null) {
|
||||
this.monitor.removeListener(this);
|
||||
if (c instanceof EntityPlayerMP) {
|
||||
SPacketMEUpdateBuffer.clear((EntityPlayerMP) c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.glodblock.github.inventory.item.IWirelessTerminal;
|
||||
import com.glodblock.github.network.SPacketMEUpdateBuffer;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
@@ -170,10 +169,6 @@ public abstract class FCContainerMonitor<T extends IAEStack<T>> extends FCBaseCo
|
||||
super.onContainerClosed(player);
|
||||
if (this.monitor != null) {
|
||||
this.monitor.removeListener(this);
|
||||
if (player instanceof EntityPlayerMP && Platform.isServer()) {
|
||||
SPacketMEUpdateBuffer.clear((EntityPlayerMP) player);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.client.gui.container.ContainerLevelMaintainer;
|
||||
import com.glodblock.github.common.tile.TileLevelMaintainer;
|
||||
|
||||
@@ -112,7 +113,9 @@ public class CPacketLevelMaintainer implements IMessage {
|
||||
case Refresh -> this.refresh(clm);
|
||||
};
|
||||
|
||||
SPacketMEUpdateBuffer.scheduleItemUpdate(player, toSend);
|
||||
SPacketMEItemInvUpdate piu = new SPacketMEItemInvUpdate();
|
||||
piu.addAll(toSend);
|
||||
FluidCraft.proxy.netHandler.sendTo(piu, player);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.BufferOverflowException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.util.item.AEFluidStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
public abstract class SPacketMEBaseInvUpdate implements IMessage {
|
||||
|
||||
protected static final int UNCOMPRESSED_PACKET_BYTE_LIMIT = 16 * 1024 * 1024;
|
||||
protected static final int OPERATION_BYTE_LIMIT = 2 * 1024;
|
||||
protected static final int TEMP_BUFFER_SIZE = 1024;
|
||||
protected static final int STREAM_MASK = 0xff;
|
||||
@Nullable
|
||||
protected GZIPOutputStream compressFrame;
|
||||
protected int writtenBytes = 0;
|
||||
protected final ByteBuf data = Unpooled.buffer(OPERATION_BYTE_LIMIT);
|
||||
protected byte ref = (byte) 0;
|
||||
protected final List<IAEStack<?>> list = new ArrayList<>();
|
||||
|
||||
public SPacketMEBaseInvUpdate() {}
|
||||
|
||||
public SPacketMEBaseInvUpdate(byte b) {
|
||||
setRef(b);
|
||||
}
|
||||
|
||||
protected void compress() throws IOException, BufferOverflowException {
|
||||
for (IAEStack<?> is : getList()) {
|
||||
final ByteBuf tmp = Unpooled.buffer(OPERATION_BYTE_LIMIT);
|
||||
is.writeToPacket(tmp);
|
||||
assert this.compressFrame != null;
|
||||
this.compressFrame.flush();
|
||||
if (this.writtenBytes + tmp.readableBytes() > UNCOMPRESSED_PACKET_BYTE_LIMIT) {
|
||||
throw new BufferOverflowException();
|
||||
} else {
|
||||
this.writtenBytes += tmp.readableBytes();
|
||||
this.compressFrame.write(tmp.array(), 0, tmp.readableBytes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeByte(getRef());
|
||||
try {
|
||||
this.compressFrame = new GZIPOutputStream(new OutputStream() {
|
||||
|
||||
@Override
|
||||
public void write(final int value) {
|
||||
SPacketMEBaseInvUpdate.this.data.writeByte(value);
|
||||
}
|
||||
});
|
||||
compress();
|
||||
this.compressFrame.finish();
|
||||
buf.writeBytes(this.data);
|
||||
this.compressFrame.close();
|
||||
} catch (IOException io) {
|
||||
io.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
ref = buf.readByte();
|
||||
try {
|
||||
final GZIPInputStream gzReader = new GZIPInputStream(new InputStream() {
|
||||
|
||||
@Override
|
||||
public int read() {
|
||||
if (buf.readableBytes() <= 0) {
|
||||
return -1;
|
||||
}
|
||||
return buf.readByte() & STREAM_MASK;
|
||||
}
|
||||
});
|
||||
final ByteBuf uncompressed = Unpooled.buffer(buf.readableBytes());
|
||||
final byte[] tmp = new byte[TEMP_BUFFER_SIZE];
|
||||
while (gzReader.available() != 0) {
|
||||
final int bytes = gzReader.read(tmp);
|
||||
if (bytes > 0) {
|
||||
uncompressed.writeBytes(tmp, 0, bytes);
|
||||
}
|
||||
}
|
||||
gzReader.close();
|
||||
while (uncompressed.readableBytes() > 0) {
|
||||
if (this instanceof SPacketMEItemInvUpdate) {
|
||||
this.getList().add(AEItemStack.loadItemStackFromPacket(uncompressed));
|
||||
} else {
|
||||
this.getList().add(AEFluidStack.loadFluidStackFromPacket(uncompressed));
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.list.isEmpty();
|
||||
}
|
||||
|
||||
public List<IAEStack<?>> getList() {
|
||||
return this.list;
|
||||
}
|
||||
|
||||
public byte getRef() {
|
||||
return this.ref;
|
||||
}
|
||||
|
||||
public void setRef(byte ref) {
|
||||
this.ref = ref;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -11,80 +9,23 @@ import com.glodblock.github.client.gui.GuiFluidCraftConfirm;
|
||||
import com.glodblock.github.client.gui.GuiFluidMonitor;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.util.item.AEFluidStack;
|
||||
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 io.netty.buffer.ByteBuf;
|
||||
|
||||
/**
|
||||
* Dedicated packet for fluid updates.
|
||||
*/
|
||||
public class SPacketMEFluidInvUpdate implements IMessage {
|
||||
|
||||
private List<IAEFluidStack> list = new ArrayList<>();
|
||||
private byte ref = (byte) 0;
|
||||
private boolean resort = true;
|
||||
public class SPacketMEFluidInvUpdate extends SPacketMEBaseInvUpdate implements IMessage {
|
||||
|
||||
public SPacketMEFluidInvUpdate() {}
|
||||
|
||||
/**
|
||||
* Used for the GUI to confirm crafting. 0 = available 1 = pending 2 = missing
|
||||
*/
|
||||
public SPacketMEFluidInvUpdate(byte b) {
|
||||
ref = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* If resort, call "updateView()". Used when multiple packets are sent to open an inventory; only the last packet
|
||||
* should resort
|
||||
*
|
||||
* @param resort whether this packet should resort the term or not
|
||||
*/
|
||||
public SPacketMEFluidInvUpdate(boolean resort) {
|
||||
this.resort = resort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
ref = buf.readByte();
|
||||
resort = buf.readBoolean();
|
||||
int amount = buf.readInt();
|
||||
list = new ArrayList<>(amount);
|
||||
try {
|
||||
for (int i = 0; i < amount; i++) {
|
||||
list.add(AEFluidStack.loadFluidStackFromPacket(buf));
|
||||
}
|
||||
} catch (Exception io) {
|
||||
System.out.println("Error handling payload w/ " + amount + " items.");
|
||||
io.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeByte(ref);
|
||||
buf.writeBoolean(resort);
|
||||
buf.writeInt(list.size());
|
||||
try {
|
||||
for (IAEFluidStack is : list) {
|
||||
is.writeToPacket(buf);
|
||||
}
|
||||
} catch (IOException io) {
|
||||
io.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setResort(boolean resort) {
|
||||
this.resort = resort;
|
||||
public void addAll(final List<IAEFluidStack> list) {
|
||||
this.list.addAll(list);
|
||||
}
|
||||
|
||||
public void appendFluid(final IAEFluidStack is) {
|
||||
list.add(is);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.list.isEmpty();
|
||||
this.list.add(is);
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<SPacketMEFluidInvUpdate, IMessage> {
|
||||
@@ -94,7 +35,7 @@ public class SPacketMEFluidInvUpdate implements IMessage {
|
||||
public IMessage onMessage(SPacketMEFluidInvUpdate message, MessageContext ctx) {
|
||||
final GuiScreen gs = Minecraft.getMinecraft().currentScreen;
|
||||
if (gs instanceof GuiFluidMonitor) {
|
||||
((GuiFluidMonitor) gs).postUpdate(message.list, message.resort);
|
||||
((GuiFluidMonitor) gs).postUpdate((List) message.list);
|
||||
} else if (gs instanceof GuiFluidCraftConfirm) {
|
||||
((GuiFluidCraftConfirm) gs).postUpdate((List) message.list, message.ref);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -13,96 +11,49 @@ import com.glodblock.github.client.gui.GuiLevelMaintainer;
|
||||
import com.glodblock.github.proxy.ClientProxy;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
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 io.netty.buffer.ByteBuf;
|
||||
|
||||
/**
|
||||
* Packet dedicated to item inventory update.
|
||||
*/
|
||||
public class SPacketMEItemInvUpdate implements IMessage {
|
||||
public class SPacketMEItemInvUpdate extends SPacketMEBaseInvUpdate implements IMessage {
|
||||
|
||||
private List<IAEItemStack> list = new ArrayList<>();
|
||||
private byte ref = (byte) 0;
|
||||
private boolean resort = true;
|
||||
|
||||
public SPacketMEItemInvUpdate() {}
|
||||
public SPacketMEItemInvUpdate() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for the GUI to confirm crafting. 0 = available 1 = pending 2 = missing
|
||||
*/
|
||||
public SPacketMEItemInvUpdate(byte b) {
|
||||
ref = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* If resort, call "updateView()". Used when multiple packets are sent to open an inventory; only the last packet
|
||||
* should resort.
|
||||
*
|
||||
* @param resort whether this packet should resort the term or not
|
||||
*/
|
||||
public SPacketMEItemInvUpdate(boolean resort) {
|
||||
this.resort = resort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
ref = buf.readByte();
|
||||
resort = buf.readBoolean();
|
||||
int amount = buf.readInt();
|
||||
list = new ArrayList<>(amount);
|
||||
try {
|
||||
for (int i = 0; i < amount; i++) {
|
||||
list.add(AEItemStack.loadItemStackFromPacket(buf));
|
||||
}
|
||||
} catch (Exception io) {
|
||||
System.out.println("Error handling payload w/ " + amount + " items.");
|
||||
io.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeByte(ref);
|
||||
buf.writeBoolean(resort);
|
||||
buf.writeInt(list.size());
|
||||
try {
|
||||
for (IAEItemStack is : list) {
|
||||
is.writeToPacket(buf);
|
||||
}
|
||||
} catch (IOException io) {
|
||||
io.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setResort(boolean resort) {
|
||||
this.resort = resort;
|
||||
super(b);
|
||||
}
|
||||
|
||||
public void appendItem(final IAEItemStack is) {
|
||||
list.add(is);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.list.isEmpty();
|
||||
public void addAll(final List<IAEItemStack> list) {
|
||||
this.list.addAll(list);
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<SPacketMEItemInvUpdate, IMessage> {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public IMessage onMessage(SPacketMEItemInvUpdate message, MessageContext ctx) {
|
||||
final GuiScreen gs = Minecraft.getMinecraft().currentScreen;
|
||||
if (gs == null && message.ref != 0) {
|
||||
ClientProxy.postUpdate(message.list, message.ref);
|
||||
ClientProxy.postUpdate((List) message.list, message.ref);
|
||||
}
|
||||
if (gs instanceof GuiItemMonitor) {
|
||||
((GuiItemMonitor) gs).postUpdate(message.list, message.resort);
|
||||
((GuiItemMonitor) gs).postUpdate((List) message.list);
|
||||
} else if (gs instanceof GuiFluidCraftConfirm) {
|
||||
((GuiFluidCraftConfirm) gs).postUpdate(message.list, message.ref);
|
||||
((GuiFluidCraftConfirm) gs).postUpdate((List) message.list, message.ref);
|
||||
} else if (gs instanceof GuiLevelMaintainer) {
|
||||
((GuiLevelMaintainer) gs).postUpdate(message.list);
|
||||
((GuiLevelMaintainer) gs).postUpdate((List) message.list);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.common.Config;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
|
||||
/**
|
||||
* Only should exist on the server side! Schedules packets to be sent every `packetRate` ms.
|
||||
*/
|
||||
public class SPacketMEUpdateBuffer {
|
||||
|
||||
private static ScheduledExecutorService executor;
|
||||
private static ScheduledFuture<?> task;
|
||||
|
||||
private static final Map<EntityPlayerMP, LinkedHashSet<IAEItemStack>> itemBuffer = new HashMap<>();
|
||||
|
||||
private static final Map<EntityPlayerMP, LinkedHashSet<IAEFluidStack>> fluidBuffer = new HashMap<>();
|
||||
|
||||
public static void init() {
|
||||
executor = Executors.newSingleThreadScheduledExecutor(r -> {
|
||||
Thread thread = new Thread(r);
|
||||
thread.setName("AE2FC Network worker");
|
||||
thread.setDaemon(true);
|
||||
thread.setPriority(6);
|
||||
return thread;
|
||||
});
|
||||
task = executor
|
||||
.scheduleAtFixedRate(SPacketMEUpdateBuffer::sendBuffer, 0, Config.packetRate, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public static void disable() {
|
||||
task.cancel(false);
|
||||
executor.shutdown();
|
||||
}
|
||||
|
||||
public static void scheduleItemUpdate(EntityPlayerMP player, List<IAEItemStack> stacks) {
|
||||
synchronized (itemBuffer) {
|
||||
if (!itemBuffer.containsKey(player)) {
|
||||
itemBuffer.put(player, new LinkedHashSet<>(1024));
|
||||
}
|
||||
LinkedHashSet<IAEItemStack> buffer = itemBuffer.get(player);
|
||||
stacks.forEach(s -> buffer.add(s.copy()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void scheduleFluidUpdate(EntityPlayerMP player, List<IAEFluidStack> stacks) {
|
||||
synchronized (itemBuffer) {
|
||||
if (!fluidBuffer.containsKey(player)) {
|
||||
fluidBuffer.put(player, new LinkedHashSet<>(1024));
|
||||
}
|
||||
LinkedHashSet<IAEFluidStack> buffer = fluidBuffer.get(player);
|
||||
stacks.forEach(s -> buffer.add(s.copy()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendBuffer() {
|
||||
synchronized (itemBuffer) {
|
||||
itemBuffer.forEach((player, updates) -> {
|
||||
if (updates.isEmpty()) return;
|
||||
int i = 0;
|
||||
SPacketMEItemInvUpdate packet = new SPacketMEItemInvUpdate(false);
|
||||
Iterator<IAEItemStack> it = updates.iterator();
|
||||
while (it.hasNext()) {
|
||||
if (i < Config.packetSize) {
|
||||
packet.appendItem(it.next());
|
||||
it.remove();
|
||||
i++;
|
||||
} else {
|
||||
FluidCraft.proxy.netHandler.sendTo(packet, player);
|
||||
packet = new SPacketMEItemInvUpdate(false);
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
packet.setResort(true);
|
||||
FluidCraft.proxy.netHandler.sendTo(packet, player);
|
||||
});
|
||||
fluidBuffer.forEach((player, updates) -> {
|
||||
if (updates.isEmpty()) return;
|
||||
int i = 0;
|
||||
SPacketMEFluidInvUpdate packet = new SPacketMEFluidInvUpdate(false);
|
||||
Iterator<IAEFluidStack> it = updates.iterator();
|
||||
while (it.hasNext()) {
|
||||
if (i < Config.packetSize) {
|
||||
packet.appendFluid(it.next());
|
||||
it.remove();
|
||||
i++;
|
||||
} else {
|
||||
FluidCraft.proxy.netHandler.sendTo(packet, player);
|
||||
packet = new SPacketMEFluidInvUpdate(false);
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
packet.setResort(true);
|
||||
FluidCraft.proxy.netHandler.sendTo(packet, player);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void clear(EntityPlayerMP player) {
|
||||
synchronized (itemBuffer) {
|
||||
if (itemBuffer.containsKey(player)) {
|
||||
itemBuffer.get(player).clear();
|
||||
}
|
||||
if (fluidBuffer.containsKey(player)) {
|
||||
fluidBuffer.get(player).clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerLeave(PlayerEvent.PlayerLoggedOutEvent event) {
|
||||
if (event.player instanceof EntityPlayerMP) {
|
||||
clear((EntityPlayerMP) event.player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,6 @@ import com.glodblock.github.crossmod.thaumcraft.AspectUtil;
|
||||
import com.glodblock.github.inventory.external.AEFluidInterfaceHandler;
|
||||
import com.glodblock.github.inventory.item.WirelessMagnetCardFilterInventory;
|
||||
import com.glodblock.github.loader.ItemAndBlockHolder;
|
||||
import com.glodblock.github.network.SPacketMEUpdateBuffer;
|
||||
import com.glodblock.github.network.wrapper.FCNetworkWrapper;
|
||||
import com.glodblock.github.util.ModAndClassUtil;
|
||||
import com.glodblock.github.util.Util;
|
||||
@@ -125,7 +124,6 @@ public class CommonProxy {
|
||||
|
||||
public void init(FMLInitializationEvent event) {
|
||||
this.registerMovables();
|
||||
FMLCommonHandler.instance().bus().register(SPacketMEUpdateBuffer.class);
|
||||
if (ModAndClassUtil.ThE) {
|
||||
AspectUtil.init();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user