use of WayofTime.bloodmagic.core.data.Binding 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.Binding 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;
}
use of WayofTime.bloodmagic.core.data.Binding in project BloodMagic by WayofTime.
the class BlockAltar method getComparatorInputOverride.
@Override
public int getComparatorInputOverride(IBlockState state, World world, BlockPos pos) {
if (world.isRemote)
return 0;
TileEntity tile = world.getTileEntity(pos);
if (tile != null && tile instanceof TileAltar) {
TileAltar altar = (TileAltar) tile;
ItemStack orbStack = altar.getStackInSlot(0);
if (world.getBlockState(pos.down()).getBlock() instanceof BlockDecorative) {
if (orbStack.getItem() instanceof IBloodOrb && orbStack.getItem() instanceof IBindable) {
BloodOrb orb = ((IBloodOrb) orbStack.getItem()).getOrb(orbStack);
Binding binding = ((IBindable) orbStack.getItem()).getBinding(orbStack);
if (orb != null && binding != null) {
SoulNetwork soulNetwork = NetworkHelper.getSoulNetwork(binding);
int maxEssence = orb.getCapacity();
int currentEssence = soulNetwork.getCurrentEssence();
int level = currentEssence * 15 / maxEssence;
return Math.min(15, level) % 16;
}
}
} else {
int maxEssence = altar.getCapacity();
int currentEssence = altar.getCurrentBlood();
int level = currentEssence * 15 / maxEssence;
return Math.min(15, level) % 16;
}
}
return 0;
}
use of WayofTime.bloodmagic.core.data.Binding in project BloodMagic by WayofTime.
the class ItemBoundSword method addInformation.
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag flag) {
if (!stack.hasTagCompound())
return;
if (TextHelper.canTranslate("tooltip.bloodmagic.bound.sword.desc"))
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.bound.sword.desc"));
tooltip.add(TextHelper.localize("tooltip.bloodmagic." + (getActivated(stack) ? "activated" : "deactivated")));
Binding binding = getBinding(stack);
if (binding != null)
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", binding.getOwnerName()));
}
use of WayofTime.bloodmagic.core.data.Binding in project BloodMagic by WayofTime.
the class ItemActivationCrystal method addInformation.
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag flag) {
tooltip.add(TextHelper.localize("tooltip.bloodmagic.activation_crystal." + getItemType(stack).getInternalName()));
if (!stack.hasTagCompound())
return;
Binding binding = getBinding(stack);
if (binding != null)
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", binding.getOwnerName()));
super.addInformation(stack, world, tooltip, flag);
}
Aggregations