Sparks now properly check against how much space is left on the target block and don't try to put in more mana than available, actually making spark networks viable. Closes #433

This commit is contained in:
Lizbeth Rika committed 2014-12-23 21:46:42 +00:00
1 parent 26e6e70b7e
commit b8a4b0c282
6 files changed
+28 -3

No files matched your search

@@ -31,6 +31,12 @@ public interface ISparkAttachable extends IManaReceiver {
*/
public void attachSpark(ISparkEntity entity);
/**
* Returns how much space for mana is available in this block, normally the total - the current.
* Should NEVER return negative values. Make sure to check against that.
*/
public int getAvailableSpaceForMana();
/**
* Gets the Spark that is attached to this block. A common implementation is
* to check for Spark entities above:
@@ -1,4 +1,4 @@
@API(owner = "Botania", apiVersion = "27", provides = "BotaniaAPI")
@API(owner = "Botania", apiVersion = "28", provides = "BotaniaAPI")
package vazkii.botania.api;
import cpw.mods.fml.common.API;
@@ -393,4 +393,9 @@ public class TileEnchanter extends TileMod implements ISparkAttachable {
return stage == 3;
}
@Override
public int getAvailableSpaceForMana() {
return Math.max(0, manaRequired - getCurrentMana());
}
}
@@ -218,4 +218,9 @@ public class TileTerraPlate extends TileMod implements ISparkAttachable {
return !areItemsValid(getItems());
}
@Override
public int getAvailableSpaceForMana() {
return Math.max(0, MAX_MANA - getCurrentMana());
}
}
@@ -361,4 +361,9 @@ public class TilePool extends TileMod implements IManaPool, IKeyLocked, ISparkAt
public boolean areIncomingTranfersDone() {
return false;
}
@Override
public int getAvailableSpaceForMana() {
return Math.max(0, manaCap - getCurrentMana());
}
}
@@ -185,6 +185,8 @@ public class EntitySpark extends Entity implements ISparkEntity {
if(!transfers.isEmpty()) {
int manaTotal = Math.min(TRANSFER_RATE * transfers.size(), tile.getCurrentMana());
int manaForEach = manaTotal / transfers.size();
int manaSpent = 0;
if(manaForEach > transfers.size()) {
for(ISparkEntity spark : transfers) {
if(spark.getAttachedTile() == null || spark.getAttachedTile().isFull() || spark.areIncomingTransfersDone()) {
@@ -193,11 +195,13 @@ public class EntitySpark extends Entity implements ISparkEntity {
}
ISparkAttachable attached = spark.getAttachedTile();
attached.recieveMana(manaForEach);
int spend = Math.min(attached.getAvailableSpaceForMana(), manaForEach);
attached.recieveMana(spend);
manaSpent += spend;
particlesTowards((Entity) spark);
}
tile.recieveMana(-manaTotal);
tile.recieveMana(-manaSpent);
}
}