use of WayofTime.bloodmagic.core.data.SoulNetwork in project BloodMagic by WayofTime.
the class TileMasterRitualStone method activateRitual.
@Override
public boolean activateRitual(ItemStack activationCrystal, @Nullable EntityPlayer activator, Ritual ritual) {
if (PlayerHelper.isFakePlayer(activator))
return false;
Binding binding = ((IBindable) activationCrystal.getItem()).getBinding(activationCrystal);
if (binding != null && ritual != null) {
if (activationCrystal.getItem() instanceof ItemActivationCrystal) {
int crystalLevel = ((ItemActivationCrystal) activationCrystal.getItem()).getCrystalLevel(activationCrystal);
if (RitualHelper.canCrystalActivate(ritual, crystalLevel)) {
if (!getWorld().isRemote) {
SoulNetwork network = NetworkHelper.getSoulNetwork(binding);
if (!isRedstoned() && network.getCurrentEssence() < ritual.getActivationCost() && (activator != null && !activator.capabilities.isCreativeMode)) {
activator.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.ritual.weak"), true);
return false;
}
if (currentRitual != null)
currentRitual.stopRitual(this, Ritual.BreakType.ACTIVATE);
RitualEvent.RitualActivatedEvent event = new RitualEvent.RitualActivatedEvent(this, binding.getOwnerId(), ritual, activator, activationCrystal, crystalLevel);
if (MinecraftForge.EVENT_BUS.post(event)) {
if (activator != null)
activator.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.ritual.prevent"), true);
return false;
}
if (ritual.activateRitual(this, activator, binding.getOwnerId())) {
if (!isRedstoned() && (activator != null && !activator.capabilities.isCreativeMode))
network.syphon(ritual.getActivationCost());
if (activator != null)
activator.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.ritual.activate"), true);
this.active = true;
this.owner = binding.getOwnerId();
this.cachedNetwork = network;
this.currentRitual = ritual;
notifyUpdate();
return true;
}
}
notifyUpdate();
return true;
}
}
} else {
if (activator != null)
activator.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.ritual.notValid"), true);
}
return false;
}
use of WayofTime.bloodmagic.core.data.SoulNetwork in project BloodMagic by WayofTime.
the class NetworkHelper method canSyphonFromContainer.
/**
* Checks if the ItemStack has a user to be syphoned from.
*
* @param stack - ItemStack to check
* @param toSyphon - Amount of LP to syphon
* @return - If syphoning is possible
*/
public static boolean canSyphonFromContainer(ItemStack stack, int toSyphon) {
if (!(stack.getItem() instanceof IBindable))
return false;
Binding binding = ((IBindable) stack.getItem()).getBinding(stack);
if (binding == null)
return false;
SoulNetwork network = getSoulNetwork(binding);
return network.getCurrentEssence() >= toSyphon;
}
use of WayofTime.bloodmagic.core.data.SoulNetwork in project BloodMagic by WayofTime.
the class SubCommandOrb method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
if (args.length > 0) {
if (args[0].equalsIgnoreCase("help"))
return;
try {
String givenName = commandSender.getName();
if (args.length > 1)
givenName = args[1];
EntityPlayer player = CommandBase.getPlayer(server, commandSender, givenName);
String uuid = PlayerHelper.getUUIDFromPlayer(player).toString();
SoulNetwork network = NetworkHelper.getSoulNetwork(uuid);
boolean displayHelp = args.length > 0 && args.length < 2;
try {
switch(ValidCommands.valueOf(args[0].toUpperCase(Locale.ENGLISH))) {
case SET:
{
if (displayHelp) {
CommandBloodMagic.displayHelpString(commandSender, ValidCommands.SET.help);
break;
}
if (args.length == 3) {
if (Utils.isInteger(args[2])) {
int amount = Integer.parseInt(args[2]);
network.setOrbTier(amount);
CommandBloodMagic.displaySuccessString(commandSender, "commands.success");
} else {
CommandBloodMagic.displayErrorString(commandSender, "commands.error.arg.invalid");
}
} else {
CommandBloodMagic.displayErrorString(commandSender, "commands.error.arg.missing");
}
break;
}
case GET:
{
if (displayHelp) {
CommandBloodMagic.displayHelpString(commandSender, ValidCommands.GET.help);
break;
}
if (args.length > 1)
commandSender.sendMessage(new TextComponentString(TextHelper.localizeEffect("message.orb.currenttier", network.getOrbTier())));
break;
}
}
} catch (IllegalArgumentException e) {
CommandBloodMagic.displayErrorString(commandSender, "commands.error.404");
}
} catch (PlayerNotFoundException e) {
CommandBloodMagic.displayErrorString(commandSender, "commands.error.404");
}
}
}
use of WayofTime.bloodmagic.core.data.SoulNetwork in project BloodMagic by WayofTime.
the class GenericHandler method onInteract.
// Handles binding of IBindable's as well as setting a player's highest orb tier
@SubscribeEvent
public static void onInteract(PlayerInteractEvent.RightClickItem event) {
if (event.getWorld().isRemote)
return;
EntityPlayer player = event.getEntityPlayer();
if (PlayerHelper.isFakePlayer(player))
return;
ItemStack held = event.getItemStack();
if (!held.isEmpty() && held.getItem() instanceof IBindable) {
// Make sure it's bindable
IBindable bindable = (IBindable) held.getItem();
Binding binding = bindable.getBinding(held);
if (binding == null) {
// If the binding is null, let's create one
if (bindable.onBind(player, held)) {
ItemBindEvent toPost = new ItemBindEvent(player, held);
if (// Allow cancellation of binding
MinecraftForge.EVENT_BUS.post(toPost))
return;
// Bind item to the player
BindableHelper.applyBinding(held, player);
}
// If the binding exists, we'll check if the player's name has changed since they last used it and update that if so.
} 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) {
IBloodOrb bloodOrb = (IBloodOrb) held.getItem();
SoulNetwork network = NetworkHelper.getSoulNetwork(player);
BloodOrb orb = bloodOrb.getOrb(held);
if (orb == null)
return;
if (orb.getTier() > network.getOrbTier())
network.setOrbTier(orb.getTier());
}
}
use of WayofTime.bloodmagic.core.data.SoulNetwork in project BloodMagic by WayofTime.
the class NetworkHelper method syphonFromContainer.
/**
* Syphons a player from within a container.
*
* @param stack - ItemStack in the Container.
* @param toSyphon - Amount of LP to syphon
* @return - If the syphon was successful.
*/
public static // TODO: Change to a String, int?
boolean syphonFromContainer(// TODO: Change to a String, int?
ItemStack stack, // TODO: Change to a String, int?
int toSyphon) {
if (!(stack.getItem() instanceof IBindable))
return false;
Binding binding = ((IBindable) stack.getItem()).getBinding(stack);
if (binding == null)
return false;
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;
}
Aggregations