use of WayofTime.bloodmagic.iface.IBindable 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.iface.IBindable in project BloodMagic by WayofTime.
the class RitualExpulsion method performRitual.
@Override
public void performRitual(IMasterRitualStone masterRitualStone) {
World world = masterRitualStone.getWorldObj();
int currentEssence = masterRitualStone.getOwnerNetwork().getCurrentEssence();
if (currentEssence < getRefreshCost()) {
masterRitualStone.getOwnerNetwork().causeNausea();
return;
}
if (masterRitualStone.getWorldObj().isRemote)
return;
AreaDescriptor expulsionRange = getBlockRange(EXPULSION_RANGE);
List<UUID> whitelist = Lists.newArrayList();
BlockPos masterPos = masterRitualStone.getBlockPos();
TileEntity tile = world.getTileEntity(masterPos.up());
if (tile != null) {
IItemHandler handler = Utils.getInventory(tile, null);
if (handler != null) {
for (int i = 0; i < handler.getSlots(); i++) {
ItemStack itemStack = handler.getStackInSlot(i);
if (!itemStack.isEmpty() && itemStack.getItem() instanceof IBindable) {
Binding binding = ((IBindable) itemStack.getItem()).getBinding(itemStack);
if (binding != null && !whitelist.contains(binding.getOwnerId()))
whitelist.add(binding.getOwnerId());
}
}
}
}
final int teleportDistance = 100;
for (EntityPlayer player : world.getEntitiesWithinAABB(EntityPlayer.class, expulsionRange.getAABB(masterRitualStone.getBlockPos()))) {
if (player.capabilities.isCreativeMode || player.getGameProfile().getId().equals(masterRitualStone.getOwner()) || whitelist.contains(player.getGameProfile().getId()))
continue;
if (teleportRandomly(player, teleportDistance))
masterRitualStone.getOwnerNetwork().syphon(getRefreshCost() * 1000);
}
whitelist.clear();
}
use of WayofTime.bloodmagic.iface.IBindable 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.iface.IBindable 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.iface.IBindable 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;
}
Aggregations