use of WayofTime.bloodmagic.event.ItemBindEvent 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());
}
}
Aggregations