SoulTicket internal implementation (#1372)

* Fix the Blood Tank BB

* Add modid to command localizations to prevent conflicts

* Fixed the items not being drawn on the right Y-level for the Sigil of Holding HUD
Corrected localizations of other lang files

* SoulTicket internal implementation

* do what TehNut says

* implement hashCode()

* Fix toggleable sigils draining on r-click when it shouldn't
Also moved the ItemSigil and ItemSigilToggleable to the sigil package (why wasn't it there???)
This commit is contained in:
Arcaratus 2018-08-07 18:27:12 -04:00 committed by Nick Ignoffo
parent 093cfb13ef
commit b441e7fc1e
56 changed files with 210 additions and 147 deletions

View file

@ -33,6 +33,10 @@ public class SoulNetwork implements INBTSerializable<NBTTagCompound> {
ticketHistory = EvictingQueue.create(16);
}
public void clear() {
ticketHistory.clear();
}
public int add(SoulTicket ticket, int maximum) {
SoulNetworkEvent.Fill event = new SoulNetworkEvent.Fill(this, ticket, maximum);
if (MinecraftForge.EVENT_BUS.post(event))
@ -46,7 +50,11 @@ public class SoulNetwork implements INBTSerializable<NBTTagCompound> {
int newEss = Math.min(event.getMaximum(), currEss + event.getTicket().getAmount());
setCurrentEssence(newEss);
if (ticketHistory.contains(ticket))
ticketHistory.remove(ticket); // "Pops" the existing ticket to the top of the queue
ticketHistory.add(ticket);
return newEss - currEss;
}
@ -78,6 +86,9 @@ public class SoulNetwork implements INBTSerializable<NBTTagCompound> {
int syphon = event.getTicket().getAmount();
if (getCurrentEssence() >= syphon) {
setCurrentEssence(getCurrentEssence() - syphon);
if (ticketHistory.contains(ticket))
ticketHistory.remove(ticket);
ticketHistory.add(ticket);
return syphon;
}
@ -107,7 +118,11 @@ public class SoulNetwork implements INBTSerializable<NBTTagCompound> {
if (drainAmount <= 0 || event.shouldDamage())
hurtPlayer(user, event.getTicket().getAmount());
if (ticketHistory.contains(ticket))
ticketHistory.remove(ticket);
ticketHistory.add(ticket);
return BooleanResult.newResult(true, event.getTicket().getAmount());
}

View file

@ -1,7 +1,12 @@
package WayofTime.bloodmagic.core.data;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
public class SoulTicket {
@ -30,4 +35,51 @@ public class SoulTicket {
public int getAmount() {
return amount;
}
/**
* @return A description in the format block|dimensionID|pos
*/
public static SoulTicket block(World world, BlockPos pos, int amount) {
return new SoulTicket(new TextComponentString("block|" + world.provider.getDimension() + "|" + pos.toLong()), amount);
}
/**
* @return A description in the format item|item registry name|dimensionID|entityName|entityPos
*/
public static SoulTicket item(ItemStack itemStack, World world, Entity entity, int amount) {
return new SoulTicket(new TextComponentString("item|" + itemStack.getItem().getRegistryName() + "|" + world.provider.getDimension() + "|" + entity.getPersistentID()), amount);
}
/**
* @return A description in the format item|item registry name|dimensionID|pos
*/
public static SoulTicket item(ItemStack itemStack, World world, BlockPos pos, int amount) {
return new SoulTicket(new TextComponentString("item|" + itemStack.getItem().getRegistryName() + "|" + world.provider.getDimension() + "|" + pos.toLong()), amount);
}
/**
* @return A description in the format item|item registry name|dimensionID
*/
public static SoulTicket item(ItemStack itemStack, int amount) {
return new SoulTicket(new TextComponentString("item|" + itemStack.getItem().getRegistryName()), amount);
}
public static SoulTicket command(ICommandSender sender, String command, int amount) {
return new SoulTicket(new TextComponentString("command|" + command + "|" + sender.getName()), amount);
}
// TODO maybe make it check the amount??
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o instanceof SoulTicket)
return ((SoulTicket) o).getDescription().equals(description);
return false;
}
@Override
public int hashCode() {
return description.hashCode();
}
}