Search in sources :

Example 11 with ClientRunnable

use of com.teamwizardry.librarianlib.features.utilities.client.ClientRunnable in project Wizardry by TeamWizardry.

the class EntitySpiritWight method attackEntityFrom.

@Override
public boolean attackEntityFrom(@Nonnull DamageSource source, float amount) {
    if (source.isMagicDamage()) {
        super.attackEntityFrom(source, amount);
        ClientRunnable.run(new ClientRunnable() {

            @Override
            @SideOnly(Side.CLIENT)
            public void runIfClient() {
                LibParticles.SPIRIT_WIGHT_HURT(world, getPositionVector());
            }
        });
        return true;
    } else
        return false;
}
Also used : SideOnly(net.minecraftforge.fml.relauncher.SideOnly) ClientRunnable(com.teamwizardry.librarianlib.features.utilities.client.ClientRunnable)

Example 12 with ClientRunnable

use of com.teamwizardry.librarianlib.features.utilities.client.ClientRunnable in project Wizardry by TeamWizardry.

the class EntityCorruptionProjectile method onUpdate.

@Override
public void onUpdate() {
    super.onUpdate();
    if (this.onGround) {
        this.setDead();
        EntityCorruptionArea area = new EntityCorruptionArea(this.world, this.posX, this.posY, this.posZ);
        this.world.spawnEntity(area);
    }
    ClientRunnable.run(new ClientRunnable() {

        @Override
        @SideOnly(Side.CLIENT)
        public void runIfClient() {
        }
    });
}
Also used : SideOnly(net.minecraftforge.fml.relauncher.SideOnly) ClientRunnable(com.teamwizardry.librarianlib.features.utilities.client.ClientRunnable)

Example 13 with ClientRunnable

use of com.teamwizardry.librarianlib.features.utilities.client.ClientRunnable 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 14 with ClientRunnable

use of com.teamwizardry.librarianlib.features.utilities.client.ClientRunnable in project Wizardry by TeamWizardry.

