From c69deecf6e85512391886ff9d2d0cc54c4ffc23c Mon Sep 17 00:00:00 2001 From: tom5454 Date: Thu, 20 Aug 2020 19:30:55 +0200 Subject: [PATCH] 1.3.11 Update Fixed crash with dedicated servers #35 Added blocking mode to AE and RS Crafting Managers --- .../tom/logisticsbridge/LogisticsBridge.java | 2 +- .../gui/GuiCraftingManagerU.java | 40 ++++++++++++- .../item/VirtualPatternAE.java | 4 -- .../node/NetworkNodeCraftingManager.java | 56 ++++++++++++++++++- .../node/NetworkNodeSatellite.java | 9 +++ .../part/PartSatelliteBus.java | 5 ++ .../logisticsbridge/pipe/CraftingManager.java | 25 ++++++--- .../tileentity/ICraftingManager.java | 2 + .../tileentity/TileEntityCraftingManager.java | 53 +++++++++++++++++- .../TileEntityCraftingManagerRS.java | 6 ++ .../assets/logisticsbridge/lang/en_us.lang | 2 + version-check.json | 5 +- 12 files changed, 187 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/tom/logisticsbridge/LogisticsBridge.java b/src/main/java/com/tom/logisticsbridge/LogisticsBridge.java index bf92641..2af1f30 100644 --- a/src/main/java/com/tom/logisticsbridge/LogisticsBridge.java +++ b/src/main/java/com/tom/logisticsbridge/LogisticsBridge.java @@ -82,7 +82,7 @@ public class LogisticsBridge { public static final String ID = "logisticsbridge"; public static final String NAME = "Logistics Bridge"; - public static final String VERSION = "1.3.10"; + public static final String VERSION = "1.3.11"; public static final String DEPS = "after:appliedenergistics2;after:refinedstorage@[1.6.15,);required-after:logisticspipes@[0.10.3.39,)"; public static final String UPDATE = "https://github.com/tom5454/LogisticsBridge/blob/master/version-check.json"; public static final Logger log = LogManager.getLogger(NAME); diff --git a/src/main/java/com/tom/logisticsbridge/gui/GuiCraftingManagerU.java b/src/main/java/com/tom/logisticsbridge/gui/GuiCraftingManagerU.java index f8c2612..3a599ac 100644 --- a/src/main/java/com/tom/logisticsbridge/gui/GuiCraftingManagerU.java +++ b/src/main/java/com/tom/logisticsbridge/gui/GuiCraftingManagerU.java @@ -13,11 +13,13 @@ import net.minecraft.client.renderer.RenderItem; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import com.tom.logisticsbridge.LogisticsBridge; import com.tom.logisticsbridge.inventory.ContainerCraftingManagerU; +import com.tom.logisticsbridge.pipe.CraftingManager.BlockingMode; import com.tom.logisticsbridge.tileentity.ICraftingManager; import logisticspipes.utils.gui.LogisticsBaseGuiScreen; @@ -62,13 +64,38 @@ public void initGui() { ConfigExtention ce = new ConfigExtention(StringUtils.translate("gui.craftingManager.satellite"), pipe.satelliteDisplayStack(), 0); ce.registerButton(extentionControllerLeft.registerControlledButton(addButton(new SmallGuiButton(0, guiLeft - 45, guiTop + 25, 40, 10, StringUtils.translate("gui.crafting.Select"))))); extentionControllerLeft.addExtention(ce); + ce = new ConfigExtention(StringUtils.translate("gui.craftingManager.blocking"), new ItemStack(Blocks.BARRIER), 2) { + + @Override + public String getString() { + return StringUtils.translate("gui.craftingManager.blocking." + pipe.getBlockingMode().name().toLowerCase()); + } + + @Override + public int textOff() { + return 70; + } + + @Override + public int getFinalWidth() { + return 140; + } + }; + ce.registerButton(extentionControllerLeft.registerControlledButton(addButton(new SmallGuiButton(1, guiLeft - 45, guiTop + 11, 40, 10, StringUtils.translate("gui.craftingManager.blocking.change"))))); + extentionControllerLeft.addExtention(ce); } @Override protected void actionPerformed(GuiButton button) throws IOException { switch (button.id) { case 0: openSubGuiForSatelliteSelection(0); - break; + return; + + case 1: + BlockingMode m = BlockingMode.VALUES[(pipe.getBlockingMode().ordinal() + 1) % BlockingMode.VALUES.length]; + if(m == BlockingMode.NULL)m = BlockingMode.OFF; + pipe.setPipeID(1, Integer.toString(m.ordinal()), null); + return; } } private void openSubGuiForSatelliteSelection(int id) { @@ -101,7 +128,7 @@ public int getFinalHeight() { @Override public void renderForground(int left, int top) { - String pid = pipe.getPipeID(id); + String pid = getString(); if (!isFullyExtended()) { GL11.glEnable(GL12.GL_RESCALE_NORMAL); OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240 / 1.0F, 240 / 1.0F); @@ -118,10 +145,17 @@ public void renderForground(int left, int top) { if (pid == null || pid.isEmpty()) { mc.fontRenderer.drawString(StringUtils.translate("gui.craftingManager.noConnection"), left + 40, top + 22, 0x404040); } else { - mc.fontRenderer.drawString("" + pid, left + 40 - mc.fontRenderer.getStringWidth("" + pid)/2, top + 22, 0x404040); + mc.fontRenderer.drawString("" + pid, left + textOff() - mc.fontRenderer.getStringWidth("" + pid)/2, top + 22, 0x404040); } } } + public String getString() { + return pipe.getPipeID(id); + } + + public int textOff() { + return 40; + } } } diff --git a/src/main/java/com/tom/logisticsbridge/item/VirtualPatternAE.java b/src/main/java/com/tom/logisticsbridge/item/VirtualPatternAE.java index 6cd8335..3340a80 100644 --- a/src/main/java/com/tom/logisticsbridge/item/VirtualPatternAE.java +++ b/src/main/java/com/tom/logisticsbridge/item/VirtualPatternAE.java @@ -284,10 +284,6 @@ public VirtualPatternHandler(ItemStack is) { @Override public ItemStack getPattern() { - if(patternItem == null) { - - } - return patternItem; } diff --git a/src/main/java/com/tom/logisticsbridge/node/NetworkNodeCraftingManager.java b/src/main/java/com/tom/logisticsbridge/node/NetworkNodeCraftingManager.java index 70b2c66..024083b 100644 --- a/src/main/java/com/tom/logisticsbridge/node/NetworkNodeCraftingManager.java +++ b/src/main/java/com/tom/logisticsbridge/node/NetworkNodeCraftingManager.java @@ -33,6 +33,7 @@ import com.tom.logisticsbridge.item.VirtualPatternRS; import com.tom.logisticsbridge.network.SetIDPacket; import com.tom.logisticsbridge.network.SetIDPacket.IIdPipe; +import com.tom.logisticsbridge.pipe.CraftingManager.BlockingMode; import logisticspipes.network.PacketHandler; import logisticspipes.network.abstractpackets.ModernPacket; @@ -50,6 +51,7 @@ public class NetworkNodeCraftingManager extends NetworkNode implements IIdPipe, @Override public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { if(supplyID.isEmpty())return stack; + if(!checkBlocking())return stack; NetworkNodeSatellite sat = find(supplyID); if(sat == null)return stack; if(stack.getItem() == LogisticsBridge.packageItem && stack.hasTagCompound() && stack.getTagCompound().getBoolean("__actStack")) { @@ -113,6 +115,8 @@ public int getSlotLimit(int slot) { return 1; } }; + private BlockingMode blockingMode = BlockingMode.OFF; + public NetworkNodeCraftingManager(World world, BlockPos pos) { super(world, pos); } @@ -133,7 +137,7 @@ public String getName(int id) { } @Override public String getPipeID(int id) { - return supplyID; + return id == 0 ? supplyID : Integer.toString(blockingMode.ordinal()); } @Override @@ -146,7 +150,8 @@ public void setPipeID(int id, String pipeID, EntityPlayer player) { final ModernPacket packet = PacketHandler.getPacket(SetIDPacket.class).setName(pipeID).setId(id).setBlockPos(getPos()).setDimension(getWorld()); MainProxy.sendPacketToPlayer(packet, player); } - supplyID = pipeID; + if(id == 0)supplyID = pipeID; + else if(id == 1)blockingMode = BlockingMode.VALUES[Math.abs(pipeID.charAt(0) - '0') % BlockingMode.VALUES.length]; } @Override @@ -156,6 +161,7 @@ public NBTTagCompound write(NBTTagCompound compound) { compound.setUniqueId(NBT_UUID, uuid); } StackUtils.writeItems(patternsInventory, 0, compound); + compound.setByte("blockingMode", (byte) blockingMode.ordinal()); return super.write(compound); } @@ -169,6 +175,7 @@ public void read(NBTTagCompound compound) { if (compound.hasUniqueId(NBT_UUID)) { uuid = compound.getUniqueId(NBT_UUID); } + blockingMode = BlockingMode.VALUES[Math.abs(compound.getByte("blockingMode")) % BlockingMode.VALUES.length]; super.read(compound); } @@ -273,4 +280,49 @@ public void onDisconnected(INetwork network) { .filter(task -> task.getPattern().getContainer().getPosition().equals(pos)) .forEach(task -> network.getCraftingManager().cancel(task.getId())); } + + private boolean checkBlocking() { + switch (blockingMode) { + case EMPTY_MAIN_SATELLITE: + { + if(supplyID.isEmpty())return false; + NetworkNodeSatellite bus = find(supplyID); + if(bus == null)return false; + IItemHandler inv = bus.getHandler(); + if (inv != null) { + for (int i = 0; i < inv.getSlots(); i++) { + ItemStack stackInSlot = inv.getStackInSlot(i); + if (!stackInSlot.isEmpty()) { + return false; + } + } + } + return true; + } + + case REDSTONE_HIGH: + if(!getWorld().isBlockPowered(getPos()))return false; + return true; + + case REDSTONE_LOW: + if(getWorld().isBlockPowered(getPos()))return false; + return true; + + /*case WAIT_FOR_RESULT://TODO + { + IRouter resultR = getResultRouterByID(getResultUUID()); + if(resultR == null)return false; + if(!(resultR.getPipe() instanceof ResultPipe))return false; + if(((ResultPipe) resultR.getPipe()).hasRequests())return false; + return true; + }*/ + + default: + return true; + } + } + + public BlockingMode getBlockingMode() { + return blockingMode; + } } diff --git a/src/main/java/com/tom/logisticsbridge/node/NetworkNodeSatellite.java b/src/main/java/com/tom/logisticsbridge/node/NetworkNodeSatellite.java index 603bd76..26cbeab 100644 --- a/src/main/java/com/tom/logisticsbridge/node/NetworkNodeSatellite.java +++ b/src/main/java/com/tom/logisticsbridge/node/NetworkNodeSatellite.java @@ -65,6 +65,15 @@ public void update() { } } + public IItemHandler getHandler() { + TileEntity te = getFacingTile(); + if(te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, getDirection())){ + IItemHandler h = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, getDirection()); + return h; + } + return null; + } + private ItemStack injectCraftedItems(ItemStack stack, IItemHandler h) { for (int i = 0; i < h.getSlots(); i++) { stack = h.insertItem(i, stack, false); diff --git a/src/main/java/com/tom/logisticsbridge/part/PartSatelliteBus.java b/src/main/java/com/tom/logisticsbridge/part/PartSatelliteBus.java index 395eb83..72ab3ed 100644 --- a/src/main/java/com/tom/logisticsbridge/part/PartSatelliteBus.java +++ b/src/main/java/com/tom/logisticsbridge/part/PartSatelliteBus.java @@ -240,4 +240,9 @@ public boolean push(ItemStack is) { itemsToInsert.add(ITEMS.createStack(is)); return true; } + + @Override + public InventoryAdaptor getHandler() { + return super.getHandler(); + } } diff --git a/src/main/java/com/tom/logisticsbridge/pipe/CraftingManager.java b/src/main/java/com/tom/logisticsbridge/pipe/CraftingManager.java index 8721348..38dd7e8 100644 --- a/src/main/java/com/tom/logisticsbridge/pipe/CraftingManager.java +++ b/src/main/java/com/tom/logisticsbridge/pipe/CraftingManager.java @@ -71,7 +71,9 @@ public class CraftingManager extends PipeLogisticsChassi implements IIdPipe { private int sendCooldown = 0; @SideOnly(Side.CLIENT) - private IInventory clientInv = new InventoryBasic(null, false, 27); + private IInventory clientInv; + + private boolean readingNBT; public CraftingManager(Item item) { super(item); @@ -135,6 +137,7 @@ public void InventoryChanged(IInventory inventory) { } private void sendSignData() { + if(readingNBT)return; for (int i = 0; i < 6; i++) { if (signItem[i] != null) { ModernPacket packet = signItem[i].getPacket(); @@ -275,14 +278,19 @@ public void writeToNBT(NBTTagCompound nbttagcompound) { } @Override public void readFromNBT(NBTTagCompound nbttagcompound) { - super.readFromNBT(nbttagcompound); - resultId = nbttagcompound.getString("resultname"); - satelliteId = nbttagcompound.getString("satellitename"); - if(nbttagcompound.hasKey("resultid")){ - resultId = Integer.toString(nbttagcompound.getInteger("resultid")); - satelliteId = Integer.toString(nbttagcompound.getInteger("satelliteid")); + try { + readingNBT = true; + super.readFromNBT(nbttagcompound); + resultId = nbttagcompound.getString("resultname"); + satelliteId = nbttagcompound.getString("satellitename"); + if(nbttagcompound.hasKey("resultid")){ + resultId = Integer.toString(nbttagcompound.getInteger("resultid")); + satelliteId = Integer.toString(nbttagcompound.getInteger("satelliteid")); + } + blockingMode = BlockingMode.VALUES[Math.abs(nbttagcompound.getByte("blockingMode")) % BlockingMode.VALUES.length]; + } finally { + readingNBT = false; } - blockingMode = BlockingMode.VALUES[Math.abs(nbttagcompound.getByte("blockingMode")) % BlockingMode.VALUES.length]; } @Override public void collectSpecificInterests(Collection itemidCollection) { @@ -543,6 +551,7 @@ public BlockingMode getBlockingMode() { @SideOnly(Side.CLIENT) public IInventory getClientModuleInventory() { + if(clientInv == null)clientInv = new InventoryBasic(null, false, 27); return clientInv; } diff --git a/src/main/java/com/tom/logisticsbridge/tileentity/ICraftingManager.java b/src/main/java/com/tom/logisticsbridge/tileentity/ICraftingManager.java index af1aefc..2174a20 100644 --- a/src/main/java/com/tom/logisticsbridge/tileentity/ICraftingManager.java +++ b/src/main/java/com/tom/logisticsbridge/tileentity/ICraftingManager.java @@ -5,9 +5,11 @@ import net.minecraft.util.math.BlockPos; import com.tom.logisticsbridge.network.SetIDPacket.IIdPipe; +import com.tom.logisticsbridge.pipe.CraftingManager.BlockingMode; public interface ICraftingManager extends IIdPipe { ItemStack satelliteDisplayStack(); Slot createGuiSlot(int i, int x, int y); BlockPos getPosition(); + BlockingMode getBlockingMode(); } diff --git a/src/main/java/com/tom/logisticsbridge/tileentity/TileEntityCraftingManager.java b/src/main/java/com/tom/logisticsbridge/tileentity/TileEntityCraftingManager.java index fdead62..91b9bd7 100644 --- a/src/main/java/com/tom/logisticsbridge/tileentity/TileEntityCraftingManager.java +++ b/src/main/java/com/tom/logisticsbridge/tileentity/TileEntityCraftingManager.java @@ -30,6 +30,7 @@ import com.tom.logisticsbridge.network.SetIDPacket; import com.tom.logisticsbridge.network.SetIDPacket.IIdPipe; import com.tom.logisticsbridge.part.PartSatelliteBus; +import com.tom.logisticsbridge.pipe.CraftingManager.BlockingMode; import appeng.api.config.Actionable; import appeng.api.implementations.ICraftingPatternItem; @@ -50,6 +51,7 @@ import appeng.api.util.DimensionalCoord; import appeng.me.helpers.MachineSource; import appeng.tile.grid.AENetworkInvTile; +import appeng.util.InventoryAdaptor; import appeng.util.SettingsFrom; import appeng.util.inv.InvOperation; import logisticspipes.network.PacketHandler; @@ -66,6 +68,8 @@ public class TileEntityCraftingManager extends AENetworkInvTile implements ITick public InvWrapper wr = new InvWrapper(inv); private IActionSource as = new MachineSource(this); private List toInsert = new ArrayList<>(); + private BlockingMode blockingMode = BlockingMode.OFF; + public TileEntityCraftingManager() { getProxy().setFlags(GridFlags.REQUIRE_CHANNEL); inv.addInventoryChangeListener(this); @@ -76,8 +80,45 @@ public AECableType getCableConnectionType(AEPartLocation aePartLocation) { return AECableType.SMART; } + private boolean checkBlocking() { + switch (blockingMode) { + case EMPTY_MAIN_SATELLITE: + { + if(supplyID.isEmpty())return false; + PartSatelliteBus bus = find(supplyID); + if(bus == null)return false; + InventoryAdaptor inv = bus.getHandler(); + if (inv != null) { + if(inv.containsItems())return false; + } + return true; + } + + case REDSTONE_HIGH: + if(!getWorld().isBlockPowered(getPos()))return false; + return true; + + case REDSTONE_LOW: + if(getWorld().isBlockPowered(getPos()))return false; + return true; + + /*case WAIT_FOR_RESULT://TODO + { + IRouter resultR = getResultRouterByID(getResultUUID()); + if(resultR == null)return false; + if(!(resultR.getPipe() instanceof ResultPipe))return false; + if(((ResultPipe) resultR.getPipe()).hasRequests())return false; + return true; + }*/ + + default: + return true; + } + } + @Override public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table) { + if(!checkBlocking())return false; if(patternDetails instanceof VirtualPatternHandler){ if(toInsert.size() > 10)return false; ItemStack stack = patternDetails.getCondensedOutputs()[0].asItemStackRepresentation(); @@ -142,7 +183,7 @@ public void provideCrafting(ICraftingProviderHelper craftingTracker) { @Override public String getPipeID(int id) { - return supplyID; + return id == 0 ? supplyID : Integer.toString(blockingMode.ordinal()); } @Override @@ -155,16 +196,19 @@ public void setPipeID(int id, String pipeID, EntityPlayer player) { final ModernPacket packet = PacketHandler.getPacket(SetIDPacket.class).setName(pipeID).setId(id).setTilePos(getTile()); MainProxy.sendPacketToPlayer(packet, player); } - supplyID = pipeID; + if(id == 0)supplyID = pipeID; + else if(id == 1)blockingMode = BlockingMode.VALUES[Math.abs(pipeID.charAt(0) - '0') % BlockingMode.VALUES.length]; } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { compound.setString("supplyName", supplyID); + compound.setByte("blockingMode", (byte) blockingMode.ordinal()); return super.writeToNBT(compound); } @Override public void readFromNBT(NBTTagCompound compound) { supplyID = compound.getString("supplyName"); + blockingMode = BlockingMode.VALUES[Math.abs(compound.getByte("blockingMode")) % BlockingMode.VALUES.length]; super.readFromNBT(compound); updateCraftingList(); } @@ -412,4 +456,9 @@ public boolean isItemValid(ItemStack stack) { public BlockPos getPosition() { return pos; } + + @Override + public BlockingMode getBlockingMode() { + return blockingMode; + } } diff --git a/src/main/java/com/tom/logisticsbridge/tileentity/TileEntityCraftingManagerRS.java b/src/main/java/com/tom/logisticsbridge/tileentity/TileEntityCraftingManagerRS.java index 3fab077..0736638 100644 --- a/src/main/java/com/tom/logisticsbridge/tileentity/TileEntityCraftingManagerRS.java +++ b/src/main/java/com/tom/logisticsbridge/tileentity/TileEntityCraftingManagerRS.java @@ -14,6 +14,7 @@ import com.tom.logisticsbridge.RSPlugin; import com.tom.logisticsbridge.node.NetworkNodeCraftingManager; +import com.tom.logisticsbridge.pipe.CraftingManager.BlockingMode; public class TileEntityCraftingManagerRS extends TileNode implements ICraftingManager { @@ -61,4 +62,9 @@ public BlockPos getPosition() { public List list(int id) { return getNode().list(id); } + + @Override + public BlockingMode getBlockingMode() { + return getNode().getBlockingMode(); + } } diff --git a/src/main/resources/assets/logisticsbridge/lang/en_us.lang b/src/main/resources/assets/logisticsbridge/lang/en_us.lang index 4afebc1..9cbcc33 100644 --- a/src/main/resources/assets/logisticsbridge/lang/en_us.lang +++ b/src/main/resources/assets/logisticsbridge/lang/en_us.lang @@ -37,6 +37,8 @@ item.logisticspipes.upgrade_lb.adv_extraction_upgrade.tip1=Works same as ItemSta item.logisticspipes.upgrade_lb.adv_extraction_upgrade.tip2=but works with %cYELLOW Bridge %cRESET %cGRAY and %cYELLOW Result Pipes item.logisticspipes.upgrade_lb.adv_extraction_upgrade.tip3=Added by %cBLUE Logistics Bridge +item.logisticspipes.sign_creator.2.name=Crafting Manager Sign Creator + item.lb.logisticsFakeItem.name=Logistics Craft Token item.lb.package.name=Empty Package item.lb.virtPattern.name=Virtual Encoded Pattern diff --git a/version-check.json b/version-check.json index 876b76d..d2b5489 100644 --- a/version-check.json +++ b/version-check.json @@ -1,10 +1,11 @@ { "homepage": "https://www.curseforge.com/minecraft/mc-mods/logistics-bridge", "promos": { - "1.12.2-latest": "1.3.10", - "1.12.2-recommended": "1.3.10" + "1.12.2-latest": "1.3.11", + "1.12.2-recommended": "1.3.11" }, "1.12.2": { + "1.3.11": "Fixed crash with dedicated servers\nAdded blocking mode to AE and RS Crafting Managers", "1.3.10": "Improved Bridging Logic speed\nAdded support for Sign creator", "1.3.9": "Added blocking mode to Crafting Manager Pipe\nFixed crash with Bridge Pipe\nFixed crash with Crafting Manager Gui\nImproved tooltips", "1.3.8": "Fixed Crafting Buffer Upgrade not sending items correctly",