Compare commits

...
Author SHA1 Message Date
zy 7912a35083 update code style 2024-01-05 11:13:48 +08:00
zy 1e6ed66244 update code style 2024-01-04 23:57:03 +08:00
zy 2c005e13d6 add infinity water cell
add infinity lava cell
2024-01-04 18:21:46 +08:00
zy d2c645524b Merge remote-tracking branch 'origin/master' 2024-01-04 14:42:04 +08:00
zy 6b7c53879a add gzip support
fix terminal sometime drop network packet
2024-01-04 14:41:52 +08:00
29 changed files with 467 additions and 454 deletions

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(
@@ -76,7 +73,7 @@ public class FluidCraft {
if (!Config.removeRecipe) {
RecipeLoader.INSTANCE.run();
}
if (Config.enableTestItemRecipe) {
if (Config.testItemRecipe) {
RecipeLoader.addTestItem();
}
RecipeLoader.runTerminalRecipe();
@@ -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();
}
@@ -45,12 +45,12 @@ public class GuiMagnet extends AEBaseMEGui {
private GuiFCImgButton disable;
private String action;
private boolean var;
private boolean value;
public Component(int x, int y, boolean var, String action) {
public Component(int x, int y, boolean value, String action) {
this.enable = new GuiFCImgButton(x, y, "ENABLE_12x", "ENABLE", false);
this.disable = new GuiFCImgButton(x, y, "DISABLE_12x", "DISABLE", false);
this.var = var;
this.value = value;
this.action = action;
buttonList.add(this.enable);
buttonList.add(this.disable);
@@ -60,20 +60,20 @@ public class GuiMagnet extends AEBaseMEGui {
return btn == this.enable || btn == this.disable;
}
public boolean getVar() {
return this.var;
public boolean getValue() {
return this.value;
}
public void setVar(boolean var) {
this.var = var;
public void setValue(boolean value) {
this.value = value;
}
public void send() {
FluidCraft.proxy.netHandler.sendToServer(new CPacketFluidTerminalBtns(this.action, !this.getVar()));
FluidCraft.proxy.netHandler.sendToServer(new CPacketFluidTerminalBtns(this.action, !this.getValue()));
}
public void draw() {
if (var) {
if (value) {
this.enable.visible = true;
this.disable.visible = false;
} else {
@@ -138,9 +138,9 @@ public class GuiMagnet extends AEBaseMEGui {
.drawString(getGuiDisplayName(NameConst.i18n(NameConst.GUI_MAGNET_CARD_META)), 61, 34, 0x404040);
this.fontRendererObj
.drawString(getGuiDisplayName(NameConst.i18n(NameConst.GUI_MAGNET_CARD_ORE)), 61, 46, 0x404040);
this.components[0].setVar(this.cont.nbt);
this.components[1].setVar(this.cont.meta);
this.components[2].setVar(this.cont.ore);
this.components[0].setValue(this.cont.nbt);
this.components[1].setValue(this.cont.meta);
this.components[2].setValue(this.cont.ore);
for (Component c : components) {
c.draw();
}
@@ -63,17 +63,17 @@ public abstract class FCBaseMEGui extends AEBaseMEGui {
protected boolean drawSwitchGuiBtn;
private boolean hasMagnetCard = false;
private StorageChannel channel = null;
private final FCBaseContainer container;
protected final int buttonOffset = 18;
public FCBaseMEGui(final InventoryPlayer inventoryPlayer, Container container) {
super(container);
if (container instanceof FCBaseContainer) {
Object target = ((FCBaseContainer) container).getTarget();
if (target instanceof IWirelessTerminal
&& ((IWirelessTerminal) target).getItemStack().getItem() instanceof ItemWirelessUltraTerminal) {
this.drawSwitchGuiBtn = true;
this.hasMagnetCard = Util.Wireless.hasMagnetCard(((IWirelessTerminal) target).getItemStack());
this.channel = ((IWirelessTerminal) target).getChannel();
}
this.container = (FCBaseContainer) container;
if (this.container.getTarget() instanceof IWirelessTerminal iwt
&& iwt.getItemStack().getItem() instanceof ItemWirelessUltraTerminal) {
this.drawSwitchGuiBtn = true;
this.hasMagnetCard = Util.Wireless.hasMagnetCard(iwt.getItemStack());
this.channel = iwt.getChannel();
}
}
@@ -112,17 +112,17 @@ public abstract class FCBaseMEGui extends AEBaseMEGui {
protected ItemMagnetCard.Mode getMagnetMode() {
if (this.hasMagnetCard) {
return ((FCBaseContainer) this.inventorySlots).mode;
return this.container.mode;
}
return null;
}
protected boolean isRestock() {
return ((FCBaseContainer) this.inventorySlots).restock;
return this.container.restock;
}
protected boolean isSyncData() {
return ((FCBaseContainer) this.inventorySlots).sync;
return this.container.sync;
}
@Override
@@ -131,16 +131,16 @@ public abstract class FCBaseMEGui extends AEBaseMEGui {
}
protected void setSyncState() {
if (this.inventorySlots instanceof FCContainerMonitor && !isPortableCell()) {
if (this.container instanceof FCContainerMonitor && !isPortableCell()) {
this.buttonList.add(
this.dataSyncEnableBtn = new GuiFCImgButton(
this.guiLeft + this.xSize - 18,
this.guiLeft + this.xSize - buttonOffset,
this.guiTop + this.ySize - 44,
"DATA_SYNC",
"ENABLE"));
this.buttonList.add(
this.dataSyncDisableBtn = new GuiFCImgButton(
this.guiLeft + this.xSize - 18,
this.guiLeft + this.xSize - buttonOffset,
this.guiTop + this.ySize - 44,
"DATA_SYNC",
"DISABLE"));
@@ -167,25 +167,25 @@ public abstract class FCBaseMEGui extends AEBaseMEGui {
if (this.getMagnetMode() != null && this.channel == StorageChannel.ITEMS) {
this.buttonList.add(
this.magnetOff = new GuiFCImgButton(
this.guiLeft + this.xSize - 18,
this.guiLeft + this.xSize - buttonOffset,
this.guiTop + this.ySize - 124,
"MAGNET_CARD",
"OFF"));
this.buttonList.add(
this.magnetInv = new GuiFCImgButton(
this.guiLeft + this.xSize - 18,
this.guiLeft + this.xSize - buttonOffset,
this.guiTop + this.ySize - 124,
"MAGNET_CARD",
"INV"));
this.buttonList.add(
this.magnetME = new GuiFCImgButton(
this.guiLeft + this.xSize - 18,
this.guiLeft + this.xSize - buttonOffset,
this.guiTop + this.ySize - 124,
"MAGNET_CARD",
"ME"));
this.buttonList.add(
this.magnetFilter = new GuiFCImgButton(
this.guiLeft + this.xSize - 18,
this.guiLeft + this.xSize - buttonOffset,
this.guiTop + this.ySize - 104,
"MAGNET_CARD",
"FILTER"));
@@ -193,13 +193,13 @@ public abstract class FCBaseMEGui extends AEBaseMEGui {
if (this.channel == StorageChannel.ITEMS) {
this.buttonList.add(
this.restockEnableBtn = new GuiFCImgButton(
this.guiLeft + this.xSize - 18,
this.guiLeft + this.xSize - buttonOffset,
this.guiTop + this.ySize - 84,
"RESTOCK",
"ENABLE"));
this.buttonList.add(
this.restockDisableBtn = new GuiFCImgButton(
this.guiLeft + this.xSize - 18,
this.guiLeft + this.xSize - buttonOffset,
this.guiTop + this.ySize - 84,
"RESTOCK",
"DISABLE"));
@@ -207,7 +207,7 @@ public abstract class FCBaseMEGui extends AEBaseMEGui {
if (!(this instanceof GuiFluidCraftingWireless)) {
this.buttonList.add(
this.CraftingTerminal = new GuiFCImgButton(
this.guiLeft - 18,
this.guiLeft - buttonOffset,
this.getOffsetY(),
"CRAFT_TEM",
"YES"));
@@ -217,7 +217,7 @@ public abstract class FCBaseMEGui extends AEBaseMEGui {
if (!(this instanceof GuiFluidPatternWireless)) {
this.buttonList.add(
this.PatternTerminal = new GuiFCImgButton(
this.guiLeft - 18,
this.guiLeft - buttonOffset,
this.getOffsetY(),
"PATTERN_TEM",
"YES"));
@@ -227,7 +227,7 @@ public abstract class FCBaseMEGui extends AEBaseMEGui {
if (!(this instanceof GuiFluidPatternExWireless)) {
this.buttonList.add(
this.PatternTerminalEx = new GuiFCImgButton(
this.guiLeft - 18,
this.guiLeft - buttonOffset,
this.getOffsetY(),
"PATTERN_EX_TEM",
"YES"));
@@ -236,14 +236,18 @@ public abstract class FCBaseMEGui extends AEBaseMEGui {
}
if (!(this instanceof GuiFluidPortableCell)) {
this.buttonList.add(
this.FluidTerminal = new GuiFCImgButton(this.guiLeft - 18, this.getOffsetY(), "FLUID_TEM", "YES"));
this.FluidTerminal = new GuiFCImgButton(
this.guiLeft - buttonOffset,
this.getOffsetY(),
"FLUID_TEM",
"YES"));
this.setOffsetY(this.getOffsetY() + 20);
termBtns.add(this.FluidTerminal);
}
if (!(this instanceof GuiInterfaceWireless)) {
this.buttonList.add(
this.InterfaceTerminal = new GuiFCImgButton(
this.guiLeft - 18,
this.guiLeft - buttonOffset,
this.getOffsetY(),
"INTERFACE_TEM",
"YES"));
@@ -252,14 +256,18 @@ public abstract class FCBaseMEGui extends AEBaseMEGui {
}
if (!(this instanceof GuiLevelWireless)) {
this.buttonList.add(
this.LevelTerminal = new GuiFCImgButton(this.guiLeft - 18, this.getOffsetY(), "LEVEL_TEM", "YES"));
this.LevelTerminal = new GuiFCImgButton(
this.guiLeft - buttonOffset,
this.getOffsetY(),
"LEVEL_TEM",
"YES"));
this.setOffsetY(this.getOffsetY() + 20);
termBtns.add(this.LevelTerminal);
}
if (ModAndClassUtil.ThE && !(this instanceof GuiEssentiaTerminal)) {
this.buttonList.add(
this.EssentiaTerminal = new GuiFCImgButton(
this.guiLeft - 18,
this.guiLeft - buttonOffset,
this.getOffsetY(),
"ESSENTIA_TEM",
"YES"));
@@ -283,10 +291,8 @@ public abstract class FCBaseMEGui extends AEBaseMEGui {
magnetButtons[i].visible = getMagnetMode().ordinal() == i;
}
}
if (this.inventorySlots instanceof FCBaseContainer) {
this.dataSyncDisableBtn.visible = !isSyncData();
this.dataSyncEnableBtn.visible = isSyncData();
}
this.dataSyncDisableBtn.visible = !isSyncData();
this.dataSyncEnableBtn.visible = isSyncData();
if (this.drawSwitchGuiBtn && this.channel == StorageChannel.ITEMS) { // Only ultra terminal
this.restockDisableBtn.visible = !this.isRestock();
this.restockEnableBtn.visible = this.isRestock();
@@ -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);
}
}
}
@@ -17,7 +17,7 @@ public abstract class FCBaseContainer extends AEBaseContainer {
private int ticks;
private final double powerMultiplier = 0.5;
private ITerminalHost host;
protected ITerminalHost host;
private int slot = -1;
private final InventoryPlayer ip;
@GuiSync(105)
@@ -40,8 +40,8 @@ public abstract class FCBaseContainer extends AEBaseContainer {
private int lockSlot() {
if (isWirelessTerminal()) {
if (this.host instanceof IFluidPortableCell) {
final int slotIndex = ((IFluidPortableCell) this.host).getInventorySlot();
if (this.host instanceof IFluidPortableCell ifpc) {
final int slotIndex = ifpc.getInventorySlot();
if (Util.GuiHelper.decodeInvType(slotIndex).getLeft() == Util.GuiHelper.InvType.PLAYER_INV) {
this.lockPlayerInventorySlot(slotIndex);
}
@@ -66,12 +66,12 @@ public abstract class FCBaseContainer extends AEBaseContainer {
((IFluidPortableCell) this.host));
}
if (Platform.isServer()) {
if (this.host instanceof IWirelessExtendCard) {
this.mode = ((IWirelessExtendCard) this.host).getMagnetCardMode();
this.restock = ((IWirelessExtendCard) this.host).isRestock();
if (this.host instanceof IWirelessExtendCard iwec) {
this.mode = iwec.getMagnetCardMode();
this.restock = iwec.isRestock();
}
if (this.host != null && this.host instanceof IItemTerminal) {
this.sync = ((IItemTerminal) this.host).getSyncData();
if (this.host != null && this.host instanceof IItemTerminal iwt) {
this.sync = iwt.getSyncData();
}
}
super.detectAndSendChanges();
@@ -86,8 +86,8 @@ public abstract class FCBaseContainer extends AEBaseContainer {
}
public IFluidPortableCell getPortableCell() {
if (this.host instanceof IFluidPortableCell) {
return (IFluidPortableCell) this.host;
if (this.host instanceof IFluidPortableCell ifpc) {
return ifpc;
} else {
return null;
}
@@ -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;
@@ -44,7 +43,6 @@ public abstract class FCContainerMonitor<T extends IAEStack<T>> extends FCBaseCo
protected final SlotRestrictedInput[] cellView = new SlotRestrictedInput[5];
protected final IConfigManager clientCM;
protected final ITerminalHost host;
@GuiSync(99)
public boolean canAccessViewCells = false;
@@ -170,10 +168,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);
}
}
}
@@ -15,11 +15,9 @@ public class Config {
public static boolean noFluidPacket;
public static boolean fluidIOBus;
public static boolean removeRecipe;
public static boolean enableTestItemRecipe = true;
public static boolean testItemRecipe;
public static double portableCellBattery;
public static boolean fluidP2PInterface;
public static int packetSize;
public static int packetRate;
public static boolean replaceEC2;
public static int levelMaintainerMinTicks;
public static int levelMaintainerMaxTicks;
@@ -57,13 +55,8 @@ public class Config {
"Disable all recipes, for quick tweaker.");
portableCellBattery = Config.get("Fluid Craft for AE2", "Portable Fluid Cell Battery Capacity", 20000D)
.getDouble();
packetSize = Config.get("Fluid Craft for AE2", "packetSize", 256, "Number of items to be sent per packet")
.getInt();
if (packetSize <= 0) packetSize = 256;
packetRate = Config
.get("Fluid Craft for AE2", "packetRate", 50, "Period at which packets are dispatched, in ms.")
.getInt();
if (packetRate <= 0) packetRate = 50;
testItemRecipe = Config.get("Fluid Craft for AE2", "Experimental items", true, "Experimental items")
.getBoolean();
replaceEC2 = Config.getBoolean(
"replaceEC2",
"Fluid Craft for AE2",
@@ -0,0 +1,123 @@
package com.glodblock.github.common.item;
import java.util.List;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;
import com.glodblock.github.api.FluidCraftAPI;
import com.glodblock.github.common.storage.IFluidCellInventory;
import com.glodblock.github.common.storage.IFluidCellInventoryHandler;
import com.glodblock.github.common.storage.IStorageFluidCell;
import com.glodblock.github.util.NameConst;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.items.AEBaseItem;
import appeng.items.contents.CellUpgrades;
import appeng.tile.inventory.AppEngInternalInventory;
public abstract class ItemBaseInfinityStorageCell extends AEBaseItem implements IStorageFluidCell {
protected static class InfinityConfig extends AppEngInternalInventory {
public InfinityConfig(final ItemStack is) {
super(null, 1);
this.setInventorySlotContents(0, is);
}
@Override
public void markDirty() {}
}
@Override
public long getBytes(ItemStack cellItem) {
return Integer.MAX_VALUE;
}
@Override
public int getBytesPerType(ItemStack cellItem) {
return 1;
}
@Override
public boolean isBlackListed(ItemStack cellItem, IAEFluidStack requestedAddition) {
return requestedAddition == null || requestedAddition.getFluid() == null
|| FluidCraftAPI.instance().isBlacklistedInStorage(requestedAddition.getFluid().getClass());
}
@Override
public abstract IInventory getConfigInventory(ItemStack is);
@Override
public boolean storableInStorageCell() {
return false;
}
@Override
public boolean isStorageCell(ItemStack i) {
return true;
}
@Override
public double getIdleDrain(ItemStack is) {
return 0;
}
@Override
public int getTotalTypes(ItemStack cellItem) {
return 0;
}
@Override
public boolean isEditable(ItemStack is) {
return false;
}
@Override
public IInventory getUpgradesInventory(ItemStack is) {
return new CellUpgrades(is, 0);
}
@Override
public FuzzyMode getFuzzyMode(ItemStack is) {
return null;
}
@Override
public void setFuzzyMode(ItemStack is, FuzzyMode fzMode) {
}
@Override
public void addCheckedInformation(final ItemStack stack, final EntityPlayer player, final List<String> lines,
final boolean displayMoreInfo) {
final IMEInventoryHandler<?> inventory = AEApi.instance().registries().cell()
.getCellInventory(stack, null, StorageChannel.FLUIDS);
if (inventory instanceof final IFluidCellInventoryHandler handler) {
final IFluidCellInventory cellInventory = handler.getCellInv();
if (GuiScreen.isCtrlKeyDown()) {
if (!cellInventory.getContents().isEmpty()) {
lines.add(StatCollector.translateToLocal(NameConst.TT_CELL_CONTENTS));
for (IAEFluidStack fluid : cellInventory.getContents()) {
if (fluid != null) {
lines.add(String.format(" %s", fluid.getFluidStack().getLocalizedName()));
}
}
} else {
lines.add(StatCollector.translateToLocal(NameConst.TT_CELL_EMPTY));
}
} else {
lines.add(StatCollector.translateToLocal(NameConst.TT_CTRL_FOR_MORE));
}
}
}
}
@@ -1,36 +1,23 @@
package com.glodblock.github.common.item;
import java.util.EnumSet;
import java.util.List;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.api.FluidCraftAPI;
import com.glodblock.github.common.storage.IFluidCellInventory;
import com.glodblock.github.common.storage.IFluidCellInventoryHandler;
import com.glodblock.github.common.storage.IStorageFluidCell;
import com.glodblock.github.common.tabs.FluidCraftingTabs;
import com.glodblock.github.loader.IRegister;
import com.glodblock.github.util.NameConst;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.core.features.AEFeature;
import appeng.items.AEBaseItem;
import appeng.items.contents.CellConfig;
import appeng.items.contents.CellUpgrades;
import appeng.util.Platform;
import cpw.mods.fml.common.registry.GameRegistry;
public class ItemCreativeFluidStorageCell extends AEBaseItem
public class ItemCreativeFluidStorageCell extends ItemBaseInfinityStorageCell
implements IStorageFluidCell, IRegister<ItemCreativeFluidStorageCell> {
public ItemCreativeFluidStorageCell() {
@@ -41,52 +28,6 @@ public class ItemCreativeFluidStorageCell extends AEBaseItem
this.setMaxStackSize(1);
}
@Override
public long getBytes(ItemStack cellItem) {
return 0;
}
@Override
public int getBytesPerType(ItemStack cellItem) {
return 0;
}
@Override
public boolean isBlackListed(ItemStack cellItem, IAEFluidStack requestedAddition) {
return requestedAddition == null || requestedAddition.getFluid() == null
|| FluidCraftAPI.instance().isBlacklistedInStorage(requestedAddition.getFluid().getClass());
}
@Override
public boolean storableInStorageCell() {
return false;
}
@Override
public boolean isStorageCell(ItemStack i) {
return true;
}
@Override
public double getIdleDrain(ItemStack is) {
return 0;
}
@Override
public int getTotalTypes(ItemStack cellItem) {
return 0;
}
@Override
public boolean isEditable(ItemStack is) {
return true;
}
@Override
public IInventory getUpgradesInventory(ItemStack is) {
return new CellUpgrades(is, 0);
}
@Override
public IInventory getConfigInventory(ItemStack is) {
return new CellConfig(is);
@@ -103,29 +44,8 @@ public class ItemCreativeFluidStorageCell extends AEBaseItem
}
@Override
public void addCheckedInformation(final ItemStack stack, final EntityPlayer player, final List<String> lines,
final boolean displayMoreInfo) {
final IMEInventoryHandler<?> inventory = AEApi.instance().registries().cell()
.getCellInventory(stack, null, StorageChannel.FLUIDS);
if (inventory instanceof final IFluidCellInventoryHandler handler) {
final IFluidCellInventory cellInventory = handler.getCellInv();
if (GuiScreen.isCtrlKeyDown()) {
if (cellInventory.getContents().size() > 0) {
lines.add(StatCollector.translateToLocal(NameConst.TT_CELL_CONTENTS));
for (IAEFluidStack fluid : cellInventory.getContents()) {
if (fluid != null) {
lines.add(String.format(" %s", fluid.getFluidStack().getLocalizedName()));
}
}
} else {
lines.add(StatCollector.translateToLocal(NameConst.TT_CELL_EMPTY));
}
} else {
lines.add(StatCollector.translateToLocal(NameConst.TT_CTRL_FOR_MORE));
}
}
public boolean isEditable(ItemStack is) {
return true;
}
@Override
@@ -0,0 +1,41 @@
package com.glodblock.github.common.item;
import static com.glodblock.github.util.Util.FluidUtil.lava_bucket;
import java.util.EnumSet;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.storage.IStorageFluidCell;
import com.glodblock.github.common.tabs.FluidCraftingTabs;
import com.glodblock.github.loader.IRegister;
import com.glodblock.github.util.NameConst;
import appeng.core.features.AEFeature;
import cpw.mods.fml.common.registry.GameRegistry;
public class ItemInfinityLavaStorageCell extends ItemBaseInfinityStorageCell
implements IStorageFluidCell, IRegister<ItemInfinityLavaStorageCell> {
@Override
public IInventory getConfigInventory(ItemStack is) {
return new InfinityConfig(lava_bucket);
}
public ItemInfinityLavaStorageCell() {
super();
setUnlocalizedName(NameConst.ITEM_INFINITY_LAVA_FLUID_STORAGE);
setTextureName(FluidCraft.resource(NameConst.ITEM_INFINITY_FLUID_STORAGE).toString());
this.setFeature(EnumSet.of(AEFeature.StorageCells));
this.setMaxStackSize(1);
}
@Override
public ItemInfinityLavaStorageCell register() {
GameRegistry.registerItem(this, NameConst.ITEM_INFINITY_LAVA_FLUID_STORAGE, FluidCraft.MODID);
setCreativeTab(FluidCraftingTabs.INSTANCE);
return this;
}
}
@@ -0,0 +1,41 @@
package com.glodblock.github.common.item;
import static com.glodblock.github.util.Util.FluidUtil.water_bucket;
import java.util.EnumSet;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.storage.IStorageFluidCell;
import com.glodblock.github.common.tabs.FluidCraftingTabs;
import com.glodblock.github.loader.IRegister;
import com.glodblock.github.util.NameConst;
import appeng.core.features.AEFeature;
import cpw.mods.fml.common.registry.GameRegistry;
public class ItemInfinityWaterStorageCell extends ItemBaseInfinityStorageCell
implements IStorageFluidCell, IRegister<ItemInfinityWaterStorageCell> {
@Override
public IInventory getConfigInventory(ItemStack is) {
return new InfinityConfig(water_bucket);
}
public ItemInfinityWaterStorageCell() {
super();
setUnlocalizedName(NameConst.ITEM_INFINITY_WATER_FLUID_STORAGE);
setTextureName(FluidCraft.resource(NameConst.ITEM_INFINITY_FLUID_STORAGE).toString());
this.setFeature(EnumSet.of(AEFeature.StorageCells));
this.setMaxStackSize(1);
}
@Override
public ItemInfinityWaterStorageCell register() {
GameRegistry.registerItem(this, NameConst.ITEM_INFINITY_WATER_FLUID_STORAGE, FluidCraft.MODID);
setCreativeTab(FluidCraftingTabs.INSTANCE);
return this;
}
}
@@ -61,7 +61,7 @@ public class CreativeFluidCellInventory extends FluidCellInventory {
if (fs == null) continue;
IAEFluidStack iaeFluidStack = Util.FluidUtil.createAEFluidStack(fs);
if (this.cellFluids.findPrecise(iaeFluidStack) == null) {
iaeFluidStack.setStackSize(Integer.MAX_VALUE);
iaeFluidStack.setStackSize(Integer.MAX_VALUE * 1000L);
this.cellFluids.add(iaeFluidStack);
}
}
@@ -12,7 +12,7 @@ import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
import com.glodblock.github.common.item.ItemCreativeFluidStorageCell;
import com.glodblock.github.common.item.ItemBaseInfinityStorageCell;
import com.glodblock.github.crossmod.extracells.storage.ProxyFluidCellInventory;
import com.glodblock.github.crossmod.extracells.storage.ProxyFluidStorageCell;
@@ -82,7 +82,7 @@ public class FluidCellInventory implements IFluidCellInventory {
public static IMEInventoryHandler<IAEFluidStack> getCell(final ItemStack o, final ISaveProvider container2) {
try {
if (o.getItem() instanceof ItemCreativeFluidStorageCell) {
if (o.getItem() instanceof ItemBaseInfinityStorageCell) {
return new FluidCellInventoryHandler(new CreativeFluidCellInventory(o, container2));
} else if (o.getItem() instanceof ProxyFluidStorageCell) {
return new FluidCellInventoryHandler(new ProxyFluidCellInventory(o, container2));
@@ -29,6 +29,8 @@ import com.glodblock.github.common.item.ItemFluidLevelEmitter;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.common.item.ItemFluidStorageHousing;
import com.glodblock.github.common.item.ItemFluidStorageMonitor;
import com.glodblock.github.common.item.ItemInfinityLavaStorageCell;
import com.glodblock.github.common.item.ItemInfinityWaterStorageCell;
import com.glodblock.github.common.item.ItemMagnetCard;
import com.glodblock.github.common.item.ItemMultiFluidStorageCell;
import com.glodblock.github.common.item.ItemPartFluidInterface;
@@ -52,9 +54,6 @@ public class ItemAndBlockHolder {
public static void init() {}
public static ItemEnergyCard ENERGY_CARD = new ItemEnergyCard().register();
public static ItemQuantumBridgeCard QUANTUM_BRIDGE_CARD = new ItemQuantumBridgeCard().register();
public static ItemMagnetCard MAGNET_CARD = new ItemMagnetCard().register();
public static BlockCertusQuartzTank CERTUS_QUARTZ_TANK = new BlockCertusQuartzTank().register();
public static BlockFluidAutoFiller FLUID_AUTO_FILLER = new BlockFluidAutoFiller().register();
public static BlockFluidDiscretizer DISCRETIZER = new BlockFluidDiscretizer().register();
@@ -138,8 +137,13 @@ public class ItemAndBlockHolder {
1,
5).register();
public static ItemCreativeFluidStorageCell CREATIVE_CELL = new ItemCreativeFluidStorageCell().register();
public static ItemInfinityWaterStorageCell INFINITY_WATER_CELL = new ItemInfinityWaterStorageCell().register();
public static ItemInfinityLavaStorageCell INFINITY_LAVA_CELL = new ItemInfinityLavaStorageCell().register();
public static ItemBasicFluidStoragePart CELL_PART = new ItemBasicFluidStoragePart().register();
public static ItemFluidStorageHousing CELL_HOUSING = new ItemFluidStorageHousing().register();
public static ItemEnergyCard ENERGY_CARD = new ItemEnergyCard().register();
public static ItemQuantumBridgeCard QUANTUM_BRIDGE_CARD = new ItemQuantumBridgeCard().register();
public static ItemMagnetCard MAGNET_CARD = new ItemMagnetCard().register();
public static void loadSetting() {
if (!Config.fluidCells) return;
@@ -651,6 +651,8 @@ public class RecipeLoader implements Runnable {
AE2_FLUIX_PEARL,
'R',
AE2_WIRELESS_RECEIVER));
GameRegistry.addRecipe(
new ShapelessOreRecipe(INFINITY_WATER_CELL, CELL_HOUSING.stack(1, 1), CellType.Cell64kPart.stack(1)));
}
public static void runTerminalRecipe() {
@@ -659,6 +661,7 @@ public class RecipeLoader implements Runnable {
GameRegistry.addRecipe(new WirelessTerminalInfinityBoosterRecipe(WIRELESS_FLUID_TERM.stack(), c));
GameRegistry.addRecipe(new WirelessTerminalInfinityBoosterRecipe(WIRELESS_ULTRA_TERM.stack(), c));
GameRegistry.addRecipe(new WirelessTerminalInfinityBoosterRecipe(WIRELESS_INTERFACE_TERM.stack(), c));
GameRegistry.addRecipe(new WirelessTerminalInfinityBoosterRecipe(WIRELESS_LEVEL_TERM.stack(), c));
}
for (ItemStack m : magnetCards) {
GameRegistry.addRecipe(new WirelessTerminalMagnetRecipe(WIRELESS_ULTRA_TERM.stack(), m));
@@ -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;
@@ -32,6 +31,7 @@ import appeng.api.config.Upgrades;
import appeng.api.networking.IGridNode;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.core.AELog;
import appeng.util.Platform;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
@@ -94,7 +94,7 @@ public class CommonProxy {
}
} catch (NullPointerException ex) {
ex.printStackTrace();
AELog.error(ex);
}
}
@@ -125,7 +125,6 @@ public class CommonProxy {
public void init(FMLInitializationEvent event) {
this.registerMovables();
FMLCommonHandler.instance().bus().register(SPacketMEUpdateBuffer.class);
if (ModAndClassUtil.ThE) {
AspectUtil.init();
}
@@ -40,6 +40,9 @@ public class NameConst {
public static final String ITEM_MULTI_FLUID_STORAGE = "multi_fluid_storage";
public static final String ITEM_QUANTUM_FLUID_STORAGE = ITEM_FLUID_STORAGE + ".quantum";
public static final String ITEM_SINGULARITY_FLUID_STORAGE = ITEM_FLUID_STORAGE + ".singularity";
public static final String ITEM_INFINITY_FLUID_STORAGE = ITEM_FLUID_STORAGE + ".infinity";
public static final String ITEM_INFINITY_WATER_FLUID_STORAGE = ITEM_INFINITY_FLUID_STORAGE + ".water";
public static final String ITEM_INFINITY_LAVA_FLUID_STORAGE = ITEM_INFINITY_FLUID_STORAGE + ".lava";
public static final String ITEM_CREATIVE_FLUID_STORAGE = "creative_" + ITEM_FLUID_STORAGE;
public static final String ITEM_FLUID_PORTABLE_CELL = "portable_fluid_cell";
public static final String ITEM_WIRELESS_FLUID_TERMINAL = "wireless_fluid_terminal";
@@ -1,6 +1,9 @@
package com.glodblock.github.util;
import static com.glodblock.github.common.item.ItemBaseWirelessTerminal.*;
import static com.glodblock.github.common.item.ItemBaseWirelessTerminal.infinityBoosterCard;
import static com.glodblock.github.common.item.ItemBaseWirelessTerminal.infinityEnergyCard;
import static com.glodblock.github.common.item.ItemBaseWirelessTerminal.magnetCard;
import static com.glodblock.github.common.item.ItemBaseWirelessTerminal.restockItems;
import static net.minecraft.init.Items.glass_bottle;
import java.io.IOException;
@@ -10,6 +13,7 @@ import java.util.Map;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemPotion;
@@ -499,7 +503,9 @@ public final class Util {
public static class FluidUtil {
private static final ItemStack glassBottle = new ItemStack(glass_bottle, 1);
public static final ItemStack glassBottle = new ItemStack(glass_bottle, 1);
public static final ItemStack water_bucket = new ItemStack(Items.water_bucket, 1);
public static final ItemStack lava_bucket = new ItemStack(Items.lava_bucket, 1);
public static ItemStack getPotion(FluidStack fs) {
if (fs == null) return null;
@@ -47,6 +47,8 @@ item.multi_fluid_storage.4096.name=%s4096k%s ME Multi-Fluid Storage Cell
item.multi_fluid_storage.16384.name=%s16384k%s ME Multi-Fluid Storage Cell
item.fluid_storage.quantum.name=ME Fluid Quantum Storage Cell
item.fluid_storage.singularity.name=ME Fluid Digital Singularity Storage Cell
item.fluid_storage.infinity.water.name=ME Fluid Infinity Water Storage Cell
item.fluid_storage.infinity.lava.name=ME Fluid Infinity Lava Storage Cell
item.fluid_part.0.name=%s1k%s ME Fluid Storage Component
item.fluid_part.1.name=%s4k%s ME Fluid Storage Component
item.fluid_part.2.name=%s16k%s ME Fluid Storage Component
Binary file not shown.

After

Width:  |  Height:  |  Size: 636 B