Search in sources :

Example 1 with IBindable

use of WayofTime.bloodmagic.iface.IBindable in project BloodMagic by WayofTime.

the class SubCommandBind method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    if (commandSender.getEntityWorld().isRemote)
        return;
    try {
        EntityPlayer player = CommandBase.getCommandSenderAsPlayer(commandSender);
        ItemStack held = player.getHeldItemMainhand();
        boolean bind = true;
        if (held.getItem() instanceof IBindable) {
            if (args.length > 0) {
                if (args[0].equalsIgnoreCase("help"))
                    return;
                if (isBoolean(args[0])) {
                    bind = Boolean.parseBoolean(args[0]);
                    if (args.length > 2)
                        player = CommandBase.getPlayer(server, commandSender, args[1]);
                } else {
                    player = CommandBase.getPlayer(server, commandSender, args[0]);
                }
            }
            if (bind) {
                Binding binding = new Binding(player.getGameProfile().getId(), player.getGameProfile().getName());
                BindableHelper.applyBinding(held, binding);
                commandSender.sendMessage(new TextComponentTranslation("commands.bind.success"));
            } else {
                Binding binding = ((IBindable) held.getItem()).getBinding(held);
                if (binding != null) {
                    held.getTagCompound().removeTag("binding");
                    commandSender.sendMessage(new TextComponentTranslation("commands.bind.remove.success"));
                }
            }
        }
    } catch (PlayerNotFoundException e) {
        commandSender.sendMessage(new TextComponentTranslation(TextHelper.localizeEffect("commands.error.404")));
    }
}
Also used : Binding(WayofTime.bloodmagic.core.data.Binding) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IBindable(WayofTime.bloodmagic.iface.IBindable) EntityPlayer(net.minecraft.entity.player.EntityPlayer) PlayerNotFoundException(net.minecraft.command.PlayerNotFoundException) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IBindable

use of WayofTime.bloodmagic.iface.IBindable in project BloodMagic by WayofTime.

the class BloodAltar method updateAltar.

private void updateAltar() {
    if (!isActive) {
        if (cooldownAfterCrafting > 0)
            cooldownAfterCrafting--;
        return;
    }
    ItemStack input = tileAltar.getStackInSlot(0);
    if (input.isEmpty())
        return;
    World world = tileAltar.getWorld();
    BlockPos pos = tileAltar.getPos();
    if (world.isRemote)
        return;
    if (!canBeFilled) {
        boolean hasOperated = false;
        int stackSize = input.getCount();
        if (totalCharge > 0) {
            int chargeDrained = Math.min(liquidRequired * stackSize - progress, totalCharge);
            totalCharge -= chargeDrained;
            progress += chargeDrained;
            hasOperated = true;
        }
        if (fluid != null && fluid.amount >= 1) {
            int liquidDrained = Math.min((int) (altarTier.ordinal() >= 2 ? consumptionRate * (1 + consumptionMultiplier) : consumptionRate), fluid.amount);
            if (liquidDrained > (liquidRequired * stackSize - progress))
                liquidDrained = liquidRequired * stackSize - progress;
            fluid.amount = fluid.amount - liquidDrained;
            progress += liquidDrained;
            hasOperated = true;
            if (internalCounter % 4 == 0 && world instanceof WorldServer) {
                WorldServer server = (WorldServer) world;
                server.spawnParticle(EnumParticleTypes.REDSTONE, pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, 1, 0.2, 0, 0.2, 0);
            }
        } else if (!hasOperated && progress > 0) {
            progress -= (int) (efficiencyMultiplier * drainRate);
            if (internalCounter % 2 == 0 && world instanceof WorldServer) {
                WorldServer server = (WorldServer) world;
                server.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, 1, 0.1, 0, 0.1, 0);
            }
        }
        if (hasOperated) {
            if (progress >= liquidRequired * stackSize) {
                ItemStack result = ItemHandlerHelper.copyStackWithSize(recipe.getOutput(), stackSize);
                BloodMagicCraftedEvent.Altar event = new BloodMagicCraftedEvent.Altar(recipe.getInput(), result);
                MinecraftForge.EVENT_BUS.post(event);
                tileAltar.setInventorySlotContents(0, event.getOutput());
                progress = 0;
                if (world instanceof WorldServer) {
                    WorldServer server = (WorldServer) world;
                    server.spawnParticle(EnumParticleTypes.REDSTONE, pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, 40, 0.3, 0, 0.3, 0);
                }
                this.cooldownAfterCrafting = 30;
                this.isActive = false;
            }
        }
    } else {
        ItemStack contained = tileAltar.getStackInSlot(0);
        if (contained.isEmpty() || !(contained.getItem() instanceof IBloodOrb) || !(contained.getItem() instanceof IBindable))
            return;
        BloodOrb orb = ((IBloodOrb) contained.getItem()).getOrb(contained);
        Binding binding = ((IBindable) contained.getItem()).getBinding(contained);
        if (binding == null || orb == null)
            return;
        if (fluid != null && fluid.amount >= 1) {
            int liquidDrained = Math.min((int) (altarTier.ordinal() >= 2 ? orb.getFillRate() * (1 + consumptionMultiplier) : orb.getFillRate()), fluid.amount);
            int drain = NetworkHelper.getSoulNetwork(binding).add(liquidDrained, (int) (orb.getCapacity() * this.orbCapacityMultiplier));
            fluid.amount = fluid.amount - drain;
            if (drain > 0 && internalCounter % 4 == 0 && world instanceof WorldServer) {
                WorldServer server = (WorldServer) world;
                server.spawnParticle(EnumParticleTypes.SPELL_WITCH, pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, 1, 0, 0, 0, 0.001);
            }
        }
    }
    tileAltar.getWorld().notifyBlockUpdate(tileAltar.getPos(), tileAltar.getWorld().getBlockState(tileAltar.getPos()), tileAltar.getWorld().getBlockState(tileAltar.getPos()), 3);
}
Also used : Binding(WayofTime.bloodmagic.core.data.Binding) IBindable(WayofTime.bloodmagic.iface.IBindable) IBloodOrb(WayofTime.bloodmagic.orb.IBloodOrb) BloodOrb(WayofTime.bloodmagic.orb.BloodOrb) IBloodOrb(WayofTime.bloodmagic.orb.IBloodOrb) WorldServer(net.minecraft.world.WorldServer) BloodMagicCraftedEvent(WayofTime.bloodmagic.api.event.BloodMagicCraftedEvent) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) RecipeBloodAltar(WayofTime.bloodmagic.api.impl.recipe.RecipeBloodAltar) TileAltar(WayofTime.bloodmagic.tile.TileAltar)

