Search in sources :

Example 1 with ItemActivationCrystal

use of WayofTime.bloodmagic.item.ItemActivationCrystal 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;
}
Also used : Binding(WayofTime.bloodmagic.core.data.Binding) RitualEvent(WayofTime.bloodmagic.event.RitualEvent) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IBindable(WayofTime.bloodmagic.iface.IBindable) SoulNetwork(WayofTime.bloodmagic.core.data.SoulNetwork) ItemActivationCrystal(WayofTime.bloodmagic.item.ItemActivationCrystal)

Aggregations

Binding (WayofTime.bloodmagic.core.data.Binding)1 SoulNetwork (WayofTime.bloodmagic.core.data.SoulNetwork)1 RitualEvent (WayofTime.bloodmagic.event.RitualEvent)1 IBindable (WayofTime.bloodmagic.iface.IBindable)1 ItemActivationCrystal (WayofTime.bloodmagic.item.ItemActivationCrystal)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1