Search in sources :

Example 16 with CapManager

use of com.teamwizardry.wizardry.api.capability.CapManager in project Wizardry by TeamWizardry.

the class PotionSteroid method performEffect.

@Override
public void performEffect(@Nonnull EntityLivingBase entityLivingBaseIn, int p_76394_2_) {
    if (!hasEffect(entityLivingBaseIn))
        return;
    CapManager manager = new CapManager(entityLivingBaseIn);
    manager.setMana(manager.getMaxMana());
    manager.setBurnout(0);
}
Also used : CapManager(com.teamwizardry.wizardry.api.capability.CapManager)

Example 17 with CapManager

use of com.teamwizardry.wizardry.api.capability.CapManager in project Wizardry by TeamWizardry.

the class TileCraftingPlate method update.

@Override
public void update() {
    super.update();
    if (!((BlockCraftingPlate) getBlockType()).isStructureComplete(getWorld(), getPos()))
        return;
    if (!new CapManager(getWizardryCap()).isManaFull()) {
        for (BlockPos relative : poses) {
            BlockPos target = getPos().add(relative);
            TileEntity tile = world.getTileEntity(target);
            if (tile != null && tile instanceof TilePearlHolder) {
                if (!((TilePearlHolder) tile).isPartOfStructure) {
                    ((TilePearlHolder) tile).isPartOfStructure = true;
                    ((TilePearlHolder) tile).structurePos = getPos();
                    tile.markDirty();
                }
            }
        }
    }
    for (EntityItem entityItem : world.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(pos))) {
        if (hasInputPearl())
            break;
        if (!isInventoryEmpty() && entityItem.getItem().getItem() instanceof IInfusable) {
            ItemStack stack = entityItem.getItem().copy();
            stack.setCount(1);
            entityItem.getItem().shrink(1);
            inputPearl.getHandler().setStackInSlot(0, stack);
        } else if (!(entityItem.getItem().getItem() instanceof IInfusable)) {
            ItemStack stack = entityItem.getItem().copy();
            stack.setCount(1);
            entityItem.getItem().shrink(1);
            for (int i = 0; i < realInventory.getHandler().getSlots(); i++) {
                if (realInventory.getHandler().getStackInSlot(i).isEmpty()) {
                    realInventory.getHandler().setStackInSlot(i, stack);
                    ClientRunnable.run(new ClientRunnable() {

                        @Override
                        @SideOnly(Side.CLIENT)
                        public void runIfClient() {
                            if (renderHandler != null)
                                ((TileCraftingPlateRenderer) renderHandler).addAnimation();
                        }
                    });
                    break;
                }
            }
        }
        markDirty();
    }
    if (hasInputPearl() && !isInventoryEmpty()) {
        CapManager manager = new CapManager(getInputPearl());
        if (manager.isManaFull()) {
            ArrayList<ItemStack> stacks = new ArrayList<>();
            for (int i = 0; i < realInventory.getHandler().getSlots(); i++) {
                if (!realInventory.getHandler().getStackInSlot(i).isEmpty()) {
                    stacks.add(realInventory.getHandler().getStackInSlot(i));
                    realInventory.getHandler().setStackInSlot(i, ItemStack.EMPTY);
                }
            }
            SpellBuilder builder = new SpellBuilder(stacks, true);
            ItemStack infusedPearl = inputPearl.getHandler().getStackInSlot(0).copy();
            inputPearl.getHandler().setStackInSlot(0, ItemStack.EMPTY);
            outputPearl.getHandler().setStackInSlot(0, infusedPearl);
            NBTTagList list = new NBTTagList();
            for (SpellRing spellRing : builder.getSpell()) {
                list.appendTag(spellRing.serializeNBT());
            }
            ItemNBTHelper.setList(infusedPearl, Constants.NBT.SPELL, list);
            // Color lastColor = SpellUtils.getAverageSpellColor(builder.getSpell());
            // float[] hsv = ColorUtils.getHSVFromColor(lastColor);
            // ItemNBTHelper.setFloat(infusedPearl, "hue", hsv[0]);
            // ItemNBTHelper.setFloat(infusedPearl, "saturation", hsv[1]);
            ItemNBTHelper.setFloat(infusedPearl, Constants.NBT.RAND, world.rand.nextFloat());
            ItemNBTHelper.setString(infusedPearl, "type", EnumPearlType.INFUSED.toString());
            // Process spellData multipliers based on nacre quality
            if (infusedPearl.getItem() instanceof INacreProduct) {
                float purity = ((INacreProduct) infusedPearl.getItem()).getQuality(infusedPearl);
                double multiplier;
                if (purity >= 1f)
                    multiplier = ConfigValues.perfectPearlMultiplier * purity;
                else if (purity <= ConfigValues.damagedPearlMultiplier)
                    multiplier = ConfigValues.damagedPearlMultiplier;
                else {
                    double base = purity - 1;
                    multiplier = 1 - (base * base * base * base);
                }
                for (SpellRing spellRing : SpellUtils.getAllSpellRings(infusedPearl)) spellRing.multiplyMultiplierForAll((float) multiplier);
            }
            ClientRunnable.run(new ClientRunnable() {

                @Override
                @SideOnly(Side.CLIENT)
                public void runIfClient() {
                    if (renderHandler != null)
                        ((TileCraftingPlateRenderer) renderHandler).clearAll();
                }
            });
            markDirty();
            PacketHandler.NETWORK.sendToAllAround(new PacketExplode(new Vec3d(pos).addVector(0.5, 0.5, 0.5), Color.CYAN, Color.BLUE, 2, 2, 500, 300, 20, true), new NetworkRegistry.TargetPoint(world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 256));
            world.playSound(null, getPos(), ModSounds.BASS_BOOM, SoundCategory.BLOCKS, 1f, (float) RandUtil.nextDouble(1, 1.5));
            List<Entity> entityList = world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(pos).grow(32, 32, 32));
            for (Entity entity1 : entityList) {
                double dist = entity1.getDistance(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
                final double upperMag = 3;
                final double scale = 0.8;
                double mag = upperMag * (scale * dist / (-scale * dist - 1) + 1);
                Vec3d dir = entity1.getPositionVector().subtract(new Vec3d(pos).addVector(0.5, 0.5, 0.5)).normalize().scale(mag);
                entity1.motionX = (dir.x);
                entity1.motionY = (dir.y);
                entity1.motionZ = (dir.z);
                entity1.fallDistance = 0;
                entity1.velocityChanged = true;
                if (entity1 instanceof EntityPlayerMP)
                    ((EntityPlayerMP) entity1).connection.sendPacket(new SPacketEntityVelocity(entity1));
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) PacketExplode(com.teamwizardry.wizardry.common.network.PacketExplode) ArrayList(java.util.ArrayList) SpellBuilder(com.teamwizardry.wizardry.api.spell.SpellBuilder) IInfusable(com.teamwizardry.wizardry.api.item.IInfusable) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) TileEntity(net.minecraft.tileentity.TileEntity) NBTTagList(net.minecraft.nbt.NBTTagList) SPacketEntityVelocity(net.minecraft.network.play.server.SPacketEntityVelocity) NetworkRegistry(net.minecraftforge.fml.common.network.NetworkRegistry) BlockPos(net.minecraft.util.math.BlockPos) TileCraftingPlateRenderer(com.teamwizardry.wizardry.client.render.block.TileCraftingPlateRenderer) EntityItem(net.minecraft.entity.item.EntityItem) ClientRunnable(com.teamwizardry.librarianlib.features.utilities.client.ClientRunnable) Vec3d(net.minecraft.util.math.Vec3d) CapManager(com.teamwizardry.wizardry.api.capability.CapManager) SpellRing(com.teamwizardry.wizardry.api.spell.SpellRing) INacreProduct(com.teamwizardry.wizardry.api.item.INacreProduct) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack)

