Search in sources :

Example 1 with ItemFertilizerHandler

use of blusunrize.immersiveengineering.api.tool.BelljarHandler.ItemFertilizerHandler in project ImmersiveEngineering by BluSunrize.

the class TileEntityBelljar method update.

@Override
public void update() {
    ApiUtils.checkForNeedlessTicking(this);
    if (dummy != 0 || world.getRedstonePowerFromNeighbors(getPos()) > 0)
        return;
    ItemStack soil = inventory.get(SLOT_SOIL);
    ItemStack seed = inventory.get(SLOT_SEED);
    if (getWorld().isRemote) {
        if (energyStorage.getEnergyStored() > IEConfig.Machines.belljar_consumption && fertilizerAmount > 0 && renderActive) {
            IPlantHandler handler = getCurrentPlantHandler();
            if (handler != null && handler.isCorrectSoil(seed, soil) && fertilizerAmount > 0) {
                if (renderGrowth < 1) {
                    renderGrowth += belljar_growth_mod * handler.getGrowthStep(seed, soil, renderGrowth, this, fertilizerMod, true);
                    fertilizerAmount--;
                } else
                    renderGrowth = handler.resetGrowth(seed, soil, renderGrowth, this, true);
                if (Utils.RAND.nextInt(8) == 0) {
                    double partX = getPos().getX() + .5;
                    double partY = getPos().getY() + 2.6875;
                    double partZ = getPos().getZ() + .5;
                    ImmersiveEngineering.proxy.spawnRedstoneFX(getWorld(), partX, partY, partZ, .25, .25, .25, 1f, .55f, .1f, .1f);
                }
            }
        }
    } else {
        if (!seed.isEmpty()) {
            IPlantHandler handler = getCurrentPlantHandler();
            if (handler != null && handler.isCorrectSoil(seed, soil) && fertilizerAmount > 0 && energyStorage.extractEnergy(IEConfig.Machines.belljar_consumption, true) == IEConfig.Machines.belljar_consumption) {
                boolean consume = false;
                if (growth >= 1) {
                    ItemStack[] outputs = handler.getOutput(seed, soil, this);
                    int canFit = 0;
                    boolean[] emptySlotsUsed = new boolean[4];
                    for (ItemStack output : outputs) if (!output.isEmpty())
                        for (int j = 3; j < 7; j++) {
                            ItemStack existing = inventory.get(j);
                            if ((existing.isEmpty() && !emptySlotsUsed[j - 3]) || (ItemHandlerHelper.canItemStacksStack(existing, output) && existing.getCount() + output.getCount() <= existing.getMaxStackSize())) {
                                canFit++;
                                if (existing.isEmpty())
                                    emptySlotsUsed[j - 3] = true;
                                break;
                            }
                        }
                    if (canFit >= outputs.length) {
                        for (ItemStack output : outputs) for (int j = 3; j < 7; j++) {
                            ItemStack existing = inventory.get(j);
                            if (existing.isEmpty()) {
                                inventory.set(j, output.copy());
                                break;
                            } else if (ItemHandlerHelper.canItemStacksStack(existing, output) && existing.getCount() + output.getCount() <= existing.getMaxStackSize()) {
                                existing.grow(output.getCount());
                                break;
                            }
                        }
                        growth = handler.resetGrowth(seed, soil, growth, this, false);
                        consume = true;
                    }
                } else if (growth < 1) {
                    growth += belljar_growth_mod * handler.getGrowthStep(seed, soil, growth, this, fertilizerMod, false);
                    consume = true;
                    if (world.getTotalWorldTime() % 32 == ((getPos().getX() ^ getPos().getZ()) & 31))
                        sendSyncPacket(0);
                }
                if (consume) {
                    energyStorage.extractEnergy(IEConfig.Machines.belljar_consumption, false);
                    fertilizerAmount--;
                    if (!renderActive) {
                        renderActive = true;
                        sendSyncPacket(0);
                    }
                } else if (renderActive) {
                    renderActive = false;
                    sendSyncPacket(0);
                }
            } else
                growth = 0;
            if (fertilizerAmount <= 0 && tank.getFluidAmount() >= IEConfig.Machines.belljar_fluid) {
                FluidFertilizerHandler fluidFert = BelljarHandler.getFluidFertilizerHandler(tank.getFluid());
                if (fluidFert != null) {
                    fertilizerMod = fluidFert.getGrowthMultiplier(tank.getFluid(), seed, soil, this);
                    tank.drain(IEConfig.Machines.belljar_fluid, true);
                    ItemStack fertilizer = inventory.get(SLOT_FERTILIZER);
                    if (!fertilizer.isEmpty()) {
                        ItemFertilizerHandler itemFert = BelljarHandler.getItemFertilizerHandler(fertilizer);
                        if (itemFert != null)
                            fertilizerMod *= itemFert.getGrowthMultiplier(fertilizer, seed, soil, this);
                        fertilizer.shrink(1);
                        if (fertilizer.getCount() <= 0)
                            inventory.set(2, ItemStack.EMPTY);
                    }
                    fertilizerAmount = IEConfig.Machines.belljar_fertilizer;
                    sendSyncPacket(1);
                }
            }
        } else
            growth = 0;
        if (world.getTotalWorldTime() % 8 == 0) {
            BlockPos outputPos = getPos().up().offset(facing.getOpposite());
            TileEntity outputTile = Utils.getExistingTileEntity(world, outputPos);
            if (outputTile != null)
                for (int j = 3; j < 7; j++) {
                    ItemStack outStack = inventory.get(j);
                    if (!outStack.isEmpty()) {
                        int outCount = Math.min(outStack.getCount(), 16);
                        ItemStack stack = Utils.copyStackWithAmount(outStack, outCount);
                        stack = Utils.insertStackIntoInventory(outputTile, stack, facing);
                        if (!stack.isEmpty())
                            outCount -= stack.getCount();
                        outStack.shrink(outCount);
                        if (outStack.getCount() <= 0)
                            this.inventory.set(j, ItemStack.EMPTY);
                    }
                }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidFertilizerHandler(blusunrize.immersiveengineering.api.tool.BelljarHandler.FluidFertilizerHandler) ItemFertilizerHandler(blusunrize.immersiveengineering.api.tool.BelljarHandler.ItemFertilizerHandler) BlockPos(net.minecraft.util.math.BlockPos) IPlantHandler(blusunrize.immersiveengineering.api.tool.BelljarHandler.IPlantHandler) ItemStack(net.minecraft.item.ItemStack) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint)

Example 2 with ItemFertilizerHandler

use of blusunrize.immersiveengineering.api.tool.BelljarHandler.ItemFertilizerHandler in project ImmersiveEngineering by BluSunrize.

the class ThermalFoundationHelper method init.

@Override
public void init() {
    // TE Compat for smelter recipes. Not worth a separate module.
    OreDictionary.registerOre("crystalSlag", new ItemStack(IEContent.itemMaterial, 1, 7));
    ChemthrowerHandler.registerEffect("coal", new ChemthrowerEffect_Potion(null, 0, IEPotions.flammable, 100, 0));
    ChemthrowerHandler.registerFlammable("coal");
    ChemthrowerHandler.registerEffect("crude_oil", new ChemthrowerEffect_Potion(null, 0, new PotionEffect(IEPotions.flammable, 140, 0), new PotionEffect(MobEffects.BLINDNESS, 80, 1)));
    ChemthrowerHandler.registerFlammable("crude_oil");
    ChemthrowerHandler.registerEffect("refined_oil", new ChemthrowerEffect_Potion(null, 0, IEPotions.flammable, 100, 1));
    ChemthrowerHandler.registerFlammable("refined_oil");
    ChemthrowerHandler.registerEffect("resin", new ChemthrowerEffect_Potion(null, 0, IEPotions.sticky, 100, 1));
    ChemthrowerHandler.registerEffect("tree_oil", new ChemthrowerEffect_Potion(null, 0, IEPotions.flammable, 120, 0));
    ChemthrowerHandler.registerFlammable("tree_oil");
    ChemthrowerHandler.registerEffect("redstone", new ChemthrowerEffect_Potion(null, 0, IEPotions.conductive, 100, 1));
    ChemthrowerHandler.registerEffect("glowstone", new ChemthrowerEffect_Potion(null, 0, new PotionEffect(MobEffects.GLOWING, 120, 0), new PotionEffect(MobEffects.SPEED, 120, 0), new PotionEffect(MobEffects.JUMP_BOOST, 120, 0)));
    ChemthrowerHandler.registerEffect("ender", new ChemthrowerEffect_RandomTeleport(null, 0, 1));
    try {
        Class c_DamageHelper = Class.forName("cofh.lib.util.helpers.DamageHelper");
        DamageSource pyrotheum = (DamageSource) c_DamageHelper.getDeclaredField("pyrotheum").get(null);
        Field f_explodeCreepers = Class.forName("cofh.thermalfoundation.fluid.BlockFluidPyrotheum").getDeclaredField("effect");
        f_explodeCreepers.setAccessible(true);
        if ((boolean) f_explodeCreepers.get(null))
            ChemthrowerHandler.registerEffect("pyrotheum", new ChemthrowerEffect_Damage(pyrotheum, 3) {

                @Override
                public void applyToEntity(EntityLivingBase target, @Nullable EntityPlayer shooter, ItemStack thrower, Fluid fluid) {
                    super.applyToEntity(target, shooter, thrower, fluid);
                    if (target instanceof EntityCreeper) {
                        target.getEntityWorld().createExplosion(target, target.posX, target.posY, target.posZ, 6.0F, target.getEntityWorld().getGameRules().getBoolean("mobGriefing"));
                        target.setDead();
                    }
                }
            });
        else
            ChemthrowerHandler.registerEffect("pyrotheum", new ChemthrowerEffect_Damage(pyrotheum, 3));
        DamageSource cryotheum = (DamageSource) c_DamageHelper.getDeclaredField("cryotheum").get(null);
        ChemthrowerHandler.registerEffect("cryotheum", new ChemthrowerEffect_Potion(cryotheum, 2, MobEffects.SLOWNESS, 50, 3));
    } catch (Exception e) {
    }
    ChemthrowerHandler.registerEffect("aerotheum", new ChemthrowerEffect_Potion(null, 0, new PotionEffect(MobEffects.INVISIBILITY, 60, 0), new PotionEffect(MobEffects.WATER_BREATHING, 300, 0)));
    ChemthrowerHandler.registerEffect("petrotheum", new ChemthrowerEffect_Potion(null, 0, new PotionEffect(MobEffects.HASTE, 300, 2), new PotionEffect(MobEffects.NIGHT_VISION, 300, 0), new PotionEffect(MobEffects.RESISTANCE, 300, 1)) {

        @Override
        public void applyToBlock(World world, RayTraceResult mop, @Nullable EntityPlayer shooter, ItemStack thrower, Fluid fluid) {
            IBlockState state = world.getBlockState(mop.getBlockPos());
            if (state.getBlock() == Blocks.STONE || state.getBlock() == Blocks.COBBLESTONE || state.getBlock() == Blocks.STONEBRICK || state.getBlock() == Blocks.MOSSY_COBBLESTONE)
                world.setBlockState(mop.getBlockPos(), Blocks.GRAVEL.getDefaultState());
        }
    });
    ChemthrowerHandler.registerEffect("mana", new ChemthrowerEffect_RandomTeleport(null, 0, .01f));
    final Item itemPhyto = Item.REGISTRY.getObject(new ResourceLocation("thermalfoundation:fertilizer"));
    if (itemPhyto != null)
        BelljarHandler.registerItemFertilizer(new ItemFertilizerHandler() {

            @Override
            public boolean isValid(@Nullable ItemStack fertilizer) {
                return !fertilizer.isEmpty() && fertilizer.getItem() == itemPhyto;
            }

            @Override
            public float getGrowthMultiplier(ItemStack fertilizer, ItemStack seed, ItemStack soil, TileEntity tile) {
                return BelljarHandler.solidFertilizerModifier * (1.5f + (.25f * fertilizer.getMetadata()));
            }
        });
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) DamageSource(net.minecraft.util.DamageSource) ChemthrowerEffect_Damage(blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_Damage) PotionEffect(net.minecraft.potion.PotionEffect) Fluid(net.minecraftforge.fluids.Fluid) RayTraceResult(net.minecraft.util.math.RayTraceResult) World(net.minecraft.world.World) ChemthrowerEffect_Potion(blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_Potion) ChemthrowerEffect_RandomTeleport(blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_RandomTeleport) TileEntity(net.minecraft.tileentity.TileEntity) Field(java.lang.reflect.Field) Item(net.minecraft.item.Item) EntityCreeper(net.minecraft.entity.monster.EntityCreeper) ItemFertilizerHandler(blusunrize.immersiveengineering.api.tool.BelljarHandler.ItemFertilizerHandler) ResourceLocation(net.minecraft.util.ResourceLocation) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Aggregations

ItemFertilizerHandler (blusunrize.immersiveengineering.api.tool.BelljarHandler.ItemFertilizerHandler)2 ItemStack (net.minecraft.item.ItemStack)2 TileEntity (net.minecraft.tileentity.TileEntity)2 FluidFertilizerHandler (blusunrize.immersiveengineering.api.tool.BelljarHandler.FluidFertilizerHandler)1 IPlantHandler (blusunrize.immersiveengineering.api.tool.BelljarHandler.IPlantHandler)1 ChemthrowerEffect_Damage (blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_Damage)1 ChemthrowerEffect_Potion (blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_Potion)1 ChemthrowerEffect_RandomTeleport (blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_RandomTeleport)1 Field (java.lang.reflect.Field)1 Nullable (javax.annotation.Nullable)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityCreeper (net.minecraft.entity.monster.EntityCreeper)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 Item (net.minecraft.item.Item)1 PotionEffect (net.minecraft.potion.PotionEffect)1 DamageSource (net.minecraft.util.DamageSource)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 BlockPos (net.minecraft.util.math.BlockPos)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1