Search in sources :

Example 16 with BlockPosition

use of powercrystals.core.position.BlockPosition 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 17 with BlockPosition

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

the class RedstoneNetwork method updatePowerLevels.

public void updatePowerLevels(int subnet) {
    int lastPower = _powerLevelOutput[subnet];
    _powerLevelOutput[subnet] = 0;
    _powerProviders[subnet] = null;
    log("Network with ID %d:%d recalculating power levels for %d single nodes and %d omni nodes", _id, subnet, _singleNodes.get(subnet).size(), _omniNodes.size());
    for (BlockPosition node : _singleNodes.get(subnet)) {
        if (!isNodeLoaded(node)) {
            continue;
        }
        int power = getSingleNodePowerLevel(node);
        if (Math.abs(power) > Math.abs(_powerLevelOutput[subnet])) {
            _powerLevelOutput[subnet] = power;
            _powerProviders[subnet] = node;
        }
    }
    for (BlockPosition node : _omniNodes) {
        if (!isNodeLoaded(node)) {
            continue;
        }
        int power = getOmniNodePowerLevel(node, subnet);
        if (Math.abs(power) > Math.abs(_powerLevelOutput[subnet])) {
            _powerLevelOutput[subnet] = power;
            _powerProviders[subnet] = node;
        }
    }
    RedstoneNetwork.log("Network with ID %d:%d recalculated power levels as: output: %d with powering node %s", _id, subnet, _powerLevelOutput[subnet], _powerProviders[subnet]);
    if (_powerLevelOutput[subnet] != lastPower) {
        notifyNodes(subnet);
    }
}
Also used : BlockPosition(powercrystals.core.position.BlockPosition)

Example 18 with BlockPosition

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

the class TileEntityRedNetCable method setNetwork.

public void setNetwork(RedstoneNetwork network) {
    _network = network;
    _network.addCable(new BlockPosition(this));
}
Also used : BlockPosition(powercrystals.core.position.BlockPosition)

Example 19 with BlockPosition

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

the class TileEntityRedNetCable method updateNetwork.