Example 18 with CapManager

use of com.teamwizardry.wizardry.api.capability.CapManager in project Wizardry by TeamWizardry.

the class TileManaBattery method update.

@Override
public void update() {
    super.update();
    if (getBlockType() == ModBlocks.MANA_BATTERY && !((BlockManaBattery) getBlockType()).isStructureComplete(getWorld(), getPos()))
        return;
    if (getBlockType() != ModBlocks.CREATIVE_MANA_BATTERY) {
        for (BlockPos relative : poses) {
            BlockPos target = getPos().add(relative);
            TileEntity tile = world.getTileEntity(target);
            if (tile instanceof TilePearlHolder) {
                if (!((TilePearlHolder) tile).isPartOfStructure) {
                    ((TilePearlHolder) tile).isPartOfStructure = true;
                    ((TilePearlHolder) tile).structurePos = getPos();
                    ((TilePearlHolder) tile).setAllowOutsideSucking(false);
                    tile.markDirty();
                }
            }
        }
    } else {
        CapManager manager = new CapManager(getWizardryCap());
        manager.setMana(manager.getMaxMana());
        manager.setBurnout(0);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) CapManager(com.teamwizardry.wizardry.api.capability.CapManager) BlockManaBattery(com.teamwizardry.wizardry.common.block.BlockManaBattery) BlockPos(net.minecraft.util.math.BlockPos)

Example 19 with CapManager

use of com.teamwizardry.wizardry.api.capability.CapManager in project Wizardry by TeamWizardry.

the class TileManaBattery method onSuckFrom.

@Override
public void onSuckFrom(TileManaInteracter from) {
    super.onSuckFrom(from);
    CapManager manager = new CapManager(from.getWizardryCap());
    if (from instanceof TilePearlHolder && manager.isManaEmpty()) {
        ((TilePearlHolder) from).setItemStack(ItemStack.EMPTY);
        from.markDirty();
        world.playSound(null, from.getPos().getX(), from.getPos().getY(), from.getPos().getZ(), ModSounds.GLASS_BREAK, SoundCategory.AMBIENT, 0.5F, (RandUtil.nextFloat() * 0.4F) + 0.8F);
        PacketHandler.NETWORK.sendToAllAround(new PacketExplode(new Vec3d(from.getPos()).addVector(0.5, 0.5, 0.5), Color.CYAN, Color.BLUE, 0.5, 0.5, 50, 50, 10, true), new NetworkRegistry.TargetPoint(world.provider.getDimension(), from.getPos().getX(), from.getPos().getY(), from.getPos().getZ(), 128));
    }
}
Also used : CapManager(com.teamwizardry.wizardry.api.capability.CapManager) PacketExplode(com.teamwizardry.wizardry.common.network.PacketExplode) NetworkRegistry(net.minecraftforge.fml.common.network.NetworkRegistry) Vec3d(net.minecraft.util.math.Vec3d)

Example 20 with CapManager

use of com.teamwizardry.wizardry.api.capability.CapManager in project Wizardry by TeamWizardry.

the class HudEventHandler method renderHud.

@SubscribeEvent
public void renderHud(Post event) {
    ScaledResolution resolution = event.getResolution();
    int width = resolution.getScaledWidth();
    int height = resolution.getScaledHeight();
    EntityPlayer player = Minecraft.getMinecraft().player;
    ItemStack stack = BaublesSupport.getItem(player, ModItems.FAKE_HALO, ModItems.CREATIVE_HALO, ModItems.REAL_HALO);
    if (stack == null || stack.isEmpty())
        return;
    if (event.getType() == ElementType.EXPERIENCE) {
        HUD_TEXTURE.bind();
        GlStateManager.pushMatrix();
        GlStateManager.color(1.0F, 1.0F, 1.0F);
        int right = ((width / 2) - (100 / 2)) + 145;
        int top = height - 17;
        emptyManaBar.draw(ClientTickHandler.getTicks(), right, top);
        emptyBurnoutBar.draw(ClientTickHandler.getTicks(), right, top + 6);
        GlStateManager.popMatrix();
        CapManager manager = new CapManager(player);
        GlStateManager.pushMatrix();
        GlStateManager.color(1.0F, 1.0F, 1.0F);
        int visualManaLength = 0;
        if (manager.getMana() > 0)
            visualManaLength = (int) (((manager.getMana() * 100) / manager.getMaxMana()) % 101);
        fullManaBar.drawClipped(ClientTickHandler.getTicks(), right, top, visualManaLength, 5);
        GlStateManager.color(1.0F, 1.0F, 1.0F);
        int visualBurnoutLength = 0;
        if (manager.getBurnout() > 0)
            visualBurnoutLength = (int) (((manager.getBurnout() * 100) / manager.getMaxBurnout()) % 101);
        fullBurnoutBar.drawClipped(ClientTickHandler.getTicks(), right, top + 6, visualBurnoutLength, 5);
        GlStateManager.popMatrix();
    }
}
Also used : CapManager(com.teamwizardry.wizardry.api.capability.CapManager) ScaledResolution(net.minecraft.client.gui.ScaledResolution) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

CapManager (com.teamwizardry.wizardry.api.capability.CapManager)26 Vec3d (net.minecraft.util.math.Vec3d)8 BlockPos (net.minecraft.util.math.BlockPos)6 ItemStack (net.minecraft.item.ItemStack)5 Entity (net.minecraft.entity.Entity)4 EntityLivingBase (net.minecraft.entity.EntityLivingBase)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 TileEntity (net.minecraft.tileentity.TileEntity)3 ParticleBuilder (com.teamwizardry.librarianlib.features.particle.ParticleBuilder)2 InterpFadeInOut (com.teamwizardry.librarianlib.features.particle.functions.InterpFadeInOut)2 ClientRunnable (com.teamwizardry.librarianlib.features.utilities.client.ClientRunnable)2 IWizardryCapability (com.teamwizardry.wizardry.api.capability.IWizardryCapability)2 PacketExplode (com.teamwizardry.wizardry.common.network.PacketExplode)2 TilePearlHolder (com.teamwizardry.wizardry.common.tile.TilePearlHolder)2 EntityItem (net.minecraft.entity.item.EntityItem)2 PotionEffect (net.minecraft.potion.PotionEffect)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 NetworkRegistry (net.minecraftforge.fml.common.network.NetworkRegistry)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 BasicAnimation (com.teamwizardry.librarianlib.features.animator.animations.BasicAnimation)1