Fix Dispersed Strikes

1. This fixes up the successiveStrikes counter. Previously it relies on a transient id to remember whether this is the same target. This id will not survive chunk unloads. It also cannot distinguish between second strike and third or fourth strike. 
  To prevent runaway effect the successiveStrikes counter is capped at 5.
2. It changes the algorithm used by Dispersed Strikes to a more reasonable one.
This commit is contained in:
Glease authored and GitHub committed 2020-10-09 12:46:12 +08:00
1 parent 52f872b6ad
commit c8fdb5747f
1 file changed
+12 -12
@@ -36,10 +36,12 @@ import thaumic.tinkerer.common.lib.LibEnchantIDs;
import java.util.List;
import java.util.Random;
import java.util.UUID;
public class ModEnchantmentHandler {
public final String NBTLastTarget = "TTEnchantLastTarget";
public final String NBTLastTarget2 = "TTEnchantLastTarget2";
public final String NBTSuccessiveStrike = "TTEnchantSuccessiveStrike";
@@ -92,29 +94,27 @@ public class ModEnchantmentHandler {
if (heldItem.stackTagCompound == null) {
heldItem.stackTagCompound = new NBTTagCompound();
}
int lastTarget = heldItem.stackTagCompound.getInteger(NBTLastTarget);
UUID lastTarget = new UUID(heldItem.stackTagCompound.getLong(NBTLastTarget), heldItem.stackTagCompound.getLong(NBTLastTarget2));
int successiveStrikes = heldItem.stackTagCompound.getInteger(NBTSuccessiveStrike);
int entityId = event.entityLiving.getEntityId();
UUID entityId = event.entityLiving.getUniqueID();
if (lastTarget != entityId) {
heldItem.stackTagCompound.setInteger(NBTSuccessiveStrike, 0);
if (!lastTarget.equals(entityId)) {
successiveStrikes = 0;
heldItem.stackTagCompound.setLong(NBTLastTarget, entityId.getMostSignificantBits());
heldItem.stackTagCompound.setLong(NBTLastTarget2, entityId.getLeastSignificantBits());
} else {
heldItem.stackTagCompound.setInteger(NBTSuccessiveStrike, successiveStrikes + 1);
successiveStrikes = 1;
successiveStrikes = Math.max(successiveStrikes + 1, 5);
}
heldItem.stackTagCompound.setInteger(NBTSuccessiveStrike, successiveStrikes);
if (focusedStrikes > 0) {
event.ammount /= 2;
event.ammount += (.5 * successiveStrikes * event.ammount * focusedStrikes);
event.ammount += (.5 * Math.max(successiveStrikes, 5) * event.ammount * focusedStrikes);
}
if (dispersedStrikes > 0) {
event.ammount *= 1 + (successiveStrikes / 5);
event.ammount /= (1 + (successiveStrikes * 2));
event.ammount *= 1 + 0.6 * dispersedStrikes + (successiveStrikes / 5);
event.ammount /= 1 + 0.25 * dispersedStrikes + (successiveStrikes * 2.5);
}
heldItem.stackTagCompound.setInteger("TTEnchantLastTarget", entityId);
}
int vampirism = EnchantmentHelper.getEnchantmentLevel(LibEnchantIDs.idVampirism, heldItem);