Search in sources :

Example 1 with Area

use of powercrystals.core.position.Area in project MineFactoryReloaded by powercrystals.

the class TileEntitySludgeBoiler method activateMachine.

@Override
protected boolean activateMachine() {
    if (_tank.getLiquid() != null && _tank.getLiquid().amount > 10) {
        _tank.drain(10, true);
        setWorkDone(getWorkDone() + 1);
        _tick++;
        if (getWorkDone() >= getWorkMax()) {
            ItemStack s = ((WeightedRandomItemStack) WeightedRandom.getRandomItem(_rand, MFRRegistry.getSludgeDrops())).getStack();
            doDrop(s);
            setWorkDone(0);
        }
        if (_tick >= 23) {
            Area a = new Area(new BlockPosition(this), 3, 3, 3);
            List<?> entities = worldObj.getEntitiesWithinAABB(EntityLiving.class, a.toAxisAlignedBB());
            for (Object o : entities) {
                if (o instanceof EntityPlayer) {
                    ((EntityPlayer) o).addPotionEffect(new PotionEffect(Potion.hunger.id, 20 * 20, 0));
                }
                if (o instanceof EntityPlayer) {
                    ((EntityPlayer) o).addPotionEffect(new PotionEffect(Potion.poison.id, 6 * 20, 0));
                }
            }
            _tick = 0;
        }
        return true;
    }
    return false;
}
Also used : Area(powercrystals.core.position.Area) PotionEffect(net.minecraft.potion.PotionEffect) BlockPosition(powercrystals.core.position.BlockPosition) WeightedRandomItemStack(powercrystals.core.random.WeightedRandomItemStack) EntityPlayer(net.minecraft.entity.player.EntityPlayer) WeightedRandomItemStack(powercrystals.core.random.WeightedRandomItemStack) ItemStack(net.minecraft.item.ItemStack)

Example 2 with Area

use of powercrystals.core.position.Area in project MineFactoryReloaded by powercrystals.

the class TileEntityFisher method activateMachine.

@Override
public boolean activateMachine() {
    if (_isJammed || worldObj.getWorldTime() % 137 == 0) {
        Area fishingHole = _ham.getHarvestArea();
        for (BlockPosition bp : fishingHole.getPositionsBottomFirst()) {
            if (worldObj.getBlockId(bp.x, bp.y, bp.z) != Block.waterStill.blockID) {
                _isJammed = true;
                setIdleTicks(getIdleTicksMax());
                return false;
            }
        }
    }
    _isJammed = false;
    setWorkDone(getWorkDone() + 1);
    if (getWorkDone() > getWorkMax()) {
        doDrop(new ItemStack(Item.fishRaw));
        setWorkDone(0);
    }
    return true;
}
Also used : Area(powercrystals.core.position.Area) BlockPosition(powercrystals.core.position.BlockPosition) ItemStack(net.minecraft.item.ItemStack)

Example 3 with Area

use of powercrystals.core.position.Area in project MineFactoryReloaded by powercrystals.

the class TileEntityFruitPicker method getNextTreeSegment.

private BlockPosition getNextTreeSegment(int x, int y, int z, boolean treeFlipped) {
    int blockId;
    if (_lastTree == null || _lastTree.x != x || _lastTree.y != y || _lastTree.z != z) {
        int yTreeAreaLowerBound = (treeFlipped ? y - MFRConfig.fruitTreeSearchMaxVertical.getInt() : y);
        int yTreeAreaUpperBound = (treeFlipped ? y : y + MFRConfig.fruitTreeSearchMaxVertical.getInt());
        Area a = new Area(x - MFRConfig.fruitTreeSearchMaxHorizontal.getInt(), x + MFRConfig.fruitTreeSearchMaxHorizontal.getInt(), yTreeAreaLowerBound, yTreeAreaUpperBound, z - MFRConfig.fruitTreeSearchMaxHorizontal.getInt(), z + MFRConfig.fruitTreeSearchMaxHorizontal.getInt());
        _treeManager = new TreeHarvestManager(a, treeFlipped ? TreeHarvestMode.HarvestInverted : TreeHarvestMode.Harvest);
        _lastTree = new BlockPosition(x, y, z);
    } else if (_treeManager.getIsDone()) {
        _treeManager.reset();
    }
    while (true) {
        if (_treeManager.getIsDone()) {
            return null;
        }
        BlockPosition bp = _treeManager.getNextBlock();
        blockId = worldObj.getBlockId(bp.x, bp.y, bp.z);
        if (MFRRegistry.getFruits().containsKey(new Integer(blockId)) && MFRRegistry.getFruits().get(new Integer(blockId)).canBePicked(worldObj, bp.x, bp.y, bp.z)) {
            return bp;
        }
        _treeManager.moveNext();
    }
}
Also used : Area(powercrystals.core.position.Area) BlockPosition(powercrystals.core.position.BlockPosition) TreeHarvestManager(powercrystals.minefactoryreloaded.core.TreeHarvestManager)

