Search in sources :

Example 1 with PacketExplode

use of com.teamwizardry.wizardry.common.network.PacketExplode in project Wizardry by TeamWizardry.

the class FluidRecipeLoader method buildFluidCrafter.

private FluidCrafter buildFluidCrafter(String identifier, ItemStack outputItem, Ingredient input, List<Ingredient> extraInputs, Fluid fluid, int duration, int required, boolean consume, boolean explode, boolean bubbling, boolean harp) {
    Ingredient outputIngredient = Ingredient.fromStacks(outputItem);
    List<Ingredient> inputs = Lists.newArrayList(extraInputs);
    return new FluidCrafter((world, pos, items) -> {
        if (allLiquidInPool(world, pos, required, fluid).size() < required)
            return false;
        List<ItemStack> list = items.stream().map(entity -> entity.getItem().copy()).collect(Collectors.toList());
        List<Ingredient> inputList = new ArrayList<>(inputs);
        inputList.add(input);
        for (Ingredient itemIn : inputList) {
            boolean foundMatch = false;
            List<ItemStack> toRemove = new LinkedList<>();
            for (ItemStack item : list) {
                if (itemIn.apply(item) && !outputIngredient.apply(item)) {
                    foundMatch = true;
                    break;
                }
            }
            if (!foundMatch)
                return false;
            list.removeAll(toRemove);
            toRemove.clear();
        }
        return true;
    }, (world, pos, items, currentDuration) -> {
        EntityItem entityItem = items.stream().filter(entity -> input.apply(entity.getItem())).findFirst().orElse(null);
        if (entityItem != null) {
            if (world.isRemote)
                LibParticles.CRAFTING_ALTAR_IDLE(world, entityItem.getPositionVector());
            if (bubbling && currentDuration % 10 == 0)
                world.playSound(null, entityItem.posX, entityItem.posY, entityItem.posZ, ModSounds.BUBBLING, SoundCategory.BLOCKS, 0.7F, (RandUtil.nextFloat() * 0.4F) + 0.8F);
        }
    }, (world, pos, items, currentDuration) -> {
        if (consume) {
            Block block = fluid.getBlock();
            if (block != null) {
                IBlockState defaultState = block.getDefaultState();
                Iterator<IProperty<?>> properties = defaultState.getPropertyKeys().iterator();
                IBlockState drainState = defaultState;
                if (properties.hasNext())
                    drainState = drainState.cycleProperty(properties.next());
                for (BlockPos position : allLiquidInPool(world, pos, required, fluid)) world.setBlockState(position, drainState);
            }
        }
        List<Ingredient> inputList = new ArrayList<>(inputs);
        inputList.add(input);
        for (Ingredient itemIn : inputList) {
            for (EntityItem entity : items) {
                if (itemIn.apply(entity.getItem()) && !outputIngredient.apply(entity.getItem())) {
                    entity.getItem().shrink(1);
                    if (entity.getItem().isEmpty())
                        entity.setDead();
                }
            }
        }
        EntityItem output = new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, outputItem.copy());
        output.motionX = 0;
        output.motionY = 0;
        output.motionZ = 0;
        output.forceSpawn = true;
        world.spawnEntity(output);
        if (explode) {
            PacketHandler.NETWORK.sendToAllAround(new PacketExplode(output.getPositionVector(), Color.CYAN, Color.BLUE, 0.9, 2, 500, 100, 50, true), new NetworkRegistry.TargetPoint(world.provider.getDimension(), output.posX, output.posY, output.posZ, 256));
            PosUtils.boom(world, output.getPositionVector(), output, 3, false);
        }
        if (harp)
            world.playSound(null, output.posX, output.posY, output.posZ, ModSounds.HARP1, SoundCategory.BLOCKS, 0.3F, 1.0F);
    }, identifier, duration).setInputs(input, inputs).setOutput(outputItem).setDoesConsume(consume).setRequired(required).setFluid(fluid);
}
Also used : JsonObject(com.google.gson.JsonObject) Ingredient(net.minecraft.item.crafting.Ingredient) java.util(java.util) JsonContext(net.minecraftforge.common.crafting.JsonContext) ModFluids(com.teamwizardry.wizardry.common.block.fluid.ModFluids) PacketExplode(com.teamwizardry.wizardry.common.network.PacketExplode) FluidRegistry(net.minecraftforge.fluids.FluidRegistry) Multimap(com.google.common.collect.Multimap) JsonParser(com.google.gson.JsonParser) PosUtils(com.teamwizardry.wizardry.api.util.PosUtils) JsonElement(com.google.gson.JsonElement) ItemStack(net.minecraft.item.ItemStack) Lists(com.google.common.collect.Lists) IProperty(net.minecraft.block.properties.IProperty) Block(net.minecraft.block.Block) Vec3d(net.minecraft.util.math.Vec3d) ModSounds(com.teamwizardry.wizardry.init.ModSounds) Fluid(net.minecraftforge.fluids.Fluid) SoundCategory(net.minecraft.util.SoundCategory) EntityItem(net.minecraft.entity.item.EntityItem) PacketHandler(com.teamwizardry.librarianlib.features.network.PacketHandler) World(net.minecraft.world.World) Wizardry(com.teamwizardry.wizardry.Wizardry) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) java.awt(java.awt) IBlockState(net.minecraft.block.state.IBlockState) JsonArray(com.google.gson.JsonArray) List(java.util.List) NetworkRegistry(net.minecraftforge.fml.common.network.NetworkRegistry) LibParticles(com.teamwizardry.wizardry.client.fx.LibParticles) ForgeRegistries(net.minecraftforge.fml.common.registry.ForgeRegistries) ResourceLocation(net.minecraft.util.ResourceLocation) RandUtil(com.teamwizardry.wizardry.api.util.RandUtil) FluidStack(net.minecraftforge.fluids.FluidStack) FileReader(java.io.FileReader) CraftingHelper(net.minecraftforge.common.crafting.CraftingHelper) IBlockState(net.minecraft.block.state.IBlockState) PacketExplode(com.teamwizardry.wizardry.common.network.PacketExplode) Ingredient(net.minecraft.item.crafting.Ingredient) Block(net.minecraft.block.Block) List(java.util.List) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 2 with PacketExplode

