Search in sources :

Example 1 with BloodOrb

use of WayofTime.bloodmagic.orb.BloodOrb in project BloodMagic by WayofTime.

the class ItemBloodOrb method addInformation.

@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag flag) {
    tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.orb.desc"));
    BloodOrb orb = getOrb(stack);
    if (flag.isAdvanced() && orb != null)
        tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.orb.owner", orb.getRegistryName().getResourceDomain()));
    super.addInformation(stack, world, tooltip, flag);
}
Also used : BloodOrb(WayofTime.bloodmagic.orb.BloodOrb) IBloodOrb(WayofTime.bloodmagic.orb.IBloodOrb) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with BloodOrb

use of WayofTime.bloodmagic.orb.BloodOrb in project BloodMagic by WayofTime.

the class ItemBloodOrb method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack stack = player.getHeldItem(hand);
    BloodOrb orb = getOrb(stack);
    if (orb == null)
        return ActionResult.newResult(EnumActionResult.FAIL, stack);
    if (world == null)
        return super.onItemRightClick(world, player, hand);
    world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F);
    if (PlayerHelper.isFakePlayer(player))
        return super.onItemRightClick(world, player, hand);
    if (!stack.hasTagCompound())
        return super.onItemRightClick(world, player, hand);
    Binding binding = getBinding(stack);
    if (binding == null)
        return super.onItemRightClick(world, player, hand);
    if (world.isRemote)
        return super.onItemRightClick(world, player, hand);
    SoulNetwork ownerNetwork = NetworkHelper.getSoulNetwork(binding);
    if (binding.getOwnerId().equals(player.getGameProfile().getId()))
        ownerNetwork.setOrbTier(orb.getTier());
    // Add LP to owner's network
    ownerNetwork.add(200, orb.getCapacity());
    // Hurt whoever is using it
    ownerNetwork.hurtPlayer(player, 200);
    return super.onItemRightClick(world, player, hand);
}
Also used : Binding(WayofTime.bloodmagic.core.data.Binding) BloodOrb(WayofTime.bloodmagic.orb.BloodOrb) IBloodOrb(WayofTime.bloodmagic.orb.IBloodOrb) SoulNetwork(WayofTime.bloodmagic.core.data.SoulNetwork) ItemStack(net.minecraft.item.ItemStack)

Example 3 with BloodOrb

use of WayofTime.bloodmagic.orb.BloodOrb 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 4 with BloodOrb

use of WayofTime.bloodmagic.orb.BloodOrb in project BloodMagic by WayofTime.

the class RegistrarBloodMagic method registerModels.

@SideOnly(Side.CLIENT)
@SubscribeEvent
public static void registerModels(ModelRegistryEvent event) {
    for (BloodOrb orb : BLOOD_ORBS) {
        ModelResourceLocation modelLocation = orb.getModelLocation();
        if (modelLocation == null)
            modelLocation = new ModelResourceLocation(orb.getRegistryName(), "inventory");
        ModelLoader.registerItemVariants(RegistrarBloodMagicItems.BLOOD_ORB, modelLocation);
    }
    ModelLoader.setCustomMeshDefinition(RegistrarBloodMagicItems.BLOOD_ORB, stack -> {
        if (!stack.hasTagCompound())
            return new ModelResourceLocation(ORB_WEAK.getRegistryName(), "inventory");
        BloodOrb orb = BLOOD_ORBS.getValue(new ResourceLocation(stack.getTagCompound().getString("orb")));
        if (orb == null || orb.getModelLocation() == null)
            return new ModelResourceLocation(ORB_WEAK.getRegistryName(), "inventory");
        return orb.getModelLocation();
    });
}
Also used : BloodOrb(WayofTime.bloodmagic.orb.BloodOrb) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 5 with BloodOrb

use of WayofTime.bloodmagic.orb.BloodOrb 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());
    }
}
Also used : Binding(WayofTime.bloodmagic.core.data.Binding) IBindable(WayofTime.bloodmagic.iface.IBindable) SoulNetwork(WayofTime.bloodmagic.core.data.SoulNetwork) IBloodOrb(WayofTime.bloodmagic.orb.IBloodOrb) BloodOrb(WayofTime.bloodmagic.orb.BloodOrb) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IBloodOrb(WayofTime.bloodmagic.orb.IBloodOrb) ItemBindEvent(WayofTime.bloodmagic.event.ItemBindEvent) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

BloodOrb (WayofTime.bloodmagic.orb.BloodOrb)8 IBloodOrb (WayofTime.bloodmagic.orb.IBloodOrb)6 ItemStack (net.minecraft.item.ItemStack)5 Binding (WayofTime.bloodmagic.core.data.Binding)4 SoulNetwork (WayofTime.bloodmagic.core.data.SoulNetwork)3 IBindable (WayofTime.bloodmagic.iface.IBindable)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3 TileAltar (WayofTime.bloodmagic.tile.TileAltar)2 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 BloodMagicCraftedEvent (WayofTime.bloodmagic.api.event.BloodMagicCraftedEvent)1 RecipeBloodAltar (WayofTime.bloodmagic.api.impl.recipe.RecipeBloodAltar)1 ItemBindEvent (WayofTime.bloodmagic.event.ItemBindEvent)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 TileEntity (net.minecraft.tileentity.TileEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1 WorldServer (net.minecraft.world.WorldServer)1