Example 3 with IBindable

use of WayofTime.bloodmagic.iface.IBindable in project BloodMagic by WayofTime.

the class ItemSigilHolding method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack stack = player.getHeldItem(hand);
    if (PlayerHelper.isFakePlayer(player))
        return ActionResult.newResult(EnumActionResult.FAIL, stack);
    int currentSlot = getCurrentItemOrdinal(stack);
    List<ItemStack> inv = getInternalInventory(stack);
    ItemStack itemUsing = inv.get(currentSlot);
    if (itemUsing.isEmpty() || ((IBindable) itemUsing.getItem()).getBinding(stack) == null)
        return ActionResult.newResult(EnumActionResult.PASS, stack);
    itemUsing.getItem().onItemRightClick(world, player, hand);
    saveInventory(stack, inv);
    return ActionResult.newResult(EnumActionResult.PASS, stack);
}
Also used : IBindable(WayofTime.bloodmagic.iface.IBindable) ItemStack(net.minecraft.item.ItemStack)

Example 4 with IBindable

use of WayofTime.bloodmagic.iface.IBindable in project BloodMagic by WayofTime.

the class ItemSigilHolding method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stack = player.getHeldItem(hand);
    if (PlayerHelper.isFakePlayer(player))
        return EnumActionResult.FAIL;
    int currentSlot = getCurrentItemOrdinal(stack);
    List<ItemStack> inv = getInternalInventory(stack);
    ItemStack itemUsing = inv.get(currentSlot);
    if (itemUsing.isEmpty() || ((IBindable) itemUsing.getItem()).getBinding(stack) == null)
        return EnumActionResult.PASS;
    EnumActionResult result = itemUsing.getItem().onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);
    saveInventory(stack, inv);
    return result;
}
Also used : IBindable(WayofTime.bloodmagic.iface.IBindable) ItemStack(net.minecraft.item.ItemStack)

Example 5 with IBindable

use of WayofTime.bloodmagic.iface.IBindable 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

IBindable (WayofTime.bloodmagic.iface.IBindable)10 Binding (WayofTime.bloodmagic.core.data.Binding)8 ItemStack (net.minecraft.item.ItemStack)7 SoulNetwork (WayofTime.bloodmagic.core.data.SoulNetwork)5 BloodOrb (WayofTime.bloodmagic.orb.BloodOrb)3 IBloodOrb (WayofTime.bloodmagic.orb.IBloodOrb)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 TileAltar (WayofTime.bloodmagic.tile.TileAltar)2 TileEntity (net.minecraft.tileentity.TileEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)2 World (net.minecraft.world.World)2 BloodMagicCraftedEvent (WayofTime.bloodmagic.api.event.BloodMagicCraftedEvent)1 RecipeBloodAltar (WayofTime.bloodmagic.api.impl.recipe.RecipeBloodAltar)1 ItemBindEvent (WayofTime.bloodmagic.event.ItemBindEvent)1 RitualEvent (WayofTime.bloodmagic.event.RitualEvent)1 SoulNetworkEvent (WayofTime.bloodmagic.event.SoulNetworkEvent)1 ItemActivationCrystal (WayofTime.bloodmagic.item.ItemActivationCrystal)1 UUID (java.util.UUID)1 PlayerNotFoundException (net.minecraft.command.PlayerNotFoundException)1