use of com.teamwizardry.wizardry.common.network.PacketExplode in project Wizardry by TeamWizardry.

the class FluidRecipeLoader method buildFluidCrafter.

private FluidCrafter buildFluidCrafter(String identifier, IBlockState outputBlock, Ingredient input, List<Ingredient> extraInputs, Fluid fluid, int duration, int required, boolean consume, boolean explode, boolean bubbling, boolean harp) {
    List<Ingredient> inputs = Lists.newArrayList(extraInputs);
    FluidCrafter builder = new FluidCrafter((world, pos, items) -> {
        if (allLiquidInPool(world, pos, required, fluid).size() < required)
            return false;
        List<ItemStack> list = items.stream().map(entity -> entity.getItem().copy()).collect(Collectors.toList());
        List<Ingredient> inputList = new ArrayList<>(inputs);
        inputList.add(input);
        for (Ingredient itemIn : inputList) {
            boolean foundMatch = false;
            List<ItemStack> toRemove = new LinkedList<>();
            for (ItemStack item : list) {
                if (itemIn.apply(item)) {
                    foundMatch = true;
                    break;
                }
            }
            if (!foundMatch)
                return false;
            list.removeAll(toRemove);
            toRemove.clear();
        }
        return true;
    }, (world, pos, items, currentDuration) -> {
        EntityItem entityItem = items.stream().filter(entity -> input.apply(entity.getItem())).findFirst().orElse(null);
        if (entityItem != null) {
            if (world.isRemote)
                LibParticles.CRAFTING_ALTAR_IDLE(world, entityItem.getPositionVector());
            if (bubbling && currentDuration % 10 == 0)
                world.playSound(null, entityItem.posX, entityItem.posY, entityItem.posZ, ModSounds.BUBBLING, SoundCategory.BLOCKS, 0.7F, (RandUtil.nextFloat() * 0.4F) + 0.8F);
        }
    }, (world, pos, items, currentDuration) -> {
        if (consume) {
            Block block = fluid.getBlock();
            if (block != null) {
                IBlockState defaultState = block.getDefaultState();
                Iterator<IProperty<?>> properties = defaultState.getPropertyKeys().iterator();
                IBlockState drainState = defaultState;
                if (properties.hasNext())
                    drainState = drainState.cycleProperty(properties.next());
                for (BlockPos position : allLiquidInPool(world, pos, required, fluid)) world.setBlockState(position, drainState);
            }
        }
        List<Ingredient> inputList = new ArrayList<>(inputs);
        inputList.add(input);
        for (Ingredient itemIn : inputList) {
            for (EntityItem entity : items) {
                if (itemIn.apply(entity.getItem())) {
                    entity.getItem().shrink(1);
                    if (entity.getItem().isEmpty())
                        entity.setDead();
                }
            }
        }
        world.setBlockState(pos, outputBlock);
        Vec3d output = new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
        if (explode) {
            PacketHandler.NETWORK.sendToAllAround(new PacketExplode(output, Color.CYAN, Color.BLUE, 0.9, 2, 500, 100, 50, true), new NetworkRegistry.TargetPoint(world.provider.getDimension(), output.x, output.y, output.z, 256));
            PosUtils.boom(world, output, null, 3, false);
        }
        if (harp)
            world.playSound(null, output.x, output.y, output.z, ModSounds.HARP1, SoundCategory.BLOCKS, 0.3F, 1.0F);
    }, identifier, duration).setInputs(input, inputs).setIsBlock(true).setDoesConsume(true).setRequired(required).setFluid(fluid);
    Fluid fluidOutput = FluidRegistry.lookupFluidForBlock(outputBlock.getBlock());
    if (fluidOutput != null)
        builder.setOutput(new FluidStack(fluidOutput, 1000));
    else
        builder.setOutput(new ItemStack(outputBlock.getBlock(), 1, outputBlock.getBlock().damageDropped(outputBlock)));
    return builder;
}
Also used : JsonObject(com.google.gson.JsonObject) Ingredient(net.minecraft.item.crafting.Ingredient) java.util(java.util) JsonContext(net.minecraftforge.common.crafting.JsonContext) ModFluids(com.teamwizardry.wizardry.common.block.fluid.ModFluids) PacketExplode(com.teamwizardry.wizardry.common.network.PacketExplode) FluidRegistry(net.minecraftforge.fluids.FluidRegistry) Multimap(com.google.common.collect.Multimap) JsonParser(com.google.gson.JsonParser) PosUtils(com.teamwizardry.wizardry.api.util.PosUtils) JsonElement(com.google.gson.JsonElement) ItemStack(net.minecraft.item.ItemStack) Lists(com.google.common.collect.Lists) IProperty(net.minecraft.block.properties.IProperty) Block(net.minecraft.block.Block) Vec3d(net.minecraft.util.math.Vec3d) ModSounds(com.teamwizardry.wizardry.init.ModSounds) Fluid(net.minecraftforge.fluids.Fluid) SoundCategory(net.minecraft.util.SoundCategory) EntityItem(net.minecraft.entity.item.EntityItem) PacketHandler(com.teamwizardry.librarianlib.features.network.PacketHandler) World(net.minecraft.world.World) Wizardry(com.teamwizardry.wizardry.Wizardry) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) java.awt(java.awt) IBlockState(net.minecraft.block.state.IBlockState) JsonArray(com.google.gson.JsonArray) List(java.util.List) NetworkRegistry(net.minecraftforge.fml.common.network.NetworkRegistry) LibParticles(com.teamwizardry.wizardry.client.fx.LibParticles) ForgeRegistries(net.minecraftforge.fml.common.registry.ForgeRegistries) ResourceLocation(net.minecraft.util.ResourceLocation) RandUtil(com.teamwizardry.wizardry.api.util.RandUtil) FluidStack(net.minecraftforge.fluids.FluidStack) FileReader(java.io.FileReader) CraftingHelper(net.minecraftforge.common.crafting.CraftingHelper) IBlockState(net.minecraft.block.state.IBlockState) PacketExplode(com.teamwizardry.wizardry.common.network.PacketExplode) FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) Vec3d(net.minecraft.util.math.Vec3d) Ingredient(net.minecraft.item.crafting.Ingredient) Block(net.minecraft.block.Block) List(java.util.List) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 3 with PacketExplode

