diff --git a/Xplat/src/main/java/vazkii/botania/api/mana/spark/ManaSpark.java b/Xplat/src/main/java/vazkii/botania/api/mana/spark/ManaSpark.java index 29a42dc7f4..f38d36c367 100644 --- a/Xplat/src/main/java/vazkii/botania/api/mana/spark/ManaSpark.java +++ b/Xplat/src/main/java/vazkii/botania/api/mana/spark/ManaSpark.java @@ -34,7 +34,7 @@ public interface ManaSpark extends SparkEntity { /** * Gets a collection of all Sparks this is tranfering to. */ - Collection getTransfers(); + Collection getOutgoingTransfers(); /** * Registers the Spark passed in as a Spark meant for mana to be transfered towards. diff --git a/Xplat/src/main/java/vazkii/botania/common/entity/ManaSparkEntity.java b/Xplat/src/main/java/vazkii/botania/common/entity/ManaSparkEntity.java index 933c93288b..88f9502a80 100644 --- a/Xplat/src/main/java/vazkii/botania/common/entity/ManaSparkEntity.java +++ b/Xplat/src/main/java/vazkii/botania/common/entity/ManaSparkEntity.java @@ -57,7 +57,7 @@ public class ManaSparkEntity extends SparkBaseEntity implements ManaSpark { private static final String TAG_UPGRADE = "upgrade"; private static final EntityDataAccessor UPGRADE = SynchedEntityData.defineId(ManaSparkEntity.class, EntityDataSerializers.INT); - private final Set transfers = Collections.newSetFromMap(new WeakHashMap<>()); + private final Set outgoingTransfers = Collections.newSetFromMap(new WeakHashMap<>()); private final ArrayList transfersTowardsSelfToRegister = new ArrayList<>(); @@ -106,7 +106,7 @@ public void tick() { var receiver = getAttachedManaReceiver(); SparkUpgradeType upgrade = getUpgrade(); - Collection transfers = getTransfers(); + Collection transfers = getOutgoingTransfers(); switch (upgrade) { case DISPERSIVE -> { @@ -176,7 +176,7 @@ public void tick() { updateTransfers(); } if (!transfersTowardsSelfToRegister.isEmpty()) { - transfersTowardsSelfToRegister.remove(0).registerTransfer(this); + transfersTowardsSelfToRegister.remove(transfersTowardsSelfToRegister.size() - 1).registerTransfer(this); } } // Recessive does not need to be handled because recessive sparks get notified in all relevant cases @@ -228,6 +228,7 @@ public void tick() { @Override public void updateTransfers() { + transfersTowardsSelfToRegister.clear(); switch (getUpgrade()) { case RECESSIVE -> { var otherSparks = SparkHelper.getSparksAround(level(), getX(), getY() + (getBbHeight() / 2), getZ(), getNetwork()); @@ -238,7 +239,7 @@ public void updateTransfers() { && otherUpgrade != SparkUpgradeType.DOMINANT && otherUpgrade != SparkUpgradeType.RECESSIVE && otherUpgrade != SparkUpgradeType.ISOLATED) { - transfers.add(otherSpark); + outgoingTransfers.add(otherSpark); } } } @@ -301,7 +302,7 @@ public InteractionResult interact(Player player, InteractionHand hand) { setUpgrade(SparkUpgradeType.NONE); // Recalculate transfers, recessive and dominant will register the proper transfers - transfers.clear(); + outgoingTransfers.clear(); notifyOthers(getNetwork()); } else { dropAndKill(); @@ -363,7 +364,7 @@ public ManaReceiver getAttachedManaReceiver() { } private void filterTransfers() { - Iterator iter = transfers.iterator(); + Iterator iter = outgoingTransfers.iterator(); while (iter.hasNext()) { ManaSpark spark = iter.next(); SparkUpgradeType upgr = getUpgrade(); @@ -385,12 +386,12 @@ private void filterTransfers() { } @Override - public Collection getTransfers() { - return transfers; + public Collection getOutgoingTransfers() { + return outgoingTransfers; } private boolean hasTransfer(ManaSpark entity) { - return transfers.contains(entity); + return outgoingTransfers.contains(entity); } @Override @@ -398,7 +399,7 @@ public void registerTransfer(ManaSpark entity) { if (hasTransfer(entity)) { return; } - transfers.add(entity); + outgoingTransfers.add(entity); filterTransfers(); }