Example 4 with Area

use of powercrystals.core.position.Area in project MineFactoryReloaded by powercrystals.

the class TileEntitySewer method updateEntity.

@Override
public void updateEntity() {
    super.updateEntity();
    if (worldObj.isRemote) {
        return;
    }
    _tick++;
    if (_nextSewerCheckTick <= worldObj.getTotalWorldTime()) {
        Area a = new Area(BlockPosition.fromFactoryTile(this), _areaManager.getRadius(), 0, 0);
        _jammed = false;
        for (BlockPosition bp : a.getPositionsBottomFirst()) {
            if (worldObj.getBlockId(bp.x, bp.y, bp.z) == MineFactoryReloadedCore.machineBlocks.get(0).blockID && worldObj.getBlockMetadata(bp.x, bp.y, bp.z) == Machine.Sewer.getMeta() && !(bp.x == xCoord && bp.y == yCoord && bp.z == zCoord)) {
                _jammed = true;
                break;
            }
        }
        _nextSewerCheckTick = worldObj.getTotalWorldTime() + 800 + worldObj.rand.nextInt(800);
    }
    if (_tick >= 31 && !_jammed) {
        _tick = 0;
        List<?> entities = worldObj.getEntitiesWithinAABB(EntityLiving.class, _areaManager.getHarvestArea().toAxisAlignedBB());
        double massFound = 0;
        for (Object o : entities) {
            if (o instanceof EntityAnimal || o instanceof EntityVillager) {
                massFound += Math.pow(((EntityLiving) o).boundingBox.getAverageEdgeLength(), 2);
            } else if (o instanceof EntityPlayer && ((EntityPlayer) o).isSneaking()) {
                massFound += Math.pow(((EntityLiving) o).boundingBox.getAverageEdgeLength(), 2);
            }
        }
        if (massFound > 0) {
            _tank.fill(LiquidDictionary.getLiquid("sewage", (int) (25 * massFound)), true);
        } else // TODO: add a second tank to the sewer for essence
        if (_tank.getLiquid() == null || _tank.getLiquid().isLiquidEqual(LiquidDictionary.getLiquid("mobEssence", 1))) {
            int maxAmount = Math.max(_tank.getCapacity() - (_tank.getLiquid() != null ? _tank.getLiquid().amount : 0), 0);
            if (maxAmount < 0) {
                return;
            }
            entities = worldObj.getEntitiesWithinAABB(EntityXPOrb.class, _areaManager.getHarvestArea().toAxisAlignedBB());
            for (Object o : entities) {
                Entity e = (Entity) o;
                if (e != null & e instanceof EntityXPOrb && !e.isDead) {
                    EntityXPOrb orb = (EntityXPOrb) o;
                    int found = Math.min(orb.xpValue, maxAmount);
                    orb.xpValue -= found;
                    if (orb.xpValue <= 0) {
                        orb.setDead();
                        found = Math.max(found, 0);
                    }
                    if (found > 0) {
                        found = (int) (found * 66.66666667f);
                        maxAmount -= found;
                        _tank.fill(LiquidDictionary.getLiquid("mobEssence", found), true);
                        if (maxAmount <= 0) {
                            break;
                        }
                    }
                }
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) Area(powercrystals.core.position.Area) EntityLiving(net.minecraft.entity.EntityLiving) BlockPosition(powercrystals.core.position.BlockPosition) EntityVillager(net.minecraft.entity.passive.EntityVillager) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityAnimal(net.minecraft.entity.passive.EntityAnimal) EntityXPOrb(net.minecraft.entity.item.EntityXPOrb)

Example 5 with Area

use of powercrystals.core.position.Area in project MineFactoryReloaded by powercrystals.

the class TileEntityHarvester method getNextTreeSegment.

private BlockPosition getNextTreeSegment(int x, int y, int z, boolean treeFlipped) {
    int blockId;
    if (_lastTree == null || _lastTree.x != x || _lastTree.y != y || _lastTree.z != z) {
        int yTreeAreaLowerBound = (treeFlipped ? y - MFRConfig.treeSearchMaxVertical.getInt() : y);
        int yTreeAreaUpperBound = (treeFlipped ? y : y + MFRConfig.treeSearchMaxVertical.getInt());
        Area a = new Area(x - MFRConfig.treeSearchMaxHorizontal.getInt(), x + MFRConfig.treeSearchMaxHorizontal.getInt(), yTreeAreaLowerBound, yTreeAreaUpperBound, z - MFRConfig.treeSearchMaxHorizontal.getInt(), z + MFRConfig.treeSearchMaxHorizontal.getInt());
        _treeManager = new TreeHarvestManager(a, treeFlipped ? TreeHarvestMode.HarvestInverted : TreeHarvestMode.Harvest);
        _lastTree = new BlockPosition(x, y, z);
    } else if (_treeManager.getIsDone()) {
        _treeManager.reset();
    }
    while (true) {
        if (_treeManager.getIsDone()) {
            return null;
        }
        BlockPosition bp = _treeManager.getNextBlock();
        blockId = worldObj.getBlockId(bp.x, bp.y, bp.z);
        if (MFRRegistry.getHarvestables().containsKey(new Integer(blockId)) && MFRRegistry.getHarvestables().get(new Integer(blockId)).canBeHarvested(worldObj, _settings, bp.x, bp.y, bp.z)) {
            if (_treeManager.getIsLeafPass() && MFRRegistry.getHarvestables().get(new Integer(blockId)).getHarvestType() == HarvestType.TreeLeaf) {
                return bp;
            } else if (!_treeManager.getIsLeafPass() && (MFRRegistry.getHarvestables().get(new Integer(blockId)).getHarvestType() == HarvestType.Tree || MFRRegistry.getHarvestables().get(new Integer(blockId)).getHarvestType() == HarvestType.TreeFlipped)) {
                return bp;
            } else if (!_treeManager.getIsLeafPass() && MFRRegistry.getHarvestables().get(new Integer(blockId)).getHarvestType() == HarvestType.TreeLeaf) {
                _treeManager.reset();
                continue;
            }
        }
        _treeManager.moveNext();
    }
}
Also used : Area(powercrystals.core.position.Area) BlockPosition(powercrystals.core.position.BlockPosition) TreeHarvestManager(powercrystals.minefactoryreloaded.core.TreeHarvestManager)

Aggregations

Area (powercrystals.core.position.Area)6 BlockPosition (powercrystals.core.position.BlockPosition)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ItemStack (net.minecraft.item.ItemStack)2 TreeHarvestManager (powercrystals.minefactoryreloaded.core.TreeHarvestManager)2 Entity (net.minecraft.entity.Entity)1 EntityLiving (net.minecraft.entity.EntityLiving)1 EntityXPOrb (net.minecraft.entity.item.EntityXPOrb)1 EntityAnimal (net.minecraft.entity.passive.EntityAnimal)1 EntityVillager (net.minecraft.entity.passive.EntityVillager)1 PotionEffect (net.minecraft.potion.PotionEffect)1 WeightedRandomItemStack (powercrystals.core.random.WeightedRandomItemStack)1