private void updateNetwork() {
    if (worldObj.isRemote) {
        return;
    }
    BlockPosition ourbp = new BlockPosition(this);
    RedstoneNetwork.log("Cable at %s updating network", ourbp.toString());
    if (_network == null) {
        for (BlockPosition bp : ourbp.getAdjacent(true)) {
            TileEntity te = bp.getTileEntity(worldObj);
            if (te instanceof TileEntityRedNetCable) {
                TileEntityRedNetCable cable = ((TileEntityRedNetCable) te);
                if (cable.getNetwork() != null && !cable.getNetwork().isInvalid()) {
                    _network = cable.getNetwork();
                    break;
                }
            }
        }
    }
    if (_network == null) {
        RedstoneNetwork.log("Initializing new network at %s", ourbp.toString());
        setNetwork(new RedstoneNetwork(worldObj));
    }
    for (BlockPosition bp : ourbp.getAdjacent(true)) {
        TileEntity te = bp.getTileEntity(worldObj);
        if (te instanceof TileEntityRedNetCable) {
            TileEntityRedNetCable cable = ((TileEntityRedNetCable) te);
            if (cable.getNetwork() == null) {
                cable.setNetwork(_network);
            } else if (cable.getNetwork() != _network && cable.getNetwork() != null && !cable.getNetwork().isInvalid()) {
                _network.mergeNetwork(cable.getNetwork());
            }
        } else {
            int subnet = getSideColor(bp.orientation);
            RedNetConnectionType connectionType = getConnectionState(bp.orientation);
            if (!worldObj.isAirBlock(bp.x, bp.y, bp.z)) {
                if (connectionType == RedNetConnectionType.CableSingle) {
                    _network.addOrUpdateNode(bp, subnet, false);
                } else if (connectionType == RedNetConnectionType.PlateSingle) {
                    _network.addOrUpdateNode(bp, subnet, true);
                } else if (connectionType == RedNetConnectionType.CableAll || connectionType == RedNetConnectionType.PlateAll) {
                    _network.addOrUpdateNode(bp);
                } else {
                    _network.removeNode(bp);
                }
            } else {
                _network.removeNode(bp);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) RedNetConnectionType(powercrystals.minefactoryreloaded.api.rednet.RedNetConnectionType) BlockPosition(powercrystals.core.position.BlockPosition)

Example 20 with BlockPosition

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

the class TileEntityRedNetCable method getConnectionState.

public RedNetConnectionType getConnectionState(ForgeDirection side) {
    BlockPosition bp = new BlockPosition(this);
    bp.orientation = side;
    bp.moveForwards(1);
    int blockId = worldObj.getBlockId(bp.x, bp.y, bp.z);
    Block b = Block.blocksList[blockId];
    if (// block doesn't exist (air) - never connect
    b == null) {
        return RedNetConnectionType.None;
    } else if (// cables - always connect
    blockId == MineFactoryReloadedCore.rednetCableBlock.blockID) {
        return RedNetConnectionType.CableAll;
    } else if (// cable-only, and not a cable - don't connct
    _mode == 2) {
        return RedNetConnectionType.None;
    } else if (b instanceof IRedNetNoConnection) {
        return RedNetConnectionType.None;
    } else if (// API node - let them figure it out
    b instanceof IConnectableRedNet) {
        return ((IConnectableRedNet) b).getConnectionType(worldObj, bp.x, bp.y, bp.z, side.getOpposite());
    } else if (_mode == 0 && (blockId <= _maxVanillaBlockId && !_connectionWhitelist.contains(blockId)) || _connectionBlackList.contains(blockId) || b.isAirBlock(worldObj, bp.x, bp.y, bp.z)) // standard connection logic, then figure out if we shouldn't connect
    // mode 1 will skip this
    {
        return RedNetConnectionType.None;
    } else if (// mode 1 forces plate mode for weak power
    _mode == 0 && b.isBlockSolidOnSide(worldObj, bp.x, bp.y, bp.z, side.getOpposite())) {
        return RedNetConnectionType.CableSingle;
    } else {
        return RedNetConnectionType.PlateSingle;
    }
}
Also used : BlockPosition(powercrystals.core.position.BlockPosition) Block(net.minecraft.block.Block) IConnectableRedNet(powercrystals.minefactoryreloaded.api.rednet.IConnectableRedNet) IRedNetNoConnection(powercrystals.minefactoryreloaded.api.rednet.IRedNetNoConnection)

Aggregations

BlockPosition (powercrystals.core.position.BlockPosition)37 ItemStack (net.minecraft.item.ItemStack)8 TileEntity (net.minecraft.tileentity.TileEntity)8 Area (powercrystals.core.position.Area)6 Block (net.minecraft.block.Block)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ForgeDirection (net.minecraftforge.common.ForgeDirection)2 IFactoryHarvestable (powercrystals.minefactoryreloaded.api.IFactoryHarvestable)2 IConnectableRedNet (powercrystals.minefactoryreloaded.api.rednet.IConnectableRedNet)2 TreeHarvestManager (powercrystals.minefactoryreloaded.core.TreeHarvestManager)2 IconOverlay (powercrystals.minefactoryreloaded.render.IconOverlay)2 TileEntityRedNetCable (powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetCable)2 IPowerProvider (buildcraft.api.power.IPowerProvider)1 IPowerReceptor (buildcraft.api.power.IPowerReceptor)1 ArrayList (java.util.ArrayList)1 Entity (net.minecraft.entity.Entity)1 EntityAgeable (net.minecraft.entity.EntityAgeable)1 EntityLiving (net.minecraft.entity.EntityLiving)1 EntityMinecartContainer (net.minecraft.entity.item.EntityMinecartContainer)1