Rewrite IBindable to provide an object instead of storing 2 strings

This commit is contained in:
Nicholas Ignoffo 2018-02-27 16:59:51 -08:00
parent 941173dbf4
commit 2a43e53842
47 changed files with 416 additions and 510 deletions

View file

@ -4,6 +4,8 @@ import WayofTime.bloodmagic.api.event.BloodMagicCraftedEvent;
import WayofTime.bloodmagic.api.impl.BloodMagicAPI; import WayofTime.bloodmagic.api.impl.BloodMagicAPI;
import WayofTime.bloodmagic.api.impl.recipe.RecipeBloodAltar; import WayofTime.bloodmagic.api.impl.recipe.RecipeBloodAltar;
import WayofTime.bloodmagic.block.enums.BloodRuneType; import WayofTime.bloodmagic.block.enums.BloodRuneType;
import WayofTime.bloodmagic.core.data.Binding;
import WayofTime.bloodmagic.iface.IBindable;
import WayofTime.bloodmagic.iface.IBloodRune; import WayofTime.bloodmagic.iface.IBloodRune;
import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.util.Constants;
import WayofTime.bloodmagic.orb.BloodOrb; import WayofTime.bloodmagic.orb.BloodOrb;
@ -329,27 +331,21 @@ public class BloodAltar implements IFluidHandler {
} }
} }
} else { } else {
ItemStack returnedItem = tileAltar.getStackInSlot(0); ItemStack contained = tileAltar.getStackInSlot(0);
if (returnedItem.isEmpty() || !(returnedItem.getItem() instanceof IBloodOrb)) if (contained.isEmpty() || !(contained.getItem() instanceof IBloodOrb) || !(contained.getItem() instanceof IBindable))
return; return;
IBloodOrb item = (IBloodOrb) (returnedItem.getItem()); BloodOrb orb = ((IBloodOrb) contained.getItem()).getOrb(contained);
NBTTagCompound itemTag = returnedItem.getTagCompound(); Binding binding = ((IBindable) contained.getItem()).getBinding(contained);
if (itemTag == null) if (binding == null || orb == null)
return;
String ownerUUID = itemTag.getString(Constants.NBT.OWNER_UUID);
if (Strings.isNullOrEmpty(ownerUUID))
return; return;
if (fluid != null && fluid.amount >= 1) { if (fluid != null && fluid.amount >= 1) {
int liquidDrained = Math.min((int) (altarTier.ordinal() >= 2 ? consumptionRate * (1 + consumptionMultiplier) : consumptionRate), fluid.amount); int liquidDrained = Math.min((int) (altarTier.ordinal() >= 2 ? orb.getFillRate() * (1 + consumptionMultiplier) : orb.getFillRate()), fluid.amount);
BloodOrb orb = item.getOrb(returnedItem); int drain = NetworkHelper.getSoulNetwork(binding).add(liquidDrained, (int) (orb.getCapacity() * this.orbCapacityMultiplier));
int drain = orb == null ? 0 : NetworkHelper.getSoulNetwork(ownerUUID).add(liquidDrained, (int) (orb.getCapacity() * this.orbCapacityMultiplier));
fluid.amount = fluid.amount - drain; fluid.amount = fluid.amount - drain;
if (drain > 0 && internalCounter % 4 == 0 && world instanceof WorldServer) { if (drain > 0 && internalCounter % 4 == 0 && world instanceof WorldServer) {

View file

@ -5,6 +5,7 @@ import WayofTime.bloodmagic.altar.BloodAltar;
import WayofTime.bloodmagic.altar.EnumAltarComponent; import WayofTime.bloodmagic.altar.EnumAltarComponent;
import WayofTime.bloodmagic.altar.IAltarManipulator; import WayofTime.bloodmagic.altar.IAltarManipulator;
import WayofTime.bloodmagic.altar.IBloodAltar; import WayofTime.bloodmagic.altar.IBloodAltar;
import WayofTime.bloodmagic.core.data.Binding;
import WayofTime.bloodmagic.iface.IAltarReader; import WayofTime.bloodmagic.iface.IAltarReader;
import WayofTime.bloodmagic.iface.IBindable; import WayofTime.bloodmagic.iface.IBindable;
import WayofTime.bloodmagic.iface.IDocumentedBlock; import WayofTime.bloodmagic.iface.IDocumentedBlock;
@ -15,7 +16,6 @@ import WayofTime.bloodmagic.util.helper.NetworkHelper;
import WayofTime.bloodmagic.client.IVariantProvider; import WayofTime.bloodmagic.client.IVariantProvider;
import WayofTime.bloodmagic.tile.TileAltar; import WayofTime.bloodmagic.tile.TileAltar;
import WayofTime.bloodmagic.util.Utils; import WayofTime.bloodmagic.util.Utils;
import com.google.common.base.Strings;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
@ -68,9 +68,9 @@ public class BlockAltar extends Block implements IVariantProvider, IDocumentedBl
if (world.getBlockState(pos.down()).getBlock() instanceof BlockDecorative) { if (world.getBlockState(pos.down()).getBlock() instanceof BlockDecorative) {
if (orbStack.getItem() instanceof IBloodOrb && orbStack.getItem() instanceof IBindable) { if (orbStack.getItem() instanceof IBloodOrb && orbStack.getItem() instanceof IBindable) {
BloodOrb orb = ((IBloodOrb) orbStack.getItem()).getOrb(orbStack); BloodOrb orb = ((IBloodOrb) orbStack.getItem()).getOrb(orbStack);
IBindable bindable = (IBindable) orbStack.getItem(); Binding binding = ((IBindable) orbStack.getItem()).getBinding(orbStack);
if (orb != null && !Strings.isNullOrEmpty(bindable.getOwnerUUID(orbStack))) { if (orb != null && binding != null) {
SoulNetwork soulNetwork = NetworkHelper.getSoulNetwork(bindable.getOwnerUUID(orbStack)); SoulNetwork soulNetwork = NetworkHelper.getSoulNetwork(binding);
int maxEssence = orb.getCapacity(); int maxEssence = orb.getCapacity();
int currentEssence = soulNetwork.getCurrentEssence(); int currentEssence = soulNetwork.getCurrentEssence();

View file

@ -50,8 +50,7 @@ public class BlockRitualController extends BlockEnum<EnumRitualController> imple
if (state.getValue(getProperty()) != EnumRitualController.IMPERFECT && tile instanceof TileMasterRitualStone) { if (state.getValue(getProperty()) != EnumRitualController.IMPERFECT && tile instanceof TileMasterRitualStone) {
if (heldItem.getItem() == RegistrarBloodMagicItems.ACTIVATION_CRYSTAL) { if (heldItem.getItem() == RegistrarBloodMagicItems.ACTIVATION_CRYSTAL) {
IBindable bindable = (IBindable) heldItem.getItem(); if (((IBindable) heldItem.getItem()).getBinding(heldItem) == null)
if (Strings.isNullOrEmpty(bindable.getOwnerName(heldItem)))
return false; return false;
String key = RitualHelper.getValidRitual(world, pos); String key = RitualHelper.getValidRitual(world, pos);

View file

@ -197,7 +197,7 @@ public class GuiItemRoutingNode extends GuiContainer {
// { // {
// if (slotInd == 0) // if (slotInd == 0)
// { // {
// this.nameField.setText(stack == null ? "" : stack.getDisplayName()); // this.nameField.setText(stack == null ? "" : stack.getOwnerName());
// this.nameField.setEnabled(stack != null); // this.nameField.setEnabled(stack != null);
// //
// if (stack != null) // if (stack != null)

View file

@ -1,5 +1,6 @@
package WayofTime.bloodmagic.command.sub; package WayofTime.bloodmagic.command.sub;
import WayofTime.bloodmagic.core.data.Binding;
import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.util.Constants;
import WayofTime.bloodmagic.iface.IBindable; import WayofTime.bloodmagic.iface.IBindable;
import WayofTime.bloodmagic.util.helper.BindableHelper; import WayofTime.bloodmagic.util.helper.BindableHelper;
@ -38,8 +39,6 @@ public class SubCommandBind extends CommandBase {
try { try {
EntityPlayer player = CommandBase.getCommandSenderAsPlayer(commandSender); EntityPlayer player = CommandBase.getCommandSenderAsPlayer(commandSender);
String playerName = player.getName();
String uuid = PlayerHelper.getUUIDFromPlayer(player).toString();
ItemStack held = player.getHeldItemMainhand(); ItemStack held = player.getHeldItemMainhand();
boolean bind = true; boolean bind = true;
@ -53,21 +52,20 @@ public class SubCommandBind extends CommandBase {
bind = Boolean.parseBoolean(args[0]); bind = Boolean.parseBoolean(args[0]);
if (args.length > 2) if (args.length > 2)
playerName = args[1]; player = CommandBase.getPlayer(server, commandSender, args[1]);
} else { } else {
playerName = args[0]; player = CommandBase.getPlayer(server, commandSender, args[0]);
uuid = PlayerHelper.getUUIDFromPlayer(CommandBase.getPlayer(server, commandSender, playerName)).toString();
} }
} }
if (bind) { if (bind) {
BindableHelper.setItemOwnerName(held, playerName); Binding binding = new Binding(player.getGameProfile().getId(), player.getGameProfile().getName());
BindableHelper.setItemOwnerUUID(held, uuid); BindableHelper.applyBinding(held, binding);
commandSender.sendMessage(new TextComponentTranslation("commands.bind.success")); commandSender.sendMessage(new TextComponentTranslation("commands.bind.success"));
} else { } else {
if (!Strings.isNullOrEmpty(((IBindable) held.getItem()).getOwnerUUID(held))) { Binding binding = ((IBindable) held.getItem()).getBinding(held);
held.getTagCompound().removeTag(Constants.NBT.OWNER_UUID); if (binding != null) {
held.getTagCompound().removeTag(Constants.NBT.OWNER_NAME); held.getTagCompound().removeTag("binding");
commandSender.sendMessage(new TextComponentTranslation("commands.bind.remove.success")); commandSender.sendMessage(new TextComponentTranslation("commands.bind.remove.success"));
} }
} }

View file

@ -63,7 +63,7 @@ public class DataProviderRitualController implements IWailaDataProvider {
if (mrs.getCurrentRitual() != null) { if (mrs.getCurrentRitual() != null) {
tag.setString("ritual", mrs.getCurrentRitual().getUnlocalizedName()); tag.setString("ritual", mrs.getCurrentRitual().getUnlocalizedName());
tag.setBoolean("active", mrs.isActive()); tag.setBoolean("active", mrs.isActive());
if (!Strings.isNullOrEmpty(mrs.getOwner())) if (mrs.getOwner() != null)
tag.setString("owner", PlayerHelper.getUsernameFromUUID(mrs.getOwner())); tag.setString("owner", PlayerHelper.getUsernameFromUUID(mrs.getOwner()));
tag.setBoolean("enabled", RitualRegistry.ritualEnabled(mrs.getCurrentRitual())); tag.setBoolean("enabled", RitualRegistry.ritualEnabled(mrs.getCurrentRitual()));
} }

View file

@ -30,18 +30,19 @@ import net.minecraftforge.registries.RegistryBuilder;
@GameRegistry.ObjectHolder(BloodMagic.MODID) @GameRegistry.ObjectHolder(BloodMagic.MODID)
public class RegistrarBloodMagic { public class RegistrarBloodMagic {
private static final BloodOrb ORB_DEF = new BloodOrb("", 0, 0, 0);
@GameRegistry.ObjectHolder("weak") @GameRegistry.ObjectHolder("weak")
public static final BloodOrb ORB_WEAK = new BloodOrb("", 0, 0); public static final BloodOrb ORB_WEAK = ORB_DEF;
@GameRegistry.ObjectHolder("apprentice") @GameRegistry.ObjectHolder("apprentice")
public static final BloodOrb ORB_APPRENTICE = new BloodOrb("", 0, 0); public static final BloodOrb ORB_APPRENTICE = ORB_DEF;
@GameRegistry.ObjectHolder("magician") @GameRegistry.ObjectHolder("magician")
public static final BloodOrb ORB_MAGICIAN = new BloodOrb("", 0, 0); public static final BloodOrb ORB_MAGICIAN = ORB_DEF;
@GameRegistry.ObjectHolder("master") @GameRegistry.ObjectHolder("master")
public static final BloodOrb ORB_MASTER = new BloodOrb("", 0, 0); public static final BloodOrb ORB_MASTER = ORB_DEF;
@GameRegistry.ObjectHolder("archmage") @GameRegistry.ObjectHolder("archmage")
public static final BloodOrb ORB_ARCHMAGE = new BloodOrb("", 0, 0); public static final BloodOrb ORB_ARCHMAGE = ORB_DEF;
@GameRegistry.ObjectHolder("transcendent") @GameRegistry.ObjectHolder("transcendent")
public static final BloodOrb ORB_TRANSCENDENT = new BloodOrb("", 0, 0); public static final BloodOrb ORB_TRANSCENDENT = ORB_DEF;
public static final Potion BOOST = MobEffects.HASTE; public static final Potion BOOST = MobEffects.HASTE;
public static final Potion WHIRLWIND = MobEffects.HASTE; public static final Potion WHIRLWIND = MobEffects.HASTE;
@ -62,12 +63,12 @@ public class RegistrarBloodMagic {
public static void registerBloodOrbs(RegistryEvent.Register<BloodOrb> event) { public static void registerBloodOrbs(RegistryEvent.Register<BloodOrb> event) {
ResourceLocation orb = RegistrarBloodMagicItems.BLOOD_ORB.getRegistryName(); ResourceLocation orb = RegistrarBloodMagicItems.BLOOD_ORB.getRegistryName();
event.getRegistry().registerAll( event.getRegistry().registerAll(
new BloodOrb("weak", 1, 5000).withModel(new ModelResourceLocation(orb, "type=weak")).setRegistryName("weak"), new BloodOrb("weak", 1, 5000, 2).withModel(new ModelResourceLocation(orb, "type=weak")).setRegistryName("weak"),
new BloodOrb("apprentice", 2, 25000).withModel(new ModelResourceLocation(orb, "type=apprentice")).setRegistryName("apprentice"), new BloodOrb("apprentice", 2, 25000, 5).withModel(new ModelResourceLocation(orb, "type=apprentice")).setRegistryName("apprentice"),
new BloodOrb("magician", 3, 150000).withModel(new ModelResourceLocation(orb, "type=magician")).setRegistryName("magician"), new BloodOrb("magician", 3, 150000, 15).withModel(new ModelResourceLocation(orb, "type=magician")).setRegistryName("magician"),
new BloodOrb("master", 4, 1000000).withModel(new ModelResourceLocation(orb, "type=master")).setRegistryName("master"), new BloodOrb("master", 4, 1000000, 25).withModel(new ModelResourceLocation(orb, "type=master")).setRegistryName("master"),
new BloodOrb("archmage", 5, 10000000).withModel(new ModelResourceLocation(orb, "type=archmage")).setRegistryName("archmage"), new BloodOrb("archmage", 5, 10000000, 50).withModel(new ModelResourceLocation(orb, "type=archmage")).setRegistryName("archmage"),
new BloodOrb("transcendent", 6, 30000000).withModel(new ModelResourceLocation(orb, "type=transcendent")).setRegistryName("transcendent") new BloodOrb("transcendent", 6, 30000000, 50).withModel(new ModelResourceLocation(orb, "type=transcendent")).setRegistryName("transcendent")
); );
} }

View file

@ -0,0 +1,71 @@
package WayofTime.bloodmagic.core.data;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTUtil;
import net.minecraftforge.common.util.INBTSerializable;
import javax.annotation.Nullable;
import java.util.UUID;
public class Binding implements INBTSerializable<NBTTagCompound> {
private UUID uuid;
private String name;
public Binding(UUID uuid, String name) {
this.uuid = uuid;
this.name = name;
}
private Binding() {
// No-op
}
@Override
public NBTTagCompound serializeNBT() {
NBTTagCompound tag = new NBTTagCompound();
tag.setTag("id", NBTUtil.createUUIDTag(uuid));
tag.setString("name", name);
return tag;
}
@Override
public void deserializeNBT(NBTTagCompound nbt) {
this.uuid = NBTUtil.getUUIDFromTag(nbt.getCompoundTag("id"));
this.name = nbt.getString("name");
}
public UUID getOwnerId() {
return uuid;
}
public Binding setOwnerId(UUID uuid) {
this.uuid = uuid;
return this;
}
public String getOwnerName() {
return name;
}
public Binding setOwnerName(String name) {
this.name = name;
return this;
}
@Nullable
public static Binding fromStack(ItemStack stack) {
if (!stack.hasTagCompound()) // Definitely hasn't been bound yet.
return null;
NBTBase bindingTag = stack.getTagCompound().getTag("binding");
if (bindingTag == null || bindingTag.getId() != 10 || bindingTag.hasNoTags()) // Make sure it's both a tag compound and that it has actual data.
return null;
Binding binding = new Binding();
binding.deserializeNBT((NBTTagCompound) bindingTag);
return binding;
}
}

View file

@ -1,6 +1,5 @@
package WayofTime.bloodmagic.core.data; package WayofTime.bloodmagic.core.data;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.util.BMLog; import WayofTime.bloodmagic.util.BMLog;
import WayofTime.bloodmagic.util.PleaseStopUsingMe; import WayofTime.bloodmagic.util.PleaseStopUsingMe;
import WayofTime.bloodmagic.event.AddToNetworkEvent; import WayofTime.bloodmagic.event.AddToNetworkEvent;
@ -74,7 +73,7 @@ public class SoulNetwork implements INBTSerializable<NBTTagCompound> {
return false; return false;
if (!Strings.isNullOrEmpty(playerId.toString())) { if (!Strings.isNullOrEmpty(playerId.toString())) {
SoulNetworkEvent.ItemDrainNetworkEvent event = new SoulNetworkEvent.ItemDrainNetworkEvent(user, playerId.toString(), null, toSyphon); SoulNetworkEvent.ItemDrainNetworkEvent event = new SoulNetworkEvent.ItemDrainNetworkEvent(user, playerId, null, toSyphon);
if (MinecraftForge.EVENT_BUS.post(event)) if (MinecraftForge.EVENT_BUS.post(event))
return false; return false;

View file

@ -7,24 +7,29 @@ import net.minecraftforge.fml.common.eventhandler.Event;
@Cancelable @Cancelable
public class ItemBindEvent extends Event { public class ItemBindEvent extends Event {
public final EntityPlayer player;
public String key; private final EntityPlayer player;
public ItemStack itemStack; private final ItemStack itemStack;
/** /**
* This event is called whenever a player attempts to bind a * This event is called whenever a player attempts to bind a
* {@link WayofTime.bloodmagic.iface.IBindable} item. * {@link WayofTime.bloodmagic.iface.IBindable} item.
* *
* @param player The player doing the binding * @param player The player doing the binding
* @param key The UUID of the player doing the binding
* @param itemStack The {@link ItemStack} that the player is binding * @param itemStack The {@link ItemStack} that the player is binding
* <p> * <p>
* This event is {@link Cancelable}.<br> * This event is {@link Cancelable}.<br>
*/ */
public ItemBindEvent(EntityPlayer player, String key, ItemStack itemStack) { public ItemBindEvent(EntityPlayer player, ItemStack itemStack) {
super();
this.player = player; this.player = player;
this.key = key;
this.itemStack = itemStack; this.itemStack = itemStack;
} }
public EntityPlayer getNewOwner() {
return player;
}
public ItemStack getBindingStack() {
return itemStack;
}
} }

View file

@ -10,14 +10,16 @@ import net.minecraft.world.World;
import net.minecraftforge.fml.common.eventhandler.Cancelable; import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event; import net.minecraftforge.fml.common.eventhandler.Event;
import java.util.UUID;
public class RitualEvent extends Event { public class RitualEvent extends Event {
public final IMasterRitualStone mrs; public final IMasterRitualStone mrs;
public final String ownerName; public final UUID ownerId;
public final Ritual ritual; public final Ritual ritual;
private RitualEvent(IMasterRitualStone mrs, String ownerName, Ritual ritual) { private RitualEvent(IMasterRitualStone mrs, UUID ownerId, Ritual ritual) {
this.mrs = mrs; this.mrs = mrs;
this.ownerName = ownerName; this.ownerId = ownerId;
this.ritual = ritual; this.ritual = ritual;
} }
@ -33,8 +35,8 @@ public class RitualEvent extends Event {
public final ItemStack crystalStack; public final ItemStack crystalStack;
public int crystalTier; public int crystalTier;
public RitualActivatedEvent(IMasterRitualStone mrs, String owner, Ritual ritual, EntityPlayer player, ItemStack activationCrystal, int crystalTier) { public RitualActivatedEvent(IMasterRitualStone mrs, UUID ownerId, Ritual ritual, EntityPlayer player, ItemStack activationCrystal, int crystalTier) {
super(mrs, owner, ritual); super(mrs, ownerId, ritual);
this.player = player; this.player = player;
this.crystalStack = activationCrystal; this.crystalStack = activationCrystal;
@ -50,8 +52,8 @@ public class RitualEvent extends Event {
*/ */
@Cancelable @Cancelable
public static class RitualRunEvent extends RitualEvent { public static class RitualRunEvent extends RitualEvent {
public RitualRunEvent(IMasterRitualStone mrs, String owner, Ritual ritual) { public RitualRunEvent(IMasterRitualStone mrs, UUID ownerId, Ritual ritual) {
super(mrs, owner, ritual); super(mrs, ownerId, ritual);
} }
} }
@ -65,8 +67,8 @@ public class RitualEvent extends Event {
public final Ritual.BreakType method; public final Ritual.BreakType method;
public RitualStopEvent(IMasterRitualStone mrs, String owner, Ritual ritual, Ritual.BreakType method) { public RitualStopEvent(IMasterRitualStone mrs, UUID ownerId, Ritual ritual, Ritual.BreakType method) {
super(mrs, owner, ritual); super(mrs, ownerId, ritual);
this.method = method; this.method = method;
} }
@ -76,12 +78,12 @@ public class RitualEvent extends Event {
public static class ImperfectRitualActivatedEvent extends Event { public static class ImperfectRitualActivatedEvent extends Event {
public final IImperfectRitualStone ims; public final IImperfectRitualStone ims;
public final String ownerName; public final UUID ownerId;
public final ImperfectRitual imperfectRitual; public final ImperfectRitual imperfectRitual;
public ImperfectRitualActivatedEvent(IImperfectRitualStone ims, String ownerName, ImperfectRitual imperfectRitual) { public ImperfectRitualActivatedEvent(IImperfectRitualStone ims, UUID ownerId, ImperfectRitual imperfectRitual) {
this.ims = ims; this.ims = ims;
this.ownerName = ownerName; this.ownerId = ownerId;
this.imperfectRitual = imperfectRitual; this.imperfectRitual = imperfectRitual;
} }
} }

View file

@ -6,6 +6,7 @@ import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event; import net.minecraftforge.fml.common.eventhandler.Event;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.UUID;
/** /**
* Base event class for Soul Network related events. * Base event class for Soul Network related events.
@ -14,17 +15,17 @@ import javax.annotation.Nullable;
* amount of LP to be drained * amount of LP to be drained
*/ */
public class SoulNetworkEvent extends Event { public class SoulNetworkEvent extends Event {
public final String ownerUUID; public final UUID ownerUUID;
public int syphon; public int syphon;
public SoulNetworkEvent(String ownerUUID, int syphon) { public SoulNetworkEvent(UUID ownerUUID, int syphon) {
this.ownerUUID = ownerUUID; this.ownerUUID = ownerUUID;
this.syphon = syphon; this.syphon = syphon;
} }
/** /**
* This event is called when an * This event is called when an
* {@link WayofTime.bloodmagic.apibutnotreally.impl.ItemBindable} is being drained * {@link WayofTime.bloodmagic.iface.IBindable} is being drained
* inside of a {@link net.minecraft.tileentity.TileEntity}. * inside of a {@link net.minecraft.tileentity.TileEntity}.
* <p> * <p>
* If canceled, the drain will not be executed. * If canceled, the drain will not be executed.
@ -33,8 +34,8 @@ public class SoulNetworkEvent extends Event {
public static class ItemDrainInContainerEvent extends SoulNetworkEvent { public static class ItemDrainInContainerEvent extends SoulNetworkEvent {
public ItemStack stack; public ItemStack stack;
public ItemDrainInContainerEvent(ItemStack stack, String ownerName, int syphon) { public ItemDrainInContainerEvent(ItemStack stack, UUID ownerId, int syphon) {
super(ownerName, syphon); super(ownerId, syphon);
this.stack = stack; this.stack = stack;
} }
} }
@ -50,8 +51,8 @@ public class SoulNetworkEvent extends Event {
// If true, will damage regardless of if the network had enough inside it // If true, will damage regardless of if the network had enough inside it
public boolean shouldDamage; public boolean shouldDamage;
public PlayerDrainNetworkEvent(EntityPlayer player, String ownerNetwork, int drainAmount) { public PlayerDrainNetworkEvent(EntityPlayer player, UUID ownerId, int drainAmount) {
super(ownerNetwork, drainAmount); super(ownerId, drainAmount);
this.shouldDamage = false; this.shouldDamage = false;
this.player = player; this.player = player;
} }
@ -72,12 +73,12 @@ public class SoulNetworkEvent extends Event {
* event prevents action without penalties * event prevents action without penalties
* *
* @param player Player using the item * @param player Player using the item
* @param ownerNetwork Network that the item is tied to * @param ownerId Network that the item is tied to
* @param itemStack Item used * @param itemStack Item used
* @param drainAmount Original drain amount - change to alter cost * @param drainAmount Original drain amount - change to alter cost
*/ */
public ItemDrainNetworkEvent(EntityPlayer player, String ownerNetwork, @Nullable ItemStack itemStack, int drainAmount) { public ItemDrainNetworkEvent(EntityPlayer player, UUID ownerId, @Nullable ItemStack itemStack, int drainAmount) {
super(player, ownerNetwork, drainAmount); super(player, ownerId, drainAmount);
this.itemStack = itemStack; this.itemStack = itemStack;
this.damageAmount = (float) (drainAmount) / 100.0f; this.damageAmount = (float) (drainAmount) / 100.0f;
} }

View file

@ -1,9 +1,26 @@
package WayofTime.bloodmagic.iface; package WayofTime.bloodmagic.iface;
import WayofTime.bloodmagic.util.Constants;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import javax.annotation.Nonnull;
public interface IActivatable { public interface IActivatable {
boolean getActivated(ItemStack stack);
ItemStack setActivatedState(ItemStack stack, boolean activated); default boolean getActivated(ItemStack stack) {
return !stack.isEmpty() && stack.hasTagCompound() && stack.getTagCompound().getBoolean(Constants.NBT.ACTIVATED);
}
@Nonnull
default ItemStack setActivatedState(ItemStack stack, boolean activated) {
if (!stack.isEmpty()) {
if (!stack.hasTagCompound())
stack.setTagCompound(new NBTTagCompound());
stack.getTagCompound().setBoolean(Constants.NBT.ACTIVATED, activated);
}
return stack;
}
} }

View file

@ -1,37 +1,28 @@
package WayofTime.bloodmagic.iface; package WayofTime.bloodmagic.iface;
import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.core.data.Binding;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import javax.annotation.Nullable;
/** /**
* Implement this interface on any Item that can be bound to a player. * Implement this interface on any Item that can be bound to a player.
*/ */
public interface IBindable { public interface IBindable {
/** /**
* Gets the username of the Item's owner. Usually for display, such as in * Gets an object that stores who this item is bound to.
* the tooltip.
* <p> * <p>
* If the item is not bound, this will be null. * If the item is not bound, this will be null.
* *
* @param stack - The owned ItemStack * @param stack - The owned ItemStack
* @return - The username of the Item's owner * @return - The binding object
*/ */
default String getOwnerName(ItemStack stack) { @Nullable
return !stack.isEmpty() && stack.hasTagCompound() ? stack.getTagCompound().getString(Constants.NBT.OWNER_NAME) : null; default Binding getBinding(ItemStack stack) {
} Binding binding = Binding.fromStack(stack);
return !stack.isEmpty() && binding != null ? binding : null;
/**
* Gets the UUID of the Item's owner.
* <p>
* If the item is not bound, this will be null.
*
* @param stack - The owned ItemStack
* @return - The UUID of the Item's owner
*/
default String getOwnerUUID(ItemStack stack) {
return !stack.isEmpty() && stack.hasTagCompound() ? stack.getTagCompound().getString(Constants.NBT.OWNER_UUID) : null;
} }
/** /**

View file

@ -1,12 +1,11 @@
package WayofTime.bloodmagic.item; package WayofTime.bloodmagic.item;
import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.core.data.Binding;
import WayofTime.bloodmagic.iface.IBindable; import WayofTime.bloodmagic.iface.IBindable;
import WayofTime.bloodmagic.util.helper.PlayerHelper;
import WayofTime.bloodmagic.core.RegistrarBloodMagicItems; import WayofTime.bloodmagic.core.RegistrarBloodMagicItems;
import WayofTime.bloodmagic.item.types.ISubItem; import WayofTime.bloodmagic.item.types.ISubItem;
import WayofTime.bloodmagic.util.helper.TextHelper; import WayofTime.bloodmagic.util.helper.TextHelper;
import com.google.common.base.Strings;
import net.minecraft.client.util.ITooltipFlag; import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -34,8 +33,9 @@ public class ItemActivationCrystal extends ItemEnum.Variant<ItemActivationCrysta
if (!stack.hasTagCompound()) if (!stack.hasTagCompound())
return; return;
if (!Strings.isNullOrEmpty(getOwnerUUID(stack))) Binding binding = getBinding(stack);
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", PlayerHelper.getUsernameFromStack(stack))); if (binding != null)
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", binding.getOwnerName()));
super.addInformation(stack, world, tooltip, flag); super.addInformation(stack, world, tooltip, flag);
} }

View file

@ -1,10 +1,9 @@
package WayofTime.bloodmagic.item; package WayofTime.bloodmagic.item;
import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.core.data.Binding;
import WayofTime.bloodmagic.iface.IBindable; import WayofTime.bloodmagic.iface.IBindable;
import WayofTime.bloodmagic.util.helper.PlayerHelper;
import WayofTime.bloodmagic.util.helper.TextHelper; import WayofTime.bloodmagic.util.helper.TextHelper;
import com.google.common.base.Strings;
import net.minecraft.client.util.ITooltipFlag; import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -28,7 +27,8 @@ public class ItemBindableBase extends Item implements IBindable {
if (!stack.hasTagCompound()) if (!stack.hasTagCompound())
return; return;
if (!Strings.isNullOrEmpty(getOwnerUUID(stack))) Binding binding = getBinding(stack);
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", PlayerHelper.getUsernameFromStack(stack))); if (binding != null)
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", binding.getOwnerName()));
} }
} }

View file

@ -1,13 +1,14 @@
package WayofTime.bloodmagic.item; package WayofTime.bloodmagic.item;
import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.core.data.Binding;
import WayofTime.bloodmagic.core.data.SoulNetwork;
import WayofTime.bloodmagic.orb.BloodOrb; import WayofTime.bloodmagic.orb.BloodOrb;
import WayofTime.bloodmagic.orb.IBloodOrb; import WayofTime.bloodmagic.orb.IBloodOrb;
import WayofTime.bloodmagic.util.helper.NetworkHelper; import WayofTime.bloodmagic.util.helper.NetworkHelper;
import WayofTime.bloodmagic.util.helper.PlayerHelper; import WayofTime.bloodmagic.util.helper.PlayerHelper;
import WayofTime.bloodmagic.core.RegistrarBloodMagic; import WayofTime.bloodmagic.core.RegistrarBloodMagic;
import WayofTime.bloodmagic.util.helper.TextHelper; import WayofTime.bloodmagic.util.helper.TextHelper;
import com.google.common.base.Strings;
import net.minecraft.client.util.ITooltipFlag; import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@ -68,21 +69,22 @@ public class ItemBloodOrb extends ItemBindableBase implements IBloodOrb {
if (PlayerHelper.isFakePlayer(player)) if (PlayerHelper.isFakePlayer(player))
return super.onItemRightClick(world, player, hand); return super.onItemRightClick(world, player, hand);
if (!stack.hasTagCompound()) { if (!stack.hasTagCompound())
return super.onItemRightClick(world, player, hand); return super.onItemRightClick(world, player, hand);
}
if (Strings.isNullOrEmpty(getOwnerUUID(stack))) Binding binding = getBinding(stack);
if (binding == null)
return super.onItemRightClick(world, player, hand); return super.onItemRightClick(world, player, hand);
if (world.isRemote) if (world.isRemote)
return super.onItemRightClick(world, player, hand); return super.onItemRightClick(world, player, hand);
if (getOwnerUUID(stack).equals(PlayerHelper.getUsernameFromPlayer(player))) SoulNetwork ownerNetwork = NetworkHelper.getSoulNetwork(binding);
NetworkHelper.setMaxOrb(NetworkHelper.getSoulNetwork(getOwnerUUID(stack)), orb.getTier()); if (binding.getOwnerId().equals(player.getGameProfile().getId()))
ownerNetwork.setOrbTier(orb.getTier());
NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).add(200, orb.getCapacity()); ownerNetwork.add(200, orb.getCapacity()); // Add LP to owner's network
NetworkHelper.getSoulNetwork(player).hurtPlayer(player, 200); ownerNetwork.hurtPlayer(player, 200); // Hurt whoever is using it
return super.onItemRightClick(world, player, hand); return super.onItemRightClick(world, player, hand);
} }

View file

@ -1,18 +1,15 @@
package WayofTime.bloodmagic.item; package WayofTime.bloodmagic.item;
import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.core.data.Binding;
import WayofTime.bloodmagic.iface.IActivatable; import WayofTime.bloodmagic.iface.IActivatable;
import WayofTime.bloodmagic.iface.IBindable; import WayofTime.bloodmagic.iface.IBindable;
import WayofTime.bloodmagic.util.helper.NBTHelper;
import WayofTime.bloodmagic.util.helper.NetworkHelper; import WayofTime.bloodmagic.util.helper.NetworkHelper;
import WayofTime.bloodmagic.util.helper.PlayerHelper;
import WayofTime.bloodmagic.client.IMeshProvider; import WayofTime.bloodmagic.client.IMeshProvider;
import WayofTime.bloodmagic.client.mesh.CustomMeshDefinitionActivatable; import WayofTime.bloodmagic.client.mesh.CustomMeshDefinitionActivatable;
import WayofTime.bloodmagic.core.RegistrarBloodMagicItems; import WayofTime.bloodmagic.core.RegistrarBloodMagicItems;
import WayofTime.bloodmagic.util.Utils; import WayofTime.bloodmagic.util.Utils;
import WayofTime.bloodmagic.util.helper.TextHelper; import WayofTime.bloodmagic.util.helper.TextHelper;
import com.google.common.base.Strings;
import com.google.common.collect.HashMultimap; import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
@ -69,13 +66,14 @@ public class ItemBoundSword extends ItemSword implements IBindable, IActivatable
@Override @Override
public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) { public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) {
if (Strings.isNullOrEmpty(getOwnerUUID(stack))) { Binding binding = getBinding(stack);
if (binding == null) {
setActivatedState(stack, false); setActivatedState(stack, false);
return; return;
} }
if (entity instanceof EntityPlayer && getActivated(stack) && world.getTotalWorldTime() % 80 == 0) if (entity instanceof EntityPlayer && getActivated(stack) && world.getTotalWorldTime() % 80 == 0)
NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage((EntityPlayer) entity, 20); NetworkHelper.getSoulNetwork(binding).syphonAndDamage((EntityPlayer) entity, 20);
} }
@Override @Override
@ -113,8 +111,9 @@ public class ItemBoundSword extends ItemSword implements IBindable, IActivatable
tooltip.add(TextHelper.localize("tooltip.bloodmagic." + (getActivated(stack) ? "activated" : "deactivated"))); tooltip.add(TextHelper.localize("tooltip.bloodmagic." + (getActivated(stack) ? "activated" : "deactivated")));
if (!Strings.isNullOrEmpty(getOwnerUUID(stack))) Binding binding = getBinding(stack);
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", PlayerHelper.getUsernameFromStack(stack))); if (binding != null)
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", binding.getOwnerName()));
} }
@Override @Override
@ -146,38 +145,4 @@ public class ItemBoundSword extends ItemSword implements IBindable, IActivatable
ret.add("active=false"); ret.add("active=false");
return ret; return ret;
} }
// IBindable
@Override
public boolean onBind(EntityPlayer player, ItemStack stack) {
return true;
}
@Override
public String getOwnerName(ItemStack stack) {
return stack != null ? NBTHelper.checkNBT(stack).getTagCompound().getString(Constants.NBT.OWNER_NAME) : null;
}
@Override
public String getOwnerUUID(ItemStack stack) {
return stack != null ? NBTHelper.checkNBT(stack).getTagCompound().getString(Constants.NBT.OWNER_UUID) : null;
}
// IActivatable
@Override
public boolean getActivated(ItemStack stack) {
return stack != null && NBTHelper.checkNBT(stack).getTagCompound().getBoolean(Constants.NBT.ACTIVATED);
}
@Override
public ItemStack setActivatedState(ItemStack stack, boolean activated) {
if (stack != null) {
NBTHelper.checkNBT(stack).getTagCompound().setBoolean(Constants.NBT.ACTIVATED, activated);
return stack;
}
return null;
}
} }

View file

@ -1,18 +1,15 @@
package WayofTime.bloodmagic.item; package WayofTime.bloodmagic.item;
import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.core.data.Binding;
import WayofTime.bloodmagic.util.ItemStackWrapper; import WayofTime.bloodmagic.util.ItemStackWrapper;
import WayofTime.bloodmagic.event.BoundToolEvent; import WayofTime.bloodmagic.event.BoundToolEvent;
import WayofTime.bloodmagic.iface.IActivatable; import WayofTime.bloodmagic.iface.IActivatable;
import WayofTime.bloodmagic.iface.IBindable; import WayofTime.bloodmagic.iface.IBindable;
import WayofTime.bloodmagic.util.helper.NBTHelper;
import WayofTime.bloodmagic.util.helper.NetworkHelper; import WayofTime.bloodmagic.util.helper.NetworkHelper;
import WayofTime.bloodmagic.util.helper.PlayerHelper;
import WayofTime.bloodmagic.core.RegistrarBloodMagicItems; import WayofTime.bloodmagic.core.RegistrarBloodMagicItems;
import WayofTime.bloodmagic.util.Utils; import WayofTime.bloodmagic.util.Utils;
import WayofTime.bloodmagic.util.helper.TextHelper; import WayofTime.bloodmagic.util.helper.TextHelper;
import com.google.common.base.Strings;
import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
@ -82,7 +79,8 @@ public class ItemBoundTool extends ItemTool implements IBindable, IActivatable {
@Override @Override
public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) { public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) {
if (Strings.isNullOrEmpty(getOwnerUUID(stack))) { Binding binding = getBinding(stack);
if (binding == null) {
setActivatedState(stack, false); setActivatedState(stack, false);
return; return;
} }
@ -95,7 +93,7 @@ public class ItemBoundTool extends ItemTool implements IBindable, IActivatable {
} }
if (entity instanceof EntityPlayer && getActivated(stack) && world.getTotalWorldTime() % 80 == 0) if (entity instanceof EntityPlayer && getActivated(stack) && world.getTotalWorldTime() % 80 == 0)
NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage((EntityPlayer) entity, 20); NetworkHelper.getSoulNetwork(binding).syphonAndDamage((EntityPlayer) entity, 20);
} }
protected int getHeldDownCount(ItemStack stack) { protected int getHeldDownCount(ItemStack stack) {
@ -191,8 +189,9 @@ public class ItemBoundTool extends ItemTool implements IBindable, IActivatable {
if (!stack.hasTagCompound()) if (!stack.hasTagCompound())
return; return;
if (!Strings.isNullOrEmpty(getOwnerUUID(stack))) Binding binding = getBinding(stack);
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", PlayerHelper.getUsernameFromStack(stack))); if (binding != null)
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", binding.getOwnerName()));
super.addInformation(stack, world, tooltip, flag); super.addInformation(stack, world, tooltip, flag);
} }
@ -216,40 +215,6 @@ public class ItemBoundTool extends ItemTool implements IBindable, IActivatable {
return ((double) -Math.min(getHeldDownCount(stack), chargeTime) / chargeTime) + 1; return ((double) -Math.min(getHeldDownCount(stack), chargeTime) / chargeTime) + 1;
} }
@Override
public String getOwnerName(ItemStack stack) {
return stack != null ? NBTHelper.checkNBT(stack).getTagCompound().getString(Constants.NBT.OWNER_NAME) : null;
}
// IBindable
@Override
public String getOwnerUUID(ItemStack stack) {
return stack != null ? NBTHelper.checkNBT(stack).getTagCompound().getString(Constants.NBT.OWNER_UUID) : null;
}
@Override
public boolean onBind(EntityPlayer player, ItemStack stack) {
return true;
}
@Override
public boolean getActivated(ItemStack stack) {
return stack != null && NBTHelper.checkNBT(stack).getTagCompound().getBoolean(Constants.NBT.ACTIVATED);
}
// IActivatable
@Override
public ItemStack setActivatedState(ItemStack stack, boolean activated) {
if (stack != null) {
NBTHelper.checkNBT(stack).getTagCompound().setBoolean(Constants.NBT.ACTIVATED, activated);
return stack;
}
return null;
}
public String getTooltipBase() { public String getTooltipBase() {
return tooltipBase; return tooltipBase;
} }

View file

@ -1,13 +1,12 @@
package WayofTime.bloodmagic.item; package WayofTime.bloodmagic.item;
import WayofTime.bloodmagic.core.data.Binding;
import WayofTime.bloodmagic.iface.IBindable; import WayofTime.bloodmagic.iface.IBindable;
import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.util.Constants;
import WayofTime.bloodmagic.ritual.data.EnumRuneType; import WayofTime.bloodmagic.ritual.data.EnumRuneType;
import WayofTime.bloodmagic.util.helper.NBTHelper; import WayofTime.bloodmagic.util.helper.NBTHelper;
import WayofTime.bloodmagic.block.BlockRitualStone; import WayofTime.bloodmagic.block.BlockRitualStone;
import WayofTime.bloodmagic.util.helper.PlayerHelper;
import WayofTime.bloodmagic.util.helper.TextHelper; import WayofTime.bloodmagic.util.helper.TextHelper;
import com.google.common.base.Strings;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.client.util.ITooltipFlag; import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
@ -101,7 +100,8 @@ public class ItemInscriptionTool extends ItemEnum.Variant<EnumRuneType> implemen
if (!stack.hasTagCompound()) if (!stack.hasTagCompound())
return; return;
if (!Strings.isNullOrEmpty(getOwnerUUID(stack))) Binding binding = getBinding(stack);
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", PlayerHelper.getUsernameFromStack(stack))); if (binding != null)
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", binding.getOwnerName()));
} }
} }

View file

@ -1,6 +1,7 @@
package WayofTime.bloodmagic.item; package WayofTime.bloodmagic.item;
import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.core.data.Binding;
import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.util.Constants;
import WayofTime.bloodmagic.util.helper.NetworkHelper; import WayofTime.bloodmagic.util.helper.NetworkHelper;
import WayofTime.bloodmagic.util.helper.PlayerHelper; import WayofTime.bloodmagic.util.helper.PlayerHelper;
@ -13,39 +14,42 @@ import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect; import net.minecraft.potion.PotionEffect;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nullable;
import java.util.List; import java.util.List;
public class ItemLavaCrystal extends ItemBindableBase implements IVariantProvider { public class ItemLavaCrystal extends ItemBindableBase implements IVariantProvider {
public ItemLavaCrystal() { public ItemLavaCrystal() {
super(); super();
setUnlocalizedName(BloodMagic.MODID + ".lavaCrystal"); setUnlocalizedName(BloodMagic.MODID + ".lavaCrystal");
} }
@Override @Override
public ItemStack getContainerItem(ItemStack itemStack) { public ItemStack getContainerItem(ItemStack stack) {
String uuid = getOwnerUUID(itemStack); Binding binding = getBinding(stack);
if (!Strings.isNullOrEmpty(uuid)) if (binding != null)
NetworkHelper.getSoulNetwork(uuid).syphon(25); NetworkHelper.getSoulNetwork(binding.getOwnerId()).syphon(25);
ItemStack returnStack = new ItemStack(this); ItemStack returnStack = new ItemStack(this);
returnStack.setTagCompound(itemStack.getTagCompound()); returnStack.setTagCompound(stack.getTagCompound());
return returnStack; return returnStack;
} }
@Override @Override
public boolean hasContainerItem(ItemStack itemStack) { public boolean hasContainerItem(ItemStack stack) {
return true; return true;
} }
@Override @Override
public int getItemBurnTime(ItemStack stack) { public int getItemBurnTime(ItemStack stack) {
if (Strings.isNullOrEmpty(getOwnerUUID(stack))) Binding binding = getBinding(stack);
if (binding == null)
return -1; return -1;
if (NetworkHelper.canSyphonFromContainer(stack, 25)) if (NetworkHelper.canSyphonFromContainer(stack, 25))
return 200; return 200;
else { else {
EntityPlayer player = PlayerHelper.getPlayerFromUUID(getOwnerUUID(stack)); EntityPlayer player = PlayerHelper.getPlayerFromUUID(binding.getOwnerId());
if (player != null) if (player != null)
player.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 99)); player.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 99));
} }
@ -53,14 +57,10 @@ public class ItemLavaCrystal extends ItemBindableBase implements IVariantProvide
return -1; return -1;
} }
@Nullable
@Override @Override
public String getOwnerName(ItemStack stack) { public Binding getBinding(ItemStack stack) {
return stack.hasTagCompound() ? stack.getTagCompound().getString(Constants.NBT.OWNER_NAME) : null; return Binding.fromStack(stack);
}
@Override
public String getOwnerUUID(ItemStack stack) {
return stack.hasTagCompound() ? stack.getTagCompound().getString(Constants.NBT.OWNER_UUID) : null;
} }
@Override @Override

View file

@ -1,12 +1,12 @@
package WayofTime.bloodmagic.item; package WayofTime.bloodmagic.item;
import WayofTime.bloodmagic.core.data.Binding;
import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.util.Constants;
import WayofTime.bloodmagic.iface.IActivatable; import WayofTime.bloodmagic.iface.IActivatable;
import WayofTime.bloodmagic.iface.ISigil; import WayofTime.bloodmagic.iface.ISigil;
import WayofTime.bloodmagic.util.helper.NBTHelper; import WayofTime.bloodmagic.util.helper.NBTHelper;
import WayofTime.bloodmagic.util.helper.NetworkHelper; import WayofTime.bloodmagic.util.helper.NetworkHelper;
import WayofTime.bloodmagic.util.helper.PlayerHelper; import WayofTime.bloodmagic.util.helper.PlayerHelper;
import com.google.common.base.Strings;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
@ -22,6 +22,7 @@ import net.minecraft.world.World;
* Base class for all toggleable sigils. * Base class for all toggleable sigils.
*/ */
public class ItemSigilToggleable extends ItemSigil implements IActivatable { public class ItemSigilToggleable extends ItemSigil implements IActivatable {
public ItemSigilToggleable(int lpUsed) { public ItemSigilToggleable(int lpUsed) {
super(lpUsed); super(lpUsed);
} }
@ -64,10 +65,12 @@ public class ItemSigilToggleable extends ItemSigil implements IActivatable {
ItemStack stack = player.getHeldItem(hand); ItemStack stack = player.getHeldItem(hand);
if (stack.getItem() instanceof ISigil.Holding) if (stack.getItem() instanceof ISigil.Holding)
stack = ((Holding) stack.getItem()).getHeldItem(stack, player); stack = ((Holding) stack.getItem()).getHeldItem(stack, player);
if (Strings.isNullOrEmpty(getOwnerUUID(stack)) || player.isSneaking()) // Make sure Sigils are bound before handling. Also ignores while toggling state
Binding binding = getBinding(stack);
if (binding == null || player.isSneaking()) // Make sure Sigils are bound before handling. Also ignores while toggling state
return EnumActionResult.PASS; return EnumActionResult.PASS;
return (NetworkHelper.getSoulNetwork(getOwnerUUID(player.getHeldItem(hand))).syphonAndDamage(player, getLpUsed()) && onSigilUse(player.getHeldItem(hand), player, world, pos, side, hitX, hitY, hitZ)) ? EnumActionResult.SUCCESS : EnumActionResult.FAIL; return (NetworkHelper.getSoulNetwork(binding).syphonAndDamage(player, getLpUsed()) && onSigilUse(player.getHeldItem(hand), player, world, pos, side, hitX, hitY, hitZ)) ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
} }
public boolean onSigilUse(ItemStack itemStack, EntityPlayer player, World world, BlockPos blockPos, EnumFacing side, float hitX, float hitY, float hitZ) { public boolean onSigilUse(ItemStack itemStack, EntityPlayer player, World world, BlockPos blockPos, EnumFacing side, float hitX, float hitY, float hitZ) {
@ -78,7 +81,7 @@ public class ItemSigilToggleable extends ItemSigil implements IActivatable {
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
if (!worldIn.isRemote && entityIn instanceof EntityPlayerMP && getActivated(stack)) { if (!worldIn.isRemote && entityIn instanceof EntityPlayerMP && getActivated(stack)) {
if (entityIn.ticksExisted % 100 == 0) { if (entityIn.ticksExisted % 100 == 0) {
if (!NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage((EntityPlayer) entityIn, getLpUsed())) { if (!NetworkHelper.getSoulNetwork(getBinding(stack)).syphonAndDamage((EntityPlayer) entityIn, getLpUsed())) {
setActivatedState(stack, false); setActivatedState(stack, false);
} }
} }

View file

@ -1,5 +1,6 @@
package WayofTime.bloodmagic.item; package WayofTime.bloodmagic.item;
import WayofTime.bloodmagic.core.data.Binding;
import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.util.Constants;
import WayofTime.bloodmagic.iface.IBindable; import WayofTime.bloodmagic.iface.IBindable;
import WayofTime.bloodmagic.util.helper.NBTHelper; import WayofTime.bloodmagic.util.helper.NBTHelper;
@ -51,11 +52,13 @@ public class ItemTelepositionFocus extends ItemEnum.Variant<ItemTelepositionFocu
tooltip.addAll(Arrays.asList(TextHelper.cutLongString(TextHelper.localize("tooltip.bloodmagic.telepositionFocus." + getItemType(stack).getInternalName())))); tooltip.addAll(Arrays.asList(TextHelper.cutLongString(TextHelper.localize("tooltip.bloodmagic.telepositionFocus." + getItemType(stack).getInternalName()))));
super.addInformation(stack, world, tooltip, flag); super.addInformation(stack, world, tooltip, flag);
Binding binding = getBinding(stack);
if (binding != null)
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", binding.getOwnerName()));
if (!stack.hasTagCompound()) if (!stack.hasTagCompound())
return; return;
stack = NBTHelper.checkNBT(stack);
NBTTagCompound tag = stack.getTagCompound(); NBTTagCompound tag = stack.getTagCompound();
BlockPos coords = getBlockPos(stack); BlockPos coords = getBlockPos(stack);

View file

@ -51,7 +51,7 @@ public class ItemSigilAir extends ItemSigilBase implements ISentientSwordEffectP
if (!world.isRemote) { if (!world.isRemote) {
if (!player.capabilities.isCreativeMode) if (!player.capabilities.isCreativeMode)
this.setUnusable(stack, !NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed())); this.setUnusable(stack, !NetworkHelper.getSoulNetwork(getBinding(stack)).syphonAndDamage(player, getLpUsed()));
if (!unusable) if (!unusable)
player.fallDistance = 0; player.fallDistance = 0;

View file

@ -1,6 +1,7 @@
package WayofTime.bloodmagic.item.sigil; package WayofTime.bloodmagic.item.sigil;
import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.core.data.Binding;
import WayofTime.bloodmagic.item.ItemSigil; import WayofTime.bloodmagic.item.ItemSigil;
import WayofTime.bloodmagic.util.helper.PlayerHelper; import WayofTime.bloodmagic.util.helper.PlayerHelper;
import WayofTime.bloodmagic.client.IVariantProvider; import WayofTime.bloodmagic.client.IVariantProvider;
@ -18,6 +19,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
public class ItemSigilBase extends ItemSigil implements IVariantProvider { public class ItemSigilBase extends ItemSigil implements IVariantProvider {
protected final String tooltipBase; protected final String tooltipBase;
private final String name; private final String name;
@ -44,8 +46,9 @@ public class ItemSigilBase extends ItemSigil implements IVariantProvider {
if (!stack.hasTagCompound()) if (!stack.hasTagCompound())
return; return;
if (!Strings.isNullOrEmpty(getOwnerName(stack))) Binding binding = getBinding(stack);
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", PlayerHelper.getUsernameFromStack(stack))); if (binding != null)
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", binding.getOwnerName()));
super.addInformation(stack, world, tooltip, flag); super.addInformation(stack, world, tooltip, flag);
} }

View file

@ -1,5 +1,6 @@
package WayofTime.bloodmagic.item.sigil; package WayofTime.bloodmagic.item.sigil;
import WayofTime.bloodmagic.core.data.SoulNetwork;
import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.util.Constants;
import WayofTime.bloodmagic.iface.ISigil; import WayofTime.bloodmagic.iface.ISigil;
import WayofTime.bloodmagic.util.helper.NBTHelper; import WayofTime.bloodmagic.util.helper.NBTHelper;
@ -41,13 +42,14 @@ public class ItemSigilBloodLight extends ItemSigilBase {
if (getCooldownRemainder(stack) > 0) if (getCooldownRemainder(stack) > 0)
return super.onItemRightClick(world, player, hand); return super.onItemRightClick(world, player, hand);
SoulNetwork network = NetworkHelper.getSoulNetwork(getBinding(stack));
if (mop != null && mop.typeOfHit == RayTraceResult.Type.BLOCK) { if (mop != null && mop.typeOfHit == RayTraceResult.Type.BLOCK) {
BlockPos blockPos = mop.getBlockPos().offset(mop.sideHit); BlockPos blockPos = mop.getBlockPos().offset(mop.sideHit);
if (world.isAirBlock(blockPos)) { if (world.isAirBlock(blockPos)) {
world.setBlockState(blockPos, RegistrarBloodMagicBlocks.BLOOD_LIGHT.getDefaultState()); world.setBlockState(blockPos, RegistrarBloodMagicBlocks.BLOOD_LIGHT.getDefaultState());
if (!world.isRemote) if (!world.isRemote)
NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed()); network.syphonAndDamage(player, getLpUsed());
resetCooldown(stack); resetCooldown(stack);
player.swingArm(hand); player.swingArm(hand);
return super.onItemRightClick(world, player, hand); return super.onItemRightClick(world, player, hand);
@ -55,7 +57,7 @@ public class ItemSigilBloodLight extends ItemSigilBase {
} else { } else {
if (!world.isRemote) { if (!world.isRemote) {
world.spawnEntity(new EntityBloodLight(world, player)); world.spawnEntity(new EntityBloodLight(world, player));
NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed()); network.syphonAndDamage(player, getLpUsed());
} }
resetCooldown(stack); resetCooldown(stack);
} }

View file

@ -1,21 +1,21 @@
package WayofTime.bloodmagic.item.sigil; package WayofTime.bloodmagic.item.sigil;
import WayofTime.bloodmagic.core.data.Binding;
import WayofTime.bloodmagic.iface.IAltarReader; import WayofTime.bloodmagic.iface.IAltarReader;
import WayofTime.bloodmagic.iface.ISigil; import WayofTime.bloodmagic.iface.ISigil;
import WayofTime.bloodmagic.util.helper.NetworkHelper; import WayofTime.bloodmagic.util.helper.NetworkHelper;
import WayofTime.bloodmagic.util.helper.PlayerHelper; import WayofTime.bloodmagic.util.helper.PlayerHelper;
import WayofTime.bloodmagic.util.ChatUtil; import WayofTime.bloodmagic.util.ChatUtil;
import com.google.common.collect.Lists;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World; import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public class ItemSigilDivination extends ItemSigilBase implements IAltarReader { public class ItemSigilDivination extends ItemSigilBase implements IAltarReader {
@ -35,13 +35,12 @@ public class ItemSigilDivination extends ItemSigilBase implements IAltarReader {
if (!world.isRemote) { if (!world.isRemote) {
super.onItemRightClick(world, player, hand); super.onItemRightClick(world, player, hand);
RayTraceResult rayTrace = rayTrace(world, player, false); Binding binding = getBinding(stack);
if (binding != null) {
if (rayTrace == null) { int currentEssence = NetworkHelper.getSoulNetwork(binding).getCurrentEssence();
int currentEssence = NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).getCurrentEssence(); List<ITextComponent> toSend = Lists.newArrayList();
List<ITextComponent> toSend = new ArrayList<ITextComponent>(); if (!binding.getOwnerId().equals(player.getGameProfile().getId()))
if (!getOwnerName(stack).equals(PlayerHelper.getUsernameFromPlayer(player))) toSend.add(new TextComponentTranslation(tooltipBase + "otherNetwork", binding.getOwnerName()));
toSend.add(new TextComponentTranslation(tooltipBase + "otherNetwork", getOwnerName(stack)));
toSend.add(new TextComponentTranslation(tooltipBase + "currentEssence", currentEssence)); toSend.add(new TextComponentTranslation(tooltipBase + "currentEssence", currentEssence));
ChatUtil.sendNoSpam(player, toSend.toArray(new ITextComponent[toSend.size()])); ChatUtil.sendNoSpam(player, toSend.toArray(new ITextComponent[toSend.size()]));
} }

View file

@ -11,7 +11,6 @@ import WayofTime.bloodmagic.client.key.IKeybindable;
import WayofTime.bloodmagic.client.key.KeyBindings; import WayofTime.bloodmagic.client.key.KeyBindings;
import WayofTime.bloodmagic.util.Utils; import WayofTime.bloodmagic.util.Utils;
import WayofTime.bloodmagic.util.helper.TextHelper; import WayofTime.bloodmagic.util.helper.TextHelper;
import com.google.common.base.Strings;
import net.minecraft.client.util.ITooltipFlag; import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@ -90,7 +89,7 @@ public class ItemSigilHolding extends ItemSigilBase implements IKeybindable, IAl
List<ItemStack> inv = getInternalInventory(stack); List<ItemStack> inv = getInternalInventory(stack);
ItemStack itemUsing = inv.get(currentSlot); ItemStack itemUsing = inv.get(currentSlot);
if (itemUsing.isEmpty() || Strings.isNullOrEmpty(((IBindable) itemUsing.getItem()).getOwnerUUID(itemUsing))) if (itemUsing.isEmpty() || ((IBindable) itemUsing.getItem()).getBinding(stack) == null)
return EnumActionResult.PASS; return EnumActionResult.PASS;
EnumActionResult result = itemUsing.getItem().onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ); EnumActionResult result = itemUsing.getItem().onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);
@ -109,7 +108,7 @@ public class ItemSigilHolding extends ItemSigilBase implements IKeybindable, IAl
List<ItemStack> inv = getInternalInventory(stack); List<ItemStack> inv = getInternalInventory(stack);
ItemStack itemUsing = inv.get(currentSlot); ItemStack itemUsing = inv.get(currentSlot);
if (itemUsing.isEmpty() || Strings.isNullOrEmpty(((IBindable) itemUsing.getItem()).getOwnerUUID(itemUsing))) if (itemUsing.isEmpty() || ((IBindable) itemUsing.getItem()).getBinding(stack) == null)
return ActionResult.newResult(EnumActionResult.PASS, stack); return ActionResult.newResult(EnumActionResult.PASS, stack);
itemUsing.getItem().onItemRightClick(world, player, hand); itemUsing.getItem().onItemRightClick(world, player, hand);

View file

@ -59,7 +59,7 @@ public class ItemSigilLava extends ItemSigilBase {
return super.onItemRightClick(world, player, hand); return super.onItemRightClick(world, player, hand);
} }
if (this.canPlaceLava(world, blockpos1) && NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed()) && this.tryPlaceLava(world, blockpos1)) { if (this.canPlaceLava(world, blockpos1) && NetworkHelper.getSoulNetwork(getBinding(stack)).syphonAndDamage(player, getLpUsed()) && this.tryPlaceLava(world, blockpos1)) {
return super.onItemRightClick(world, player, hand); return super.onItemRightClick(world, player, hand);
} }
} }
@ -85,7 +85,7 @@ public class ItemSigilLava extends ItemSigilBase {
FluidStack fluid = new FluidStack(FluidRegistry.LAVA, 1000); FluidStack fluid = new FluidStack(FluidRegistry.LAVA, 1000);
int amount = handler.fill(fluid, false); int amount = handler.fill(fluid, false);
if (amount > 0 && NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed())) { if (amount > 0 && NetworkHelper.getSoulNetwork(getBinding(stack)).syphonAndDamage(player, getLpUsed())) {
handler.fill(fluid, true); handler.fill(fluid, true);
return EnumActionResult.SUCCESS; return EnumActionResult.SUCCESS;
} }

View file

@ -55,7 +55,7 @@ public class ItemSigilTeleposition extends ItemSigilBase {
if (!world.isRemote && NBTHelper.checkNBT(stack) != null && stack.getTagCompound().hasKey(Constants.NBT.DIMENSION_ID) && stack.getTagCompound().hasKey(Constants.NBT.X_COORD) && stack.getTagCompound().hasKey(Constants.NBT.Y_COORD) && stack.getTagCompound().hasKey(Constants.NBT.Z_COORD)) { if (!world.isRemote && NBTHelper.checkNBT(stack) != null && stack.getTagCompound().hasKey(Constants.NBT.DIMENSION_ID) && stack.getTagCompound().hasKey(Constants.NBT.X_COORD) && stack.getTagCompound().hasKey(Constants.NBT.Y_COORD) && stack.getTagCompound().hasKey(Constants.NBT.Z_COORD)) {
BlockPos blockPos = new BlockPos(getValue(stack.getTagCompound(), Constants.NBT.X_COORD), getValue(stack.getTagCompound(), Constants.NBT.Y_COORD), getValue(stack.getTagCompound(), Constants.NBT.Z_COORD)).up(); BlockPos blockPos = new BlockPos(getValue(stack.getTagCompound(), Constants.NBT.X_COORD), getValue(stack.getTagCompound(), Constants.NBT.Y_COORD), getValue(stack.getTagCompound(), Constants.NBT.Z_COORD)).up();
if (world.provider.getDimension() == getValue(stack.getTagCompound(), Constants.NBT.DIMENSION_ID)) { if (world.provider.getDimension() == getValue(stack.getTagCompound(), Constants.NBT.DIMENSION_ID)) {
TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(blockPos, player, getOwnerUUID(stack), true)); TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(blockPos, player, getBinding(stack).getOwnerId(), true));
} }
// FIXME - Fix cross-dimension teleports causing major desync // FIXME - Fix cross-dimension teleports causing major desync
// } else { // } else {

View file

@ -1,6 +1,7 @@
package WayofTime.bloodmagic.item.sigil; package WayofTime.bloodmagic.item.sigil;
import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.core.data.Binding;
import WayofTime.bloodmagic.item.ItemSigilToggleable; import WayofTime.bloodmagic.item.ItemSigilToggleable;
import WayofTime.bloodmagic.util.helper.PlayerHelper; import WayofTime.bloodmagic.util.helper.PlayerHelper;
import WayofTime.bloodmagic.client.IMeshProvider; import WayofTime.bloodmagic.client.IMeshProvider;
@ -21,6 +22,7 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
public class ItemSigilToggleableBase extends ItemSigilToggleable implements IMeshProvider { public class ItemSigilToggleableBase extends ItemSigilToggleable implements IMeshProvider {
protected final String tooltipBase; protected final String tooltipBase;
private final String name; private final String name;
@ -40,10 +42,12 @@ public class ItemSigilToggleableBase extends ItemSigilToggleable implements IMes
super.addInformation(stack, world, tooltip, flag); super.addInformation(stack, world, tooltip, flag);
if (!stack.hasTagCompound()) if (!stack.hasTagCompound())
return; return;
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic." + (getActivated(stack) ? "activated" : "deactivated"))); tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic." + (getActivated(stack) ? "activated" : "deactivated")));
if (!Strings.isNullOrEmpty(getOwnerName(stack))) Binding binding = getBinding(stack);
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", PlayerHelper.getUsernameFromStack(stack))); if (binding != null)
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", binding.getOwnerName()));
} }
@Override @Override

View file

@ -99,7 +99,7 @@ public class ItemSigilTransposition extends ItemSigilBase {
stack.getTagCompound().setByte(Constants.NBT.CONTAINED_BLOCK_META, metadata); stack.getTagCompound().setByte(Constants.NBT.CONTAINED_BLOCK_META, metadata);
stack.getTagCompound().setTag(Constants.NBT.CONTAINED_TILE_ENTITY, tileNBTTag); stack.getTagCompound().setTag(Constants.NBT.CONTAINED_TILE_ENTITY, tileNBTTag);
NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, cost); NetworkHelper.getSoulNetwork(getBinding(stack)).syphonAndDamage(player, cost);
world.removeTileEntity(blockPos); world.removeTileEntity(blockPos);
world.setBlockToAir(blockPos); world.setBlockToAir(blockPos);

View file

@ -1,5 +1,6 @@
package WayofTime.bloodmagic.item.sigil; package WayofTime.bloodmagic.item.sigil;
import WayofTime.bloodmagic.core.data.SoulNetwork;
import WayofTime.bloodmagic.iface.ISigil; import WayofTime.bloodmagic.iface.ISigil;
import WayofTime.bloodmagic.util.helper.NetworkHelper; import WayofTime.bloodmagic.util.helper.NetworkHelper;
import WayofTime.bloodmagic.util.helper.PlayerHelper; import WayofTime.bloodmagic.util.helper.PlayerHelper;
@ -85,12 +86,13 @@ public class ItemSigilVoid extends ItemSigilBase {
return EnumActionResult.FAIL; return EnumActionResult.FAIL;
} }
SoulNetwork network = NetworkHelper.getSoulNetwork(getBinding(stack));
TileEntity tile = world.getTileEntity(blockPos); TileEntity tile = world.getTileEntity(blockPos);
if (tile != null && tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) { if (tile != null && tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) {
IFluidHandler handler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side); IFluidHandler handler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
FluidStack amount = handler.drain(1000, false); FluidStack amount = handler.drain(1000, false);
if (amount != null && amount.amount > 0 && NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed())) { if (amount != null && amount.amount > 0 && network.syphonAndDamage(player, getLpUsed())) {
handler.drain(1000, true); handler.drain(1000, true);
return EnumActionResult.SUCCESS; return EnumActionResult.SUCCESS;
} }
@ -104,7 +106,7 @@ public class ItemSigilVoid extends ItemSigilBase {
return EnumActionResult.FAIL; return EnumActionResult.FAIL;
} }
if (world.getBlockState(newPos).getBlock() instanceof IFluidBlock && NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed())) { if (world.getBlockState(newPos).getBlock() instanceof IFluidBlock && network.syphonAndDamage(player, getLpUsed())) {
world.setBlockToAir(newPos); world.setBlockToAir(newPos);
return EnumActionResult.SUCCESS; return EnumActionResult.SUCCESS;
} }

View file

@ -54,7 +54,7 @@ public class ItemSigilWater extends ItemSigilBase {
if (!player.canPlayerEdit(blockpos1, rayTrace.sideHit, stack)) if (!player.canPlayerEdit(blockpos1, rayTrace.sideHit, stack))
return super.onItemRightClick(world, player, hand); return super.onItemRightClick(world, player, hand);
if (this.canPlaceWater(world, blockpos1) && NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed()) && this.tryPlaceWater(world, blockpos1)) if (this.canPlaceWater(world, blockpos1) && NetworkHelper.getSoulNetwork(getBinding(stack)).syphonAndDamage(player, getLpUsed()) && this.tryPlaceWater(world, blockpos1))
return super.onItemRightClick(world, player, hand); return super.onItemRightClick(world, player, hand);
} }
} }

View file

@ -15,6 +15,7 @@ public class BloodOrb extends IForgeRegistryEntry.Impl<BloodOrb> {
private final String name; private final String name;
private final int tier; private final int tier;
private final int capacity; private final int capacity;
private final int fillRate;
@Nullable @Nullable
private ModelResourceLocation modelLocation; private ModelResourceLocation modelLocation;
@ -25,11 +26,13 @@ public class BloodOrb extends IForgeRegistryEntry.Impl<BloodOrb> {
* @param name - A name for the Orb. Gets put into an unlocalized name. * @param name - A name for the Orb. Gets put into an unlocalized name.
* @param tier - The tier of the Orb. * @param tier - The tier of the Orb.
* @param capacity - The max amount of LP the Orb can store. * @param capacity - The max amount of LP the Orb can store.
* @param fillRate - The amount of LP per tick the Altar can fill the network with.
*/ */
public BloodOrb(String name, int tier, int capacity) { public BloodOrb(String name, int tier, int capacity, int fillRate) {
this.name = name; this.name = name;
this.tier = tier; this.tier = tier;
this.capacity = capacity; this.capacity = capacity;
this.fillRate = fillRate;
} }
public String getName() { public String getName() {
@ -44,6 +47,10 @@ public class BloodOrb extends IForgeRegistryEntry.Impl<BloodOrb> {
return capacity; return capacity;
} }
public int getFillRate() {
return fillRate;
}
@Nullable @Nullable
public ModelResourceLocation getModelLocation() { public ModelResourceLocation getModelLocation() {
return modelLocation; return modelLocation;

View file

@ -1,11 +1,12 @@
package WayofTime.bloodmagic.ritual; package WayofTime.bloodmagic.ritual;
import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.core.data.Binding;
import WayofTime.bloodmagic.iface.IBindable; import WayofTime.bloodmagic.iface.IBindable;
import WayofTime.bloodmagic.util.helper.PlayerHelper; import WayofTime.bloodmagic.util.helper.PlayerHelper;
import WayofTime.bloodmagic.ritual.data.*; import WayofTime.bloodmagic.ritual.data.*;
import WayofTime.bloodmagic.util.Utils; import WayofTime.bloodmagic.util.Utils;
import com.google.common.base.Strings; import com.google.common.collect.Lists;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@ -23,6 +24,7 @@ import net.minecraftforge.items.IItemHandler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.UUID;
public class RitualExpulsion extends Ritual { public class RitualExpulsion extends Ritual {
public static final String EXPULSION_RANGE = "expulsionRange"; public static final String EXPULSION_RANGE = "expulsionRange";
@ -48,7 +50,7 @@ public class RitualExpulsion extends Ritual {
AreaDescriptor expulsionRange = getBlockRange(EXPULSION_RANGE); AreaDescriptor expulsionRange = getBlockRange(EXPULSION_RANGE);
List<String> allowedNames = new ArrayList<String>(); List<UUID> whitelist = Lists.newArrayList();
BlockPos masterPos = masterRitualStone.getBlockPos(); BlockPos masterPos = masterRitualStone.getBlockPos();
TileEntity tile = world.getTileEntity(masterPos.up()); TileEntity tile = world.getTileEntity(masterPos.up());
@ -57,10 +59,10 @@ public class RitualExpulsion extends Ritual {
if (handler != null) { if (handler != null) {
for (int i = 0; i < handler.getSlots(); i++) { for (int i = 0; i < handler.getSlots(); i++) {
ItemStack itemStack = handler.getStackInSlot(i); ItemStack itemStack = handler.getStackInSlot(i);
if (itemStack != null && itemStack.getItem() instanceof IBindable) { if (!itemStack.isEmpty() && itemStack.getItem() instanceof IBindable) {
IBindable bindable = (IBindable) itemStack.getItem(); Binding binding = ((IBindable) itemStack.getItem()).getBinding(itemStack);
if (!Strings.isNullOrEmpty(bindable.getOwnerName(itemStack)) && !allowedNames.contains(bindable.getOwnerName(itemStack))) if (binding != null && !whitelist.contains(binding.getOwnerId()))
allowedNames.add(bindable.getOwnerUUID(itemStack)); whitelist.add(binding.getOwnerId());
} }
} }
} }
@ -69,14 +71,14 @@ public class RitualExpulsion extends Ritual {
final int teleportDistance = 100; final int teleportDistance = 100;
for (EntityPlayer player : world.getEntitiesWithinAABB(EntityPlayer.class, expulsionRange.getAABB(masterRitualStone.getBlockPos()))) { for (EntityPlayer player : world.getEntitiesWithinAABB(EntityPlayer.class, expulsionRange.getAABB(masterRitualStone.getBlockPos()))) {
if (player.capabilities.isCreativeMode || PlayerHelper.getUUIDFromPlayer(player).toString().equals(masterRitualStone.getOwner()) || allowedNames.contains(PlayerHelper.getUUIDFromPlayer(player).toString())) if (player.capabilities.isCreativeMode || PlayerHelper.getUUIDFromPlayer(player).toString().equals(masterRitualStone.getOwner()) || whitelist.contains(player.getGameProfile().getId()))
continue; continue;
if (teleportRandomly(player, teleportDistance)) if (teleportRandomly(player, teleportDistance))
masterRitualStone.getOwnerNetwork().syphon(getRefreshCost() * 1000); masterRitualStone.getOwnerNetwork().syphon(getRefreshCost() * 1000);
} }
allowedNames.clear(); whitelist.clear();
} }
public boolean teleportRandomly(EntityLivingBase entityLiving, double distance) { public boolean teleportRandomly(EntityLivingBase entityLiving, double distance) {
@ -162,20 +164,16 @@ public class RitualExpulsion extends Ritual {
} }
public void moveEntityViaTeleport(EntityLivingBase entityLiving, double x, double y, double z) { public void moveEntityViaTeleport(EntityLivingBase entityLiving, double x, double y, double z) {
if (entityLiving != null && entityLiving instanceof EntityPlayer) { if (entityLiving instanceof EntityPlayerMP) {
if (entityLiving instanceof EntityPlayerMP) { EntityPlayerMP player = (EntityPlayerMP) entityLiving;
EntityPlayerMP entityplayermp = (EntityPlayerMP) entityLiving;
if (entityplayermp.getEntityWorld() == entityLiving.getEntityWorld()) { EnderTeleportEvent event = new EnderTeleportEvent(player, x, y, z, 5.0F);
EnderTeleportEvent event = new EnderTeleportEvent(entityplayermp, x, y, z, 5.0F);
if (!MinecraftForge.EVENT_BUS.post(event)) { if (!MinecraftForge.EVENT_BUS.post(event)) {
if (entityLiving.isRiding()) { if (entityLiving.isRiding())
entityplayermp.mountEntityAndWakeUp(); player.mountEntityAndWakeUp();
}
entityLiving.setPositionAndUpdate(event.getTargetX(), event.getTargetY(), event.getTargetZ()); entityLiving.setPositionAndUpdate(event.getTargetX(), event.getTargetY(), event.getTargetZ());
}
}
} }
} else if (entityLiving != null) { } else if (entityLiving != null) {
entityLiving.setPosition(x, y, z); entityLiving.setPosition(x, y, z);

View file

@ -18,6 +18,7 @@ import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.ForgeRegistries; import net.minecraftforge.fml.common.registry.ForgeRegistries;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.UUID;
public class RitualPortal extends Ritual { public class RitualPortal extends Ritual {
@ -31,14 +32,14 @@ public class RitualPortal extends Ritual {
} }
@Override @Override
public boolean activateRitual(IMasterRitualStone masterRitualStone, EntityPlayer player, String owner) { public boolean activateRitual(IMasterRitualStone masterRitualStone, EntityPlayer player, UUID owner) {
World world = masterRitualStone.getWorldObj(); World world = masterRitualStone.getWorldObj();
int x = masterRitualStone.getBlockPos().getX(); int x = masterRitualStone.getBlockPos().getX();
int y = masterRitualStone.getBlockPos().getY(); int y = masterRitualStone.getBlockPos().getY();
int z = masterRitualStone.getBlockPos().getZ(); int z = masterRitualStone.getBlockPos().getZ();
EnumFacing direction = masterRitualStone.getDirection(); EnumFacing direction = masterRitualStone.getDirection();
String name = owner; String name = owner.toString();
IBlockState blockState; IBlockState blockState;
if (!world.isRemote) { if (!world.isRemote) {

View file

@ -9,6 +9,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import java.util.List; import java.util.List;
import java.util.UUID;
/** /**
* This interface is for internal implementation only. * This interface is for internal implementation only.
@ -16,7 +17,7 @@ import java.util.List;
* It is provided via the API for easy obtaining of basic data. * It is provided via the API for easy obtaining of basic data.
*/ */
public interface IMasterRitualStone { public interface IMasterRitualStone {
String getOwner(); UUID getOwner();
SoulNetwork getOwnerNetwork(); SoulNetwork getOwnerNetwork();

View file

@ -14,10 +14,7 @@ import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
/** /**
@ -100,7 +97,7 @@ public abstract class Ritual {
* owner of the ritual if being reactivated. * owner of the ritual if being reactivated.
* @return - Whether activation was successful * @return - Whether activation was successful
*/ */
public boolean activateRitual(IMasterRitualStone masterRitualStone, EntityPlayer player, String owner) { public boolean activateRitual(IMasterRitualStone masterRitualStone, EntityPlayer player, UUID owner) {
return true; return true;
} }

View file

@ -20,17 +20,19 @@ import net.minecraft.world.WorldServer;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.FMLCommonHandler;
import java.util.UUID;
public class Teleports { public class Teleports {
public static class TeleportSameDim extends Teleport { public static class TeleportSameDim extends Teleport {
private final boolean teleposer; private final boolean teleposer;
public TeleportSameDim(int x, int y, int z, Entity entity, String networkToDrain, boolean teleposer) { public TeleportSameDim(int x, int y, int z, Entity entity, UUID networkOwner, boolean teleposer) {
this(new BlockPos(x, y, z), entity, networkToDrain, teleposer); this(new BlockPos(x, y, z), entity, networkOwner, teleposer);
} }
public TeleportSameDim(BlockPos blockPos, Entity entity, String networkToDrain, boolean teleposer) { public TeleportSameDim(BlockPos blockPos, Entity entity, UUID networkOwner, boolean teleposer) {
super(blockPos, entity, networkToDrain); super(blockPos, entity, networkOwner);
this.teleposer = teleposer; this.teleposer = teleposer;
} }
@ -39,7 +41,7 @@ public class Teleports {
if (entity != null) { if (entity != null) {
if (entity.timeUntilPortal <= 0) { if (entity.timeUntilPortal <= 0) {
if (entity instanceof EntityPlayer) { if (entity instanceof EntityPlayer) {
SoulNetwork network = NetworkHelper.getSoulNetwork(networkToDrain); SoulNetwork network = NetworkHelper.getSoulNetwork(networkOwner);
if (network.getCurrentEssence() < getTeleportCost()) if (network.getCurrentEssence() < getTeleportCost())
return; return;
@ -60,7 +62,7 @@ public class Teleports {
if (teleposer) if (teleposer)
MinecraftForge.EVENT_BUS.post(new TeleposeEvent.Ent.Post(entity, entity.getEntityWorld(), entity.getPosition(), entity.getEntityWorld(), new BlockPos(x, y, z))); MinecraftForge.EVENT_BUS.post(new TeleposeEvent.Ent.Post(entity, entity.getEntityWorld(), entity.getPosition(), entity.getEntityWorld(), new BlockPos(x, y, z)));
} else { } else {
SoulNetwork network = NetworkHelper.getSoulNetwork(networkToDrain); SoulNetwork network = NetworkHelper.getSoulNetwork(networkOwner);
if (network.getCurrentEssence() < (getTeleportCost() / 10)) if (network.getCurrentEssence() < (getTeleportCost() / 10))
return; return;
@ -95,12 +97,12 @@ public class Teleports {
private int newWorldID; private int newWorldID;
private boolean teleposer; private boolean teleposer;
public TeleportToDim(int x, int y, int z, Entity entity, String networkToDrain, World oldWorld, int newWorld, boolean teleposer) { public TeleportToDim(int x, int y, int z, Entity entity, UUID networkOwner, World oldWorld, int newWorld, boolean teleposer) {
this(new BlockPos(x, y, z), entity, networkToDrain, oldWorld, newWorld, teleposer); this(new BlockPos(x, y, z), entity, networkOwner, oldWorld, newWorld, teleposer);
} }
public TeleportToDim(BlockPos blockPos, Entity entity, String networkToDrain, World oldWorld, int newWorldID, boolean teleposer) { public TeleportToDim(BlockPos blockPos, Entity entity, UUID networkOwner, World oldWorld, int newWorldID, boolean teleposer) {
super(blockPos, entity, networkToDrain); super(blockPos, entity, networkOwner);
this.oldWorld = oldWorld; this.oldWorld = oldWorld;
this.newWorldID = newWorldID; this.newWorldID = newWorldID;
this.teleposer = teleposer; this.teleposer = teleposer;
@ -118,7 +120,7 @@ public class Teleports {
EntityPlayerMP player = (EntityPlayerMP) entity; EntityPlayerMP player = (EntityPlayerMP) entity;
if (!player.getEntityWorld().isRemote) { if (!player.getEntityWorld().isRemote) {
SoulNetwork network = NetworkHelper.getSoulNetwork(networkToDrain); SoulNetwork network = NetworkHelper.getSoulNetwork(networkOwner);
if (network.getCurrentEssence() < getTeleportCost()) if (network.getCurrentEssence() < getTeleportCost())
return; return;
@ -138,7 +140,7 @@ public class Teleports {
} }
} else if (!entity.getEntityWorld().isRemote) { } else if (!entity.getEntityWorld().isRemote) {
SoulNetwork network = NetworkHelper.getSoulNetwork(networkToDrain); SoulNetwork network = NetworkHelper.getSoulNetwork(networkOwner);
if (network.getCurrentEssence() < (getTeleportCost() / 10)) if (network.getCurrentEssence() < (getTeleportCost() / 10))
return; return;

View file

@ -3,23 +3,25 @@ package WayofTime.bloodmagic.teleport;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import java.util.UUID;
public abstract class Teleport implements ITeleport { public abstract class Teleport implements ITeleport {
protected int x; protected int x;
protected int y; protected int y;
protected int z; protected int z;
protected Entity entity; protected Entity entity;
protected String networkToDrain; protected UUID networkOwner;
public Teleport(int x, int y, int z, Entity entity, String networkToDrain) { public Teleport(int x, int y, int z, Entity entity, UUID networkOwner) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
this.entity = entity; this.entity = entity;
this.networkToDrain = networkToDrain; this.networkOwner = networkOwner;
} }
public Teleport(BlockPos blockPos, Entity entity, String networkToDrain) { public Teleport(BlockPos blockPos, Entity entity, UUID networkOwner) {
this(blockPos.getX(), blockPos.getY(), blockPos.getZ(), entity, networkToDrain); this(blockPos.getX(), blockPos.getY(), blockPos.getZ(), entity, networkOwner);
} }
public int getX() { public int getX() {
@ -38,8 +40,8 @@ public abstract class Teleport implements ITeleport {
return entity; return entity;
} }
public String getNetworkToDrain() { public UUID getNetworkOwner() {
return networkToDrain; return networkOwner;
} }
@Override @Override
@ -53,7 +55,7 @@ public abstract class Teleport implements ITeleport {
if (y != teleport.y) return false; if (y != teleport.y) return false;
if (z != teleport.z) return false; if (z != teleport.z) return false;
if (entity != null ? !entity.equals(teleport.entity) : teleport.entity != null) return false; if (entity != null ? !entity.equals(teleport.entity) : teleport.entity != null) return false;
return networkToDrain != null ? networkToDrain.equals(teleport.networkToDrain) : teleport.networkToDrain == null; return networkOwner != null ? networkOwner.equals(teleport.networkOwner) : teleport.networkOwner == null;
} }
@Override @Override
@ -62,7 +64,7 @@ public abstract class Teleport implements ITeleport {
result = 31 * result + y; result = 31 * result + y;
result = 31 * result + z; result = 31 * result + z;
result = 31 * result + (entity != null ? entity.hashCode() : 0); result = 31 * result + (entity != null ? entity.hashCode() : 0);
result = 31 * result + (networkToDrain != null ? networkToDrain.hashCode() : 0); result = 31 * result + (networkOwner != null ? networkOwner.hashCode() : 0);
return result; return result;
} }
} }

View file

@ -1,5 +1,7 @@
package WayofTime.bloodmagic.tile; package WayofTime.bloodmagic.tile;
import WayofTime.bloodmagic.core.data.Binding;
import WayofTime.bloodmagic.iface.IBindable;
import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.util.Constants;
import WayofTime.bloodmagic.event.RitualEvent; import WayofTime.bloodmagic.event.RitualEvent;
import WayofTime.bloodmagic.core.registry.RitualRegistry; import WayofTime.bloodmagic.core.registry.RitualRegistry;
@ -7,10 +9,7 @@ import WayofTime.bloodmagic.ritual.data.IMasterRitualStone;
import WayofTime.bloodmagic.ritual.data.Ritual; import WayofTime.bloodmagic.ritual.data.Ritual;
import WayofTime.bloodmagic.core.data.SoulNetwork; import WayofTime.bloodmagic.core.data.SoulNetwork;
import WayofTime.bloodmagic.soul.EnumDemonWillType; import WayofTime.bloodmagic.soul.EnumDemonWillType;
import WayofTime.bloodmagic.util.helper.NBTHelper; import WayofTime.bloodmagic.util.helper.*;
import WayofTime.bloodmagic.util.helper.NetworkHelper;
import WayofTime.bloodmagic.util.helper.PlayerHelper;
import WayofTime.bloodmagic.util.helper.RitualHelper;
import WayofTime.bloodmagic.core.RegistrarBloodMagicItems; import WayofTime.bloodmagic.core.RegistrarBloodMagicItems;
import WayofTime.bloodmagic.item.ItemActivationCrystal; import WayofTime.bloodmagic.item.ItemActivationCrystal;
import WayofTime.bloodmagic.tile.base.TileTicking; import WayofTime.bloodmagic.tile.base.TileTicking;
@ -29,9 +28,10 @@ import net.minecraftforge.fml.common.eventhandler.Event;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
public class TileMasterRitualStone extends TileTicking implements IMasterRitualStone { public class TileMasterRitualStone extends TileTicking implements IMasterRitualStone {
private String owner; private UUID owner;
private SoulNetwork cachedNetwork; private SoulNetwork cachedNetwork;
private boolean active; private boolean active;
private boolean redstoned; private boolean redstoned;
@ -57,7 +57,7 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
if (!isActive() && !isPowered() && isRedstoned() && getCurrentRitual() != null) { if (!isActive() && !isPowered() && isRedstoned() && getCurrentRitual() != null) {
active = true; active = true;
ItemStack crystalStack = NBTHelper.checkNBT(new ItemStack(RegistrarBloodMagicItems.ACTIVATION_CRYSTAL, 1, getCurrentRitual().getCrystalLevel())); ItemStack crystalStack = NBTHelper.checkNBT(new ItemStack(RegistrarBloodMagicItems.ACTIVATION_CRYSTAL, 1, getCurrentRitual().getCrystalLevel()));
crystalStack.getTagCompound().setString(Constants.NBT.OWNER_UUID, getOwner()); BindableHelper.applyBinding(crystalStack, new Binding(owner, PlayerHelper.getUsernameFromUUID(owner)));
activateRitual(crystalStack, null, getCurrentRitual()); activateRitual(crystalStack, null, getCurrentRitual());
redstoned = false; redstoned = false;
} }
@ -72,8 +72,8 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
@Override @Override
public void deserialize(NBTTagCompound tag) { public void deserialize(NBTTagCompound tag) {
owner = tag.getString(Constants.NBT.OWNER_UUID); owner = tag.hasUniqueId("owner") ? tag.getUniqueId("owner") : null;
if (!Strings.isNullOrEmpty(owner)) if (owner != null)
cachedNetwork = NetworkHelper.getSoulNetwork(owner); cachedNetwork = NetworkHelper.getSoulNetwork(owner);
currentRitual = RitualRegistry.getRitualForId(tag.getString(Constants.NBT.CURRENT_RITUAL)); currentRitual = RitualRegistry.getRitualForId(tag.getString(Constants.NBT.CURRENT_RITUAL));
if (currentRitual != null) { if (currentRitual != null) {
@ -97,7 +97,8 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
@Override @Override
public NBTTagCompound serialize(NBTTagCompound tag) { public NBTTagCompound serialize(NBTTagCompound tag) {
String ritualId = RitualRegistry.getIdForRitual(getCurrentRitual()); String ritualId = RitualRegistry.getIdForRitual(getCurrentRitual());
tag.setString(Constants.NBT.OWNER_UUID, Strings.isNullOrEmpty(getOwner()) ? "" : getOwner()); if (owner != null)
tag.setUniqueId(Constants.NBT.OWNER_UUID, owner);
tag.setString(Constants.NBT.CURRENT_RITUAL, Strings.isNullOrEmpty(ritualId) ? "" : ritualId); tag.setString(Constants.NBT.CURRENT_RITUAL, Strings.isNullOrEmpty(ritualId) ? "" : ritualId);
if (currentRitual != null) { if (currentRitual != null) {
NBTTagCompound ritualTag = new NBTTagCompound(); NBTTagCompound ritualTag = new NBTTagCompound();
@ -121,15 +122,13 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
if (PlayerHelper.isFakePlayer(activator)) if (PlayerHelper.isFakePlayer(activator))
return false; return false;
activationCrystal = NBTHelper.checkNBT(activationCrystal); Binding binding = ((IBindable) activationCrystal.getItem()).getBinding(activationCrystal);
String crystalOwner = activationCrystal.getTagCompound().getString(Constants.NBT.OWNER_UUID); if (binding != null && ritual != null) {
if (!Strings.isNullOrEmpty(crystalOwner) && ritual != null) {
if (activationCrystal.getItem() instanceof ItemActivationCrystal) { if (activationCrystal.getItem() instanceof ItemActivationCrystal) {
int crystalLevel = ((ItemActivationCrystal) activationCrystal.getItem()).getCrystalLevel(activationCrystal); int crystalLevel = ((ItemActivationCrystal) activationCrystal.getItem()).getCrystalLevel(activationCrystal);
if (RitualHelper.canCrystalActivate(ritual, crystalLevel)) { if (RitualHelper.canCrystalActivate(ritual, crystalLevel)) {
if (!getWorld().isRemote) { if (!getWorld().isRemote) {
SoulNetwork network = NetworkHelper.getSoulNetwork(crystalOwner); SoulNetwork network = NetworkHelper.getSoulNetwork(binding);
if (!isRedstoned() && network.getCurrentEssence() < ritual.getActivationCost() && (activator != null && !activator.capabilities.isCreativeMode)) { if (!isRedstoned() && network.getCurrentEssence() < ritual.getActivationCost() && (activator != null && !activator.capabilities.isCreativeMode)) {
activator.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.ritual.weak"), true); activator.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.ritual.weak"), true);
@ -139,7 +138,7 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
if (currentRitual != null) if (currentRitual != null)
currentRitual.stopRitual(this, Ritual.BreakType.ACTIVATE); currentRitual.stopRitual(this, Ritual.BreakType.ACTIVATE);
RitualEvent.RitualActivatedEvent event = new RitualEvent.RitualActivatedEvent(this, crystalOwner, ritual, activator, activationCrystal, crystalLevel); RitualEvent.RitualActivatedEvent event = new RitualEvent.RitualActivatedEvent(this, binding.getOwnerId(), ritual, activator, activationCrystal, crystalLevel);
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY) { if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY) {
if (activator != null) if (activator != null)
@ -147,7 +146,7 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
return false; return false;
} }
if (ritual.activateRitual(this, activator, crystalOwner)) { if (ritual.activateRitual(this, activator, binding.getOwnerId())) {
if (!isRedstoned() && (activator != null && !activator.capabilities.isCreativeMode)) if (!isRedstoned() && (activator != null && !activator.capabilities.isCreativeMode))
network.syphon(ritual.getActivationCost()); network.syphon(ritual.getActivationCost());
@ -155,7 +154,7 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
activator.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.ritual.activate"), true); activator.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.ritual.activate"), true);
this.active = true; this.active = true;
this.owner = crystalOwner; this.owner = binding.getOwnerId();
this.cachedNetwork = network; this.cachedNetwork = network;
this.currentRitual = ritual; this.currentRitual = ritual;
@ -240,11 +239,11 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
} }
@Override @Override
public String getOwner() { public UUID getOwner() {
return owner; return owner;
} }
public void setOwner(String owner) { public void setOwner(UUID owner) {
this.owner = owner; this.owner = owner;
} }

View file

@ -1,19 +1,19 @@
package WayofTime.bloodmagic.tile; package WayofTime.bloodmagic.tile;
import WayofTime.bloodmagic.core.data.Binding;
import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.util.Constants;
import WayofTime.bloodmagic.event.TeleposeEvent; import WayofTime.bloodmagic.event.TeleposeEvent;
import WayofTime.bloodmagic.teleport.TeleportQueue; import WayofTime.bloodmagic.teleport.TeleportQueue;
import WayofTime.bloodmagic.util.helper.NBTHelper;
import WayofTime.bloodmagic.util.helper.NetworkHelper; import WayofTime.bloodmagic.util.helper.NetworkHelper;
import WayofTime.bloodmagic.util.helper.PlayerHelper; import WayofTime.bloodmagic.util.helper.PlayerHelper;
import WayofTime.bloodmagic.block.BlockTeleposer; import WayofTime.bloodmagic.block.BlockTeleposer;
import WayofTime.bloodmagic.item.ItemTelepositionFocus; import WayofTime.bloodmagic.item.ItemTelepositionFocus;
import WayofTime.bloodmagic.ritual.portal.Teleports; import WayofTime.bloodmagic.ritual.portal.Teleports;
import WayofTime.bloodmagic.util.Utils; import WayofTime.bloodmagic.util.Utils;
import com.google.common.base.Strings;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ITickable; import net.minecraft.util.ITickable;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -59,17 +59,23 @@ public class TileTeleposer extends TileInventory implements ITickable {
} }
public void initiateTeleport() { public void initiateTeleport() {
if (!getWorld().isRemote && canInitiateTeleport(this) && getBlockType() instanceof BlockTeleposer) { if (!getWorld().isRemote && canInitiateTeleport() && getBlockType() instanceof BlockTeleposer) {
ItemStack focusStack = NBTHelper.checkNBT(getStackInSlot(0)); ItemStack focusStack = getStackInSlot(0);
ItemTelepositionFocus focus = (ItemTelepositionFocus) focusStack.getItem(); ItemTelepositionFocus focus = (ItemTelepositionFocus) focusStack.getItem();
Binding binding = focus.getBinding(focusStack);
if (binding == null)
return;
BlockPos focusPos = focus.getBlockPos(getStackInSlot(0)); BlockPos focusPos = focus.getBlockPos(getStackInSlot(0));
World focusWorld = focus.getWorld(getStackInSlot(0)); World focusWorld = focus.getWorld(getStackInSlot(0));
if (focusWorld == null)
return;
if (focusWorld != null && focusWorld.getTileEntity(focusPos) instanceof TileTeleposer && !focusWorld.getTileEntity(focusPos).equals(this)) { TileEntity boundTile = focusWorld.getTileEntity(focusPos);
if (boundTile instanceof TileTeleposer && boundTile != this) {
final int focusLevel = (getStackInSlot(0).getItemDamage() + 1); final int focusLevel = (getStackInSlot(0).getItemDamage() + 1);
final int lpToBeDrained = (int) (0.5F * Math.sqrt((pos.getX() - focusPos.getX()) * (pos.getX() - focusPos.getX()) + (pos.getY() - focusPos.getY() + 1) * (pos.getY() - focusPos.getY() + 1) + (pos.getZ() - focusPos.getZ()) * (pos.getZ() - focusPos.getZ()))); final int lpToBeDrained = (int) (0.5F * Math.sqrt((pos.getX() - focusPos.getX()) * (pos.getX() - focusPos.getX()) + (pos.getY() - focusPos.getY() + 1) * (pos.getY() - focusPos.getY() + 1) + (pos.getZ() - focusPos.getZ()) * (pos.getZ() - focusPos.getZ())));
if (NetworkHelper.getSoulNetwork(focus.getOwnerUUID(focusStack)).syphonAndDamage(PlayerHelper.getPlayerFromUUID(focus.getOwnerUUID(focusStack)), lpToBeDrained * (focusLevel * 2 - 1) * (focusLevel * 2 - 1) * (focusLevel * 2 - 1))) { if (NetworkHelper.getSoulNetwork(binding).syphonAndDamage(PlayerHelper.getPlayerFromUUID(binding.getOwnerId()), lpToBeDrained * (focusLevel * 2 - 1) * (focusLevel * 2 - 1) * (focusLevel * 2 - 1))) {
int blocksTransported = 0; int blocksTransported = 0;
for (int i = -(focusLevel - 1); i <= (focusLevel - 1); i++) { for (int i = -(focusLevel - 1); i <= (focusLevel - 1); i++) {
@ -95,13 +101,13 @@ public class TileTeleposer extends TileInventory implements ITickable {
if (focusWorld.equals(getWorld())) { if (focusWorld.equals(getWorld())) {
if (!originalWorldEntities.isEmpty()) { if (!originalWorldEntities.isEmpty()) {
for (Entity entity : originalWorldEntities) { for (Entity entity : originalWorldEntities) {
TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(new BlockPos(entity.posX - pos.getX() + focusPos.getX(), entity.posY - pos.getY() + focusPos.getY(), entity.posZ - pos.getZ() + focusPos.getZ()), entity, focusStack.getTagCompound().getString(Constants.NBT.OWNER_UUID), true)); TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(new BlockPos(entity.posX - pos.getX() + focusPos.getX(), entity.posY - pos.getY() + focusPos.getY(), entity.posZ - pos.getZ() + focusPos.getZ()), entity, binding.getOwnerId(), true));
} }
} }
if (!focusWorldEntities.isEmpty()) { if (!focusWorldEntities.isEmpty()) {
for (Entity entity : focusWorldEntities) { for (Entity entity : focusWorldEntities) {
TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(new BlockPos(entity.posX - pos.getX() + focusPos.getX(), entity.posY - pos.getY() + focusPos.getY(), entity.posZ - pos.getZ() + focusPos.getZ()), entity, focusStack.getTagCompound().getString(Constants.NBT.OWNER_UUID), true)); TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(new BlockPos(entity.posX - pos.getX() + focusPos.getX(), entity.posY - pos.getY() + focusPos.getY(), entity.posZ - pos.getZ() + focusPos.getZ()), entity, binding.getOwnerId(), true));
} }
} }
} }
@ -124,7 +130,8 @@ public class TileTeleposer extends TileInventory implements ITickable {
} }
} }
private boolean canInitiateTeleport(TileTeleposer teleposer) { private boolean canInitiateTeleport() {
return !teleposer.getStackInSlot(0).isEmpty() && teleposer.getStackInSlot(0).getItem() instanceof ItemTelepositionFocus && !Strings.isNullOrEmpty(((ItemTelepositionFocus) teleposer.getStackInSlot(0).getItem()).getOwnerName(teleposer.getStackInSlot(0))); ItemStack focusStack = getStackInSlot(0);
return !focusStack.isEmpty() && focusStack.getItem() instanceof ItemTelepositionFocus && ((ItemTelepositionFocus) focusStack.getItem()).getBinding(focusStack) != null;
} }
} }

View file

@ -3,6 +3,7 @@ package WayofTime.bloodmagic.util.handler.event;
import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.ConfigHandler; import WayofTime.bloodmagic.ConfigHandler;
import WayofTime.bloodmagic.api.impl.BloodMagicAPI; import WayofTime.bloodmagic.api.impl.BloodMagicAPI;
import WayofTime.bloodmagic.core.data.Binding;
import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.util.Constants;
import WayofTime.bloodmagic.event.ItemBindEvent; import WayofTime.bloodmagic.event.ItemBindEvent;
import WayofTime.bloodmagic.event.SacrificeKnifeUsedEvent; import WayofTime.bloodmagic.event.SacrificeKnifeUsedEvent;
@ -53,6 +54,7 @@ import net.minecraft.init.MobEffects;
import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource; import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.EnumParticleTypes;
@ -79,10 +81,7 @@ import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.registry.EntityEntry; import net.minecraftforge.fml.common.registry.EntityEntry;
import net.minecraftforge.fml.common.registry.EntityRegistry; import net.minecraftforge.fml.common.registry.EntityRegistry;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Random;
@Mod.EventBusSubscriber(modid = BloodMagic.MODID) @Mod.EventBusSubscriber(modid = BloodMagic.MODID)
public class GenericHandler { public class GenericHandler {
@ -339,25 +338,25 @@ public class GenericHandler {
return; return;
ItemStack held = event.getItemStack(); ItemStack held = event.getItemStack();
if (!held.isEmpty() && held.getItem() instanceof IBindable) { if (!held.isEmpty() && held.getItem() instanceof IBindable) { // Make sure it's bindable
held = NBTHelper.checkNBT(held);
IBindable bindable = (IBindable) held.getItem(); IBindable bindable = (IBindable) held.getItem();
if (Strings.isNullOrEmpty(bindable.getOwnerUUID(held))) { Binding binding = bindable.getBinding(held);
if (binding == null) { // If the binding is null, let's create one
if (bindable.onBind(player, held)) { if (bindable.onBind(player, held)) {
String uuid = PlayerHelper.getUUIDFromPlayer(player).toString(); ItemBindEvent toPost = new ItemBindEvent(player, held);
ItemBindEvent toPost = new ItemBindEvent(player, uuid, held); if (MinecraftForge.EVENT_BUS.post(toPost)) // Allow cancellation of binding
if (MinecraftForge.EVENT_BUS.post(toPost) || toPost.getResult() == Result.DENY)
return; return;
BindableHelper.setItemOwnerUUID(held, uuid); BindableHelper.applyBinding(held, player); // Bind item to the player
BindableHelper.setItemOwnerName(held, player.getDisplayNameString());
} }
} else if (bindable.getOwnerUUID(held).equals(PlayerHelper.getUUIDFromPlayer(player).toString()) && !bindable.getOwnerName(held).equals(player.getDisplayNameString())) // If the binding exists, we'll check if the player's name has changed since they last used it and update that if so.
BindableHelper.setItemOwnerName(held, player.getDisplayNameString()); } else if (binding.getOwnerId().equals(player.getGameProfile().getId()) && !binding.getOwnerName().equals(player.getGameProfile().getName())) {
binding.setOwnerName(player.getGameProfile().getName());
BindableHelper.applyBinding(held, binding);
}
} }
if (!held.isEmpty() && held.getItem() instanceof IBloodOrb) { if (!held.isEmpty() && held.getItem() instanceof IBloodOrb) {
held = NBTHelper.checkNBT(held);
IBloodOrb bloodOrb = (IBloodOrb) held.getItem(); IBloodOrb bloodOrb = (IBloodOrb) held.getItem();
SoulNetwork network = NetworkHelper.getSoulNetwork(player); SoulNetwork network = NetworkHelper.getSoulNetwork(player);

View file

@ -1,17 +1,26 @@
package WayofTime.bloodmagic.util.helper; package WayofTime.bloodmagic.util.helper;
import WayofTime.bloodmagic.core.data.Binding;
import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.util.Constants;
import WayofTime.bloodmagic.event.ItemBindEvent; import WayofTime.bloodmagic.event.ItemBindEvent;
import WayofTime.bloodmagic.iface.IBindable;
import WayofTime.bloodmagic.util.handler.event.GenericHandler;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge; import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import java.util.UUID;
public class BindableHelper { public class BindableHelper {
public static void applyBinding(ItemStack stack, EntityPlayer player) {
Binding binding = new Binding(player.getGameProfile().getId(), player.getGameProfile().getName());
applyBinding(stack, binding);
}
public static void applyBinding(ItemStack stack, Binding binding) {
if (!stack.hasTagCompound())
stack.setTagCompound(new NBTTagCompound());
stack.getTagCompound().setTag("binding", binding.serializeNBT());
}
/** /**
* Sets the Owner Name of the item without checking if it is already bound. * Sets the Owner Name of the item without checking if it is already bound.
* Also bypasses {@link ItemBindEvent}. * Also bypasses {@link ItemBindEvent}.
@ -37,113 +46,4 @@ public class BindableHelper {
stack.getTagCompound().setString(Constants.NBT.OWNER_UUID, ownerUUID); stack.getTagCompound().setString(Constants.NBT.OWNER_UUID, ownerUUID);
} }
// Everything below is to be removed.
/**
* Deprecated.
* <p>
* Built into {@link IBindable} now.
*
* @param stack - The ItemStack to check the owner of
* @return - The username of the ItemStack's owner
*/
@Deprecated
public static String getOwnerName(ItemStack stack) {
stack = NBTHelper.checkNBT(stack);
return PlayerHelper.getUsernameFromStack(stack);
}
/**
* Deprecated.
* <p>
* Built into {@link IBindable} now.
*
* @param stack - The ItemStack to check the owner of
* @return - The UUID of the ItemStack's owner
*/
@Deprecated
public static String getOwnerUUID(ItemStack stack) {
stack = NBTHelper.checkNBT(stack);
return stack.getTagCompound().getString(Constants.NBT.OWNER_UUID);
}
/**
* Deprecated.
* <p>
* Now handled automatically with
* {@link GenericHandler#onInteract(PlayerInteractEvent.RightClickItem)}
*
* @param stack - The ItemStack to bind
* @param player - The Player to bind the ItemStack to
* @return - Whether binding was successful
*/
@Deprecated
public static boolean checkAndSetItemOwner(ItemStack stack, EntityPlayer player) {
return !PlayerHelper.isFakePlayer(player) && checkAndSetItemOwner(stack, PlayerHelper.getUUIDFromPlayer(player), player.getName());
}
/**
* Deprecated.
* <p>
* Now handled automatically with
* {@link GenericHandler#onInteract(PlayerInteractEvent.RightClickItem)}
*
* @param stack - The ItemStack to bind
* @param uuid - The username to bind the ItemStack to
* @param currentUsername - The current name of the player.
* @return - Whether the binding was successful
*/
@Deprecated
public static boolean checkAndSetItemOwner(ItemStack stack, String uuid, String currentUsername) {
stack = NBTHelper.checkNBT(stack);
if (!(stack.getItem() instanceof IBindable))
return false;
String currentOwner = stack.getTagCompound().getString(Constants.NBT.OWNER_UUID);
if (currentOwner == "") //The player has not been set yet, so set everything.
{
MinecraftForge.EVENT_BUS.post(new ItemBindEvent(PlayerHelper.getPlayerFromUUID(uuid), uuid, stack));
((IBindable) stack.getItem()).onBind(PlayerHelper.getPlayerFromUUID(uuid), stack);
stack.getTagCompound().setString(Constants.NBT.OWNER_UUID, uuid);
stack.getTagCompound().setString(Constants.NBT.OWNER_NAME, currentUsername);
return true;
} else if (currentOwner.equals(uuid)) //The player has been set, so this will simply update the display name
{
stack.getTagCompound().setString(Constants.NBT.OWNER_NAME, currentUsername);
}
return true;
}
/**
* Deprecated.
* <p>
* Now handled automatically with
* {@link GenericHandler#onInteract(PlayerInteractEvent.RightClickItem)}
*
* @param stack - ItemStack to check
* @param uuid - UUID of the Player
* @param currentUsername - The current name of the player.
*/
@Deprecated
public static boolean checkAndSetItemOwner(ItemStack stack, UUID uuid, String currentUsername) {
return checkAndSetItemOwner(stack, uuid.toString(), currentUsername);
}
/**
* Deprecated.
*
* @param stack - The ItemStack to bind
* @param ownerName - The username to bind the ItemStack to
* @see #setItemOwnerName(ItemStack, String)
*/
@Deprecated
public static void setItemOwner(ItemStack stack, String ownerName) {
setItemOwnerName(stack, ownerName);
}
} }

View file

@ -1,5 +1,7 @@
package WayofTime.bloodmagic.util.helper; package WayofTime.bloodmagic.util.helper;
import WayofTime.bloodmagic.core.data.Binding;
import WayofTime.bloodmagic.iface.IBindable;
import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.util.Constants;
import WayofTime.bloodmagic.event.SoulNetworkEvent; import WayofTime.bloodmagic.event.SoulNetworkEvent;
import WayofTime.bloodmagic.orb.BloodOrb; import WayofTime.bloodmagic.orb.BloodOrb;
@ -57,6 +59,10 @@ public class NetworkHelper {
return getSoulNetwork(PlayerHelper.getUUIDFromPlayer(player)); return getSoulNetwork(PlayerHelper.getUUIDFromPlayer(player));
} }
public static SoulNetwork getSoulNetwork(Binding binding) {
return getSoulNetwork(binding.getOwnerId());
}
/** /**
* Gets the current orb tier of the SoulNetwork. * Gets the current orb tier of the SoulNetwork.
* *
@ -99,7 +105,7 @@ public class NetworkHelper {
@Deprecated @Deprecated
public static boolean syphonAndDamage(SoulNetwork soulNetwork, EntityPlayer user, int toSyphon) { public static boolean syphonAndDamage(SoulNetwork soulNetwork, EntityPlayer user, int toSyphon) {
// if (soulNetwork.getPlayer() == null) // if (soulNetwork.getNewOwner() == null)
// { // {
// soulNetwork.syphon(toSyphon); // soulNetwork.syphon(toSyphon);
// return true; // return true;
@ -117,15 +123,16 @@ public class NetworkHelper {
*/ */
public static boolean syphonFromContainer(ItemStack stack, int toSyphon) //TODO: Change to a String, int? public static boolean syphonFromContainer(ItemStack stack, int toSyphon) //TODO: Change to a String, int?
{ {
stack = NBTHelper.checkNBT(stack); if (!(stack.getItem() instanceof IBindable))
String ownerName = stack.getTagCompound().getString(Constants.NBT.OWNER_UUID);
if (Strings.isNullOrEmpty(ownerName))
return false; return false;
SoulNetwork network = getSoulNetwork(ownerName); Binding binding = ((IBindable) stack.getItem()).getBinding(stack);
if (binding == null)
return false;
SoulNetworkEvent.ItemDrainInContainerEvent event = new SoulNetworkEvent.ItemDrainInContainerEvent(stack, ownerName, toSyphon); SoulNetwork network = getSoulNetwork(binding);
SoulNetworkEvent.ItemDrainInContainerEvent event = new SoulNetworkEvent.ItemDrainInContainerEvent(stack, binding.getOwnerId(), toSyphon);
return !(MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY) && network.syphon(event.syphon) >= toSyphon; return !(MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY) && network.syphon(event.syphon) >= toSyphon;
} }
@ -138,13 +145,14 @@ public class NetworkHelper {
* @return - If syphoning is possible * @return - If syphoning is possible
*/ */
public static boolean canSyphonFromContainer(ItemStack stack, int toSyphon) { public static boolean canSyphonFromContainer(ItemStack stack, int toSyphon) {
stack = NBTHelper.checkNBT(stack); if (!(stack.getItem() instanceof IBindable))
String ownerName = stack.getTagCompound().getString(Constants.NBT.OWNER_UUID);
if (Strings.isNullOrEmpty(ownerName))
return false; return false;
SoulNetwork network = getSoulNetwork(ownerName); Binding binding = ((IBindable) stack.getItem()).getBinding(stack);
if (binding == null)
return false;
SoulNetwork network = getSoulNetwork(binding);
return network.getCurrentEssence() >= toSyphon; return network.getCurrentEssence() >= toSyphon;
} }

View file

@ -1,12 +1,7 @@
package WayofTime.bloodmagic.util.helper; package WayofTime.bloodmagic.util.helper;
import WayofTime.bloodmagic.util.Constants;
import com.google.common.base.Strings;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraftforge.common.UsernameCache; import net.minecraftforge.common.UsernameCache;
import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.FMLCommonHandler;
@ -23,43 +18,25 @@ public class PlayerHelper {
*/ */
private static final ArrayList<String> knownFakePlayers = Lists.newArrayList(); private static final ArrayList<String> knownFakePlayers = Lists.newArrayList();
public static String getUsernameFromPlayer(EntityPlayer player) { public static EntityPlayer getPlayerFromId(UUID uuid) {
return player.getEntityWorld().isRemote ? "" : UsernameCache.getLastKnownUsername(getUUIDFromPlayer(player));
}
public static EntityPlayer getPlayerFromUsername(String username) {
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
return null; return null;
return FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUsername(username); return FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUUID(uuid);
}
public static EntityPlayer getPlayerFromUUID(String uuid) {
return getPlayerFromUsername(getUsernameFromUUID(uuid));
} }
public static EntityPlayer getPlayerFromUUID(UUID uuid) { public static EntityPlayer getPlayerFromUUID(UUID uuid) {
return getPlayerFromUsername(getUsernameFromUUID(uuid)); return getPlayerFromId(uuid);
} }
public static UUID getUUIDFromPlayer(EntityPlayer player) { public static UUID getUUIDFromPlayer(EntityPlayer player) {
return player.getGameProfile().getId(); return player.getGameProfile().getId();
} }
public static String getUsernameFromUUID(String uuid) {
return UsernameCache.getLastKnownUsername(UUID.fromString(uuid));
}
public static String getUsernameFromUUID(UUID uuid) { public static String getUsernameFromUUID(UUID uuid) {
return UsernameCache.getLastKnownUsername(uuid); return UsernameCache.getLastKnownUsername(uuid);
} }
public static String getUsernameFromStack(ItemStack stack) {
stack = NBTHelper.checkNBT(stack);
return stack.getTagCompound().getString(Constants.NBT.OWNER_NAME);
}
/** /**
* Checks whether or not the given player is an "actual" player * Checks whether or not the given player is an "actual" player
* *
@ -69,23 +46,4 @@ public class PlayerHelper {
public static boolean isFakePlayer(EntityPlayer player) { public static boolean isFakePlayer(EntityPlayer player) {
return player instanceof FakePlayer || (player != null && knownFakePlayers.contains(player.getClass().getCanonicalName())); return player instanceof FakePlayer || (player != null && knownFakePlayers.contains(player.getClass().getCanonicalName()));
} }
public static void causeNauseaToPlayer(ItemStack stack) {
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
return;
stack = NBTHelper.checkNBT(stack);
if (!Strings.isNullOrEmpty(stack.getTagCompound().getString(Constants.NBT.OWNER_UUID)))
causeNauseaToPlayer(stack.getTagCompound().getString(Constants.NBT.OWNER_UUID));
}
public static void causeNauseaToPlayer(String ownerName) {
EntityPlayer player = getPlayerFromUsername(ownerName);
if (player == null)
return;
player.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 80));
}
} }