the class BlockCraftingPlate method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack heldItem = playerIn.getHeldItem(hand);
    if (isStructureComplete(worldIn, pos)) {
        TileCraftingPlate plate = getTE(worldIn, pos);
        if (!plate.inputPearl.getHandler().getStackInSlot(0).isEmpty())
            return false;
        if (!heldItem.isEmpty()) {
            if (heldItem.getItem() == ModItems.BOOK && playerIn.isCreative()) {
                ItemStack pearl = new ItemStack(ModItems.PEARL_NACRE);
                NBTTagList spellList = ItemNBTHelper.getList(heldItem, Constants.NBT.SPELL, net.minecraftforge.common.util.Constants.NBT.TAG_COMPOUND);
                if (spellList == null)
                    return false;
                SpellBuilder builder = new SpellBuilder(SpellUtils.getSpellChains(spellList), true, true);
                // Color lastColor = SpellUtils.getAverageSpellColor(builder.getSpell());
                // 
                // float[] hsv = ColorUtils.getHSVFromColor(lastColor);
                // ItemNBTHelper.setFloat(pearl, "hue", hsv[0]);
                // ItemNBTHelper.setFloat(pearl, "saturation", hsv[1]);
                ItemNBTHelper.setFloat(pearl, Constants.NBT.RAND, playerIn.world.rand.nextFloat());
                ItemNBTHelper.setList(pearl, Constants.NBT.SPELL, spellList);
                plate.outputPearl.getHandler().setStackInSlot(0, pearl);
                plate.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, false), new NetworkRegistry.TargetPoint(worldIn.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 256));
                worldIn.playSound(null, pos, ModSounds.BASS_BOOM, SoundCategory.BLOCKS, 1f, (float) RandUtil.nextDouble(1, 1.5));
                return true;
            } else {
                ItemStack stack = heldItem.copy();
                stack.setCount(1);
                heldItem.shrink(1);
                if (!plate.isInventoryEmpty() && stack.getItem() instanceof IInfusable) {
                    plate.inputPearl.getHandler().setStackInSlot(0, stack);
                } else if (!(stack.getItem() instanceof IInfusable)) {
                    for (int i = 0; i < plate.realInventory.getHandler().getSlots(); i++) {
                        if (plate.realInventory.getHandler().getStackInSlot(i).isEmpty()) {
                            plate.realInventory.getHandler().setStackInSlot(i, stack);
                            ClientRunnable.run(new ClientRunnable() {

                                @Override
                                @SideOnly(Side.CLIENT)
                                public void runIfClient() {
                                    if (plate.renderHandler != null)
                                        ((TileCraftingPlateRenderer) plate.renderHandler).addAnimation();
                                }
                            });
                            break;
                        }
                    }
                }
                playerIn.openContainer.detectAndSendChanges();
                worldIn.notifyBlockUpdate(pos, state, state, 3);
                return true;
            }
        } else {
            if (plate.hasOutputPearl()) {
                playerIn.setHeldItem(hand, plate.outputPearl.getHandler().extractItem(0, 1, false));
                playerIn.openContainer.detectAndSendChanges();
                worldIn.notifyBlockUpdate(pos, state, state, 3);
                return true;
            } else {
                boolean empty = true;
                for (int i = 0; i < plate.realInventory.getHandler().getSlots(); i++) {
                    if (!plate.realInventory.getHandler().getStackInSlot(i).isEmpty()) {
                        empty = false;
                        break;
                    }
                }
                if (!empty) {
                    for (int i = plate.realInventory.getHandler().getSlots() - 1; i >= 0; i--) {
                        ItemStack extracted = plate.realInventory.getHandler().getStackInSlot(i);
                        if (!extracted.isEmpty()) {
                            playerIn.addItemStackToInventory(plate.realInventory.getHandler().extractItem(i, extracted.getCount(), false));
                            plate.markDirty();
                            ClientRunnable.run(new ClientRunnable() {

                                @Override
                                @SideOnly(Side.CLIENT)
                                public void runIfClient() {
                                    if (plate.renderHandler != null)
                                        ((TileCraftingPlateRenderer) plate.renderHandler).clearAll();
                                }
                            });
                            break;
                        }
                    }
                }
            }
            return true;
        }
    } else {
        if (playerIn.isCreative() && playerIn.isSneaking()) {
            tickStructure(worldIn, playerIn, pos);
        } else {
            TileCraftingPlate plate = getTE(worldIn, pos);
            plate.revealStructure = !plate.revealStructure;
            plate.markDirty();
        }
    }
    return heldItem.isEmpty();
}
Also used : PacketExplode(com.teamwizardry.wizardry.common.network.PacketExplode) SpellBuilder(com.teamwizardry.wizardry.api.spell.SpellBuilder) IInfusable(com.teamwizardry.wizardry.api.item.IInfusable) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) ClientRunnable(com.teamwizardry.librarianlib.features.utilities.client.ClientRunnable) Vec3d(net.minecraft.util.math.Vec3d) NBTTagList(net.minecraft.nbt.NBTTagList) NetworkRegistry(net.minecraftforge.fml.common.network.NetworkRegistry) TileCraftingPlateRenderer(com.teamwizardry.wizardry.client.render.block.TileCraftingPlateRenderer) ItemStack(net.minecraft.item.ItemStack) TileCraftingPlate(com.teamwizardry.wizardry.common.tile.TileCraftingPlate)

Example 15 with ClientRunnable

use of com.teamwizardry.librarianlib.features.utilities.client.ClientRunnable in project Wizardry by TeamWizardry.

the class EntityCorruptionArea method onUpdate.

public void onUpdate() {
    super.onUpdate();
    float radius = this.getRadius();
    if (duration < 0)
        setDead();
    duration--;
    ClientRunnable.run(new ClientRunnable() {

        @Override
        @SideOnly(Side.CLIENT)
        public void runIfClient() {
            ParticleBuilder glitter = new ParticleBuilder(RandUtil.nextInt(30, 50));
            glitter.setRender(new ResourceLocation(Wizardry.MODID, Constants.MISC.SPARKLE_BLURRED));
            glitter.enableMotionCalculation();
            glitter.setCollision(true);
            glitter.setCanBounce(true);
            glitter.setAcceleration(new Vec3d(0, -0.035, 0));
            glitter.setColor(new Color(255, 0, 206));
            glitter.setAlphaFunction(new InterpFadeInOut(0.5f, 0f));
            ParticleSpawner.spawn(glitter, world, new StaticInterp<>(getPositionVector()), 1, 1, (i, build) -> {
                double theta = 2.0f * (float) Math.PI * RandUtil.nextFloat();
                double r = getRadius() * RandUtil.nextFloat();
                double x = r * MathHelper.cos((float) theta);
                double z = r * MathHelper.sin((float) theta);
                build.setPositionOffset(new Vec3d(x, 0, z));
                build.addMotion(new Vec3d(0, RandUtil.nextDouble(0.01, 0.15), 0));
            });
        }
    });
    radius += radiusPerTick;
    setRadius(radius);
    Iterator<Entry<Entity, Integer>> iter = this.reapplicationDelayMap.entrySet().iterator();
    while (iter.hasNext()) {
        Entry<Entity, Integer> entry = iter.next();
        int timeLeft = entry.getValue();
        if (timeLeft > 0)
            entry.setValue(timeLeft - 1);
        else
            iter.remove();
    }
    List<EntityLivingBase> entityList = world.getEntitiesWithinAABB(EntityLivingBase.class, this.getEntityBoundingBox());
    for (EntityLivingBase entity : entityList) {
        if (entity instanceof EntityZachriel)
            continue;
        if (this.reapplicationDelayMap.containsKey(entity))
            continue;
        double xDiff = entity.posX - this.posX;
        double zDiff = entity.posY - this.posY;
        if (xDiff * xDiff + zDiff * zDiff <= radius * radius)
            affectEntity(entity);
    }
}
Also used : EntityDataManager(net.minecraft.network.datasync.EntityDataManager) InterpFadeInOut(com.teamwizardry.librarianlib.features.particle.functions.InterpFadeInOut) StaticInterp(com.teamwizardry.librarianlib.features.math.interpolate.StaticInterp) HashMap(java.util.HashMap) ParticleSpawner(com.teamwizardry.librarianlib.features.particle.ParticleSpawner) ParticleBuilder(com.teamwizardry.librarianlib.features.particle.ParticleBuilder) PotionEffect(net.minecraft.potion.PotionEffect) Vec3d(net.minecraft.util.math.Vec3d) Side(net.minecraftforge.fml.relauncher.Side) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Save(com.teamwizardry.librarianlib.features.saving.Save) EnumPushReaction(net.minecraft.block.material.EnumPushReaction) Entity(net.minecraft.entity.Entity) Iterator(java.util.Iterator) ClientRunnable(com.teamwizardry.librarianlib.features.utilities.client.ClientRunnable) World(net.minecraft.world.World) Wizardry(com.teamwizardry.wizardry.Wizardry) ModPotions(com.teamwizardry.wizardry.init.ModPotions) BlockPos(net.minecraft.util.math.BlockPos) DataParameter(net.minecraft.network.datasync.DataParameter) java.awt(java.awt) List(java.util.List) DataSerializers(net.minecraft.network.datasync.DataSerializers) EntityLivingBase(net.minecraft.entity.EntityLivingBase) MathHelper(net.minecraft.util.math.MathHelper) ResourceLocation(net.minecraft.util.ResourceLocation) Entry(java.util.Map.Entry) EntityMod(com.teamwizardry.librarianlib.features.base.entity.EntityMod) RandUtil(com.teamwizardry.wizardry.api.util.RandUtil) Constants(com.teamwizardry.wizardry.api.Constants) Entity(net.minecraft.entity.Entity) StaticInterp(com.teamwizardry.librarianlib.features.math.interpolate.StaticInterp) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) ClientRunnable(com.teamwizardry.librarianlib.features.utilities.client.ClientRunnable) InterpFadeInOut(com.teamwizardry.librarianlib.features.particle.functions.InterpFadeInOut) ParticleBuilder(com.teamwizardry.librarianlib.features.particle.ParticleBuilder) Vec3d(net.minecraft.util.math.Vec3d) Entry(java.util.Map.Entry) ResourceLocation(net.minecraft.util.ResourceLocation) EntityLivingBase(net.minecraft.entity.EntityLivingBase)

Aggregations

ClientRunnable (com.teamwizardry.librarianlib.features.utilities.client.ClientRunnable)20 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)17 Vec3d (net.minecraft.util.math.Vec3d)15 ParticleBuilder (com.teamwizardry.librarianlib.features.particle.ParticleBuilder)11 InterpFadeInOut (com.teamwizardry.librarianlib.features.particle.functions.InterpFadeInOut)11 ResourceLocation (net.minecraft.util.ResourceLocation)11 StaticInterp (com.teamwizardry.librarianlib.features.math.interpolate.StaticInterp)8 ParticleSpawner (com.teamwizardry.librarianlib.features.particle.ParticleSpawner)8 Wizardry (com.teamwizardry.wizardry.Wizardry)8 Constants (com.teamwizardry.wizardry.api.Constants)8 RandUtil (com.teamwizardry.wizardry.api.util.RandUtil)8 java.awt (java.awt)8 EntityLivingBase (net.minecraft.entity.EntityLivingBase)8 World (net.minecraft.world.World)8 Side (net.minecraftforge.fml.relauncher.Side)8 MathHelper (net.minecraft.util.math.MathHelper)7 Entity (net.minecraft.entity.Entity)6 InterpScale (com.teamwizardry.wizardry.api.util.interp.InterpScale)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 LibParticles (com.teamwizardry.wizardry.client.fx.LibParticles)4