use of com.teamwizardry.wizardry.common.network.PacketExplode 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 4 with PacketExplode

use of com.teamwizardry.wizardry.common.network.PacketExplode 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 5 with PacketExplode

use of com.teamwizardry.wizardry.common.network.PacketExplode 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)

Aggregations

PacketExplode (com.teamwizardry.wizardry.common.network.PacketExplode)6 NetworkRegistry (net.minecraftforge.fml.common.network.NetworkRegistry)6 Vec3d (net.minecraft.util.math.Vec3d)5 ItemStack (net.minecraft.item.ItemStack)4 EntityItem (net.minecraft.entity.item.EntityItem)3 BlockPos (net.minecraft.util.math.BlockPos)3 Lists (com.google.common.collect.Lists)2 Multimap (com.google.common.collect.Multimap)2 Sets (com.google.common.collect.Sets)2 JsonArray (com.google.gson.JsonArray)2 JsonElement (com.google.gson.JsonElement)2 JsonObject (com.google.gson.JsonObject)2 JsonParser (com.google.gson.JsonParser)2 PacketHandler (com.teamwizardry.librarianlib.features.network.PacketHandler)2 Wizardry (com.teamwizardry.wizardry.Wizardry)2 CapManager (com.teamwizardry.wizardry.api.capability.CapManager)2 PosUtils (com.teamwizardry.wizardry.api.util.PosUtils)2 RandUtil (com.teamwizardry.wizardry.api.util.RandUtil)2 LibParticles (com.teamwizardry.wizardry.client.fx.LibParticles)2 ModFluids (com.teamwizardry.wizardry.common.block.fluid.ModFluids)2