From fb5bf61efd9ba0a55fe480aa2fee5e7a425ff6a8 Mon Sep 17 00:00:00 2001 From: DrParadox7 Date: Tue, 18 Jun 2024 16:30:36 +0200 Subject: [PATCH 1/4] Limit Jar network to pairs only Refactor Mirrored Jars to only trade in pairs, massively enhancing performance. Also fixes Jar labels being lost on placement --- .../common/blocks/tiles/TileRemoteJar.java | 102 ++++++++++++------ .../common/items/ItemBlockRemoteJar.java | 4 +- 2 files changed, 70 insertions(+), 36 deletions(-) diff --git a/src/main/java/makeo/gadomancy/common/blocks/tiles/TileRemoteJar.java b/src/main/java/makeo/gadomancy/common/blocks/tiles/TileRemoteJar.java index 4dd3272..601aa24 100644 --- a/src/main/java/makeo/gadomancy/common/blocks/tiles/TileRemoteJar.java +++ b/src/main/java/makeo/gadomancy/common/blocks/tiles/TileRemoteJar.java @@ -1,8 +1,6 @@ package makeo.gadomancy.common.blocks.tiles; import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -28,24 +26,45 @@ public class TileRemoteJar extends TileJarFillable { private boolean registered_to_network; + private boolean shouldUpdate() { + return this.count % 3 == 0 && !this.getWorldObj().isRemote + && this.networkId != null + && (!this.registered_to_network || this.amount < this.maxAmount); + } + @Override public void updateEntity() { super.updateEntity(); - if (this.count % 3 == 0 && !this.getWorldObj().isRemote - && this.networkId != null - && (!this.registered_to_network || this.amount < this.maxAmount)) { + + if (shouldUpdate()) { this.count = 0; JarNetwork network = TileRemoteJar.getNetwork(this.networkId); - this.registered_to_network = true; + if (handleNetworkConnections(network)) { + network.update(); + this.registered_to_network = true; + } + } + + this.count++; + } + + private boolean handleNetworkConnections(JarNetwork network) { + int networkCapacity = network.jars.size(); + + // Network requiring jars for operation, registering jar... + if (networkCapacity <= 2) { if (!network.jars.contains(this)) { network.jars.add((TileJarFillable) this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord)); } - network.update(); + return true; } - this.count++; + + this.networkId = null; + this.registered_to_network = false; + return false; } @Override @@ -64,43 +83,56 @@ public void writeCustomNBT(NBTTagCompound compound) { } } - private static Map networks = new HashMap(); + private static final Map networks = new HashMap(); private static class JarNetwork { private long lastTime; - private List jars = new ArrayList(); + private final List jars = new ArrayList(2); private void update() { long time = MinecraftServer.getServer().getEntityWorld().getTotalWorldTime(); if (time > this.lastTime) { - if (this.jars.size() > 1) { - Collections.sort(this.jars, new Comparator() { - - @Override - public int compare(TileJarFillable o1, TileJarFillable o2) { - return o2.amount - o1.amount; - } - }); - - TileJarFillable jar1 = this.jars.get(0); - if (!JarNetwork.isValid(jar1)) { - this.jars.remove(0); - return; - } - - TileJarFillable jar2 = this.jars.get(this.jars.size() - 1); - if (!JarNetwork.isValid(jar2)) { - this.jars.remove(this.jars.size() - 1); - return; - } - - if ((jar2.amount + 1) < jar1.amount && jar2.addToContainer(jar1.aspect, 1) == 0) { - jar1.takeFromContainer(jar1.aspect, 1); - } + + // Not enough jars... + if (this.jars.size() < 2) return; + + // Just enough jars... + if (this.jars.size() == 2) { + if (hasProcessedJars()) this.lastTime = time + 3; + return; + } + + // Too many jars. Refreshing network... + this.jars.clear(); + } + } + + private boolean hasProcessedJars() { + + TileJarFillable jar1 = this.jars.get(0); + if (!JarNetwork.isValid(jars.get(0))) { + this.jars.remove(0); + return false; + } + + TileJarFillable jar2 = this.jars.get(1); + if (!JarNetwork.isValid(jars.get(1))) { + this.jars.remove(1); + return false; + } + + // Transfer Essence if necessary + if (Math.abs(jar1.amount - jar2.amount) > 1) { + + TileJarFillable sourceJar = (jar1.amount > jar2.amount) ? jar1 : jar2; + TileJarFillable destinationJar = (sourceJar == jar1) ? jar2 : jar1; + + if (destinationJar.addToContainer(sourceJar.aspect, 1) == 0) { + sourceJar.takeFromContainer(sourceJar.aspect, 1); } - this.lastTime = time + 3; } + return true; } private static boolean isValid(TileJarFillable jar) { diff --git a/src/main/java/makeo/gadomancy/common/items/ItemBlockRemoteJar.java b/src/main/java/makeo/gadomancy/common/items/ItemBlockRemoteJar.java index 5d449e1..1dcb83e 100644 --- a/src/main/java/makeo/gadomancy/common/items/ItemBlockRemoteJar.java +++ b/src/main/java/makeo/gadomancy/common/items/ItemBlockRemoteJar.java @@ -23,6 +23,7 @@ import makeo.gadomancy.common.registration.RegisteredBlocks; import makeo.gadomancy.common.utils.NBTHelper; import makeo.gadomancy.common.utils.StringHelper; +import thaumcraft.api.aspects.Aspect; import thaumcraft.api.aspects.AspectList; import thaumcraft.common.blocks.ItemJarFilled; import thaumcraft.common.config.ConfigItems; @@ -83,7 +84,7 @@ public boolean onItemUse(ItemStack p_77648_1_, EntityPlayer p_77648_2_, World p_ public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { TileRemoteJar tile = BlockRemoteJar.getJarTile(world, x, y, z); - if (tile != null) { + if (stack.stackSize == 1 && tile != null) { if (!world.isRemote) { NBTTagCompound compound = NBTHelper.getData(stack); if (!player.isSneaking()) { @@ -129,6 +130,7 @@ public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, i if (!world.isRemote) { tile.networkId = NBTHelper.getUUID(stack.getTagCompound(), "networkId"); + tile.aspectFilter = Aspect.getAspect(stack.getTagCompound().getString("AspectFilter")); tile.markForUpdate(); } } From 575c603598ab2b7b2e3d7bd8fe5196730c91a4d7 Mon Sep 17 00:00:00 2001 From: DrParadox7 Date: Fri, 21 Jun 2024 21:25:04 +0200 Subject: [PATCH 2/4] Better Pairing & Overcapacity Checks Pairing of jars always results into a new network, regardless of existing connections either jar had. Networks in overcapacity will simply disconnect jars past the last valid connection rather than all its jars. --- .../common/blocks/tiles/TileRemoteJar.java | 33 ++++++++++++++----- .../common/items/ItemBlockRemoteJar.java | 32 ++++++------------ 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/src/main/java/makeo/gadomancy/common/blocks/tiles/TileRemoteJar.java b/src/main/java/makeo/gadomancy/common/blocks/tiles/TileRemoteJar.java index 601aa24..af07da5 100644 --- a/src/main/java/makeo/gadomancy/common/blocks/tiles/TileRemoteJar.java +++ b/src/main/java/makeo/gadomancy/common/blocks/tiles/TileRemoteJar.java @@ -93,18 +93,17 @@ private static class JarNetwork { private void update() { long time = MinecraftServer.getServer().getEntityWorld().getTotalWorldTime(); if (time > this.lastTime) { + int networkSize = this.jars.size(); - // Not enough jars... - if (this.jars.size() < 2) return; + // Too many jars... + if (networkSize > 2) { + jars.subList(2, jars.size()).clear(); + } // Just enough jars... - if (this.jars.size() == 2) { - if (hasProcessedJars()) this.lastTime = time + 3; - return; + if (networkSize == 2 && hasProcessedJars()) { + this.lastTime = time + 3; } - - // Too many jars. Refreshing network... - this.jars.clear(); } } @@ -152,6 +151,24 @@ private static JarNetwork getNetwork(UUID id) { return network; } + public void disconnectJar(TileRemoteJar jar) { + UUID id = jar.networkId; + + if (id != null) { + JarNetwork network = TileRemoteJar.networks.get(id); + + if (network != null) { + if (network.jars.size() < 2) { + // Network consists of only this Jar. Discarding Network instead + networks.remove(id); + } + + // Discarding Jar from Network + network.jars.remove(jar); + } + } + } + public void markForUpdate() { this.markDirty(); this.getWorldObj().markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); diff --git a/src/main/java/makeo/gadomancy/common/items/ItemBlockRemoteJar.java b/src/main/java/makeo/gadomancy/common/items/ItemBlockRemoteJar.java index 1dcb83e..8cab8f3 100644 --- a/src/main/java/makeo/gadomancy/common/items/ItemBlockRemoteJar.java +++ b/src/main/java/makeo/gadomancy/common/items/ItemBlockRemoteJar.java @@ -85,32 +85,20 @@ public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, float hitX, float hitY, float hitZ) { TileRemoteJar tile = BlockRemoteJar.getJarTile(world, x, y, z); if (stack.stackSize == 1 && tile != null) { - if (!world.isRemote) { + if (!world.isRemote && !player.isSneaking()) { NBTTagCompound compound = NBTHelper.getData(stack); - if (!player.isSneaking()) { - UUID networkId = null; - if (tile.networkId == null) { - player.addChatComponentMessage(new ChatComponentTranslation("gadomancy.info.RemoteJar.new")); - networkId = UUID.randomUUID(); - tile.networkId = networkId; - tile.markForUpdate(); - } else { - UUID current = NBTHelper.getUUID(compound, "networkId"); - if (current == null || !current.equals(tile.networkId)) { - player.addChatComponentMessage( - new ChatComponentTranslation("gadomancy.info.RemoteJar.connected")); - networkId = tile.networkId; - } - } + UUID networkId = UUID.randomUUID(); + + player.addChatComponentMessage(new ChatComponentTranslation("gadomancy.info.RemoteJar.new")); + NBTHelper.setUUID(compound, "networkId", networkId); + + tile.disconnectJar(tile); + tile.networkId = networkId; + tile.markForUpdate(); - if (networkId != null) { - NBTHelper.setUUID(compound, "networkId", networkId); - } - } return true; - } else { - return player.isSneaking(); } + return player.isSneaking(); } return false; } From fbf29910609b5b87e136371df44391801e0218a6 Mon Sep 17 00:00:00 2001 From: DrParadox7 Date: Sun, 15 Dec 2024 07:52:03 +0100 Subject: [PATCH 3/4] Fix Wrong item reference Fixed wrong item reference in Damage Familiar Infusion --- .../makeo/gadomancy/common/registration/RegisteredRecipes.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/makeo/gadomancy/common/registration/RegisteredRecipes.java b/src/main/java/makeo/gadomancy/common/registration/RegisteredRecipes.java index 92dce2d..1ef289b 100644 --- a/src/main/java/makeo/gadomancy/common/registration/RegisteredRecipes.java +++ b/src/main/java/makeo/gadomancy/common/registration/RegisteredRecipes.java @@ -1303,7 +1303,7 @@ private static InfusionRecipe[][] createEtherealFamiliarUpgradeRecipes() { ThaumcraftApi.getCraftingRecipes().add(infusion); (recipes[11])[i] = infusion; - ItemStack balancedShard = new ItemStack(ConfigItems.itemResource, 1, 6); + ItemStack balancedShard = new ItemStack(ConfigItems.itemShard, 1, 6); ItemStack gunpowder = new ItemStack(Items.gunpowder); // Damage 0 -> 1 From 12c0a7fa81c49bd4bba11201f2ac4f1a39d744c8 Mon Sep 17 00:00:00 2001 From: DrParadox7 Date: Sun, 15 Dec 2024 09:37:55 +0100 Subject: [PATCH 4/4] Clarify Modifier Types Familiar Infusions Clarify that Speed, Range and Damage familiar infusions are modifiers that require a valid effect infusion to be applied. As it was worded, it implied these modifiers could be applied to the familiar's base attack, causing players to get unknowingly stuck on invalid infusions attempts. --- src/main/resources/assets/gadomancy/lang/en_US.lang | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/assets/gadomancy/lang/en_US.lang b/src/main/resources/assets/gadomancy/lang/en_US.lang index 14f6b4f..41018bf 100644 --- a/src/main/resources/assets/gadomancy/lang/en_US.lang +++ b/src/main/resources/assets/gadomancy/lang/en_US.lang @@ -76,15 +76,15 @@ gadomancy.research_page.FAMILIAR_WEAKNESS.1=This upgrade removes the familiars d tc.research_name.GADOMANCY.FAMILIAR_DAMAGE=Arc Amplification tc.research_text.GADOMANCY.FAMILIAR_DAMAGE=What does the scouter say about its power level? -gadomancy.research_page.FAMILIAR_DAMAGE.1=By concentrating more arcane energy into the wisp, its attack power is effectively doubled.Consumes 0.03 Ignis vis per attack and level. +gadomancy.research_page.FAMILIAR_DAMAGE.1=By concentrating more arcane energy into the wisp, the potency of its infusion effects is effectively doubled.Consumes 0.03 Ignis vis per attack and level. tc.research_name.GADOMANCY.FAMILIAR_RANGE=Sensitivity Boost tc.research_text.GADOMANCY.FAMILIAR_RANGE=Attacking even further -gadomancy.research_page.FAMILIAR_RANGE.1=By enhancing the wisps sensitivity to external influence, you can slightly increasing its range.Consumes additionally 0.02 Aer vis and 0.01 Ordo vis per attack and level. +gadomancy.research_page.FAMILIAR_RANGE.1=By enhancing the wisps sensitivity to external influence, you can slightly increasing the range of its infusion effects.Consumes additionally 0.02 Aer vis and 0.01 Ordo vis per attack and level. tc.research_name.GADOMANCY.FAMILIAR_SPEED=Frequency Emission Overdrive tc.research_text.GADOMANCY.FAMILIAR_SPEED=A certain scientific Railgun -gadomancy.research_page.FAMILIAR_SPEED.1=Some variants of familiars can have a considerable amount of difficulty dealing with large numbers of foes at once. This upgrade enhances an Ethereal Familiar so that it can attack twice as fast as before. The second stage both increases its attack speed and allows it to hit multiple enemies in a single strike.Consumes 0.02 Ordo and 0.01 Ignis vis per attack and level. +gadomancy.research_page.FAMILIAR_SPEED.1=Some variants of familiars can have a considerable amount of difficulty dealing with large numbers of foes at once. This upgrade enhances an Ethereal Familiar so that it can apply its infusion effects twice as fast as before. The second stage both increases its attack speed and allows it to hit multiple enemies in a single strike.Consumes 0.02 Ordo and 0.01 Ignis vis per attack and level. tc.research_name.GADOMANCY.KNOWLEDGE_BOOK=Book of Knowledge tc.research_text.GADOMANCY.KNOWLEDGE_BOOK=Knowledge is power