Search in sources :

Example 16 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project BluePower by Qmunity.

the class PneumaticTube method getTubeBoxes.

protected List<Vec3dCube> getTubeBoxes() {
    List<Vec3dCube> aabbs = getOcclusionBoxes();
    for (int i = 0; i < 6; i++) {
        ForgeDirection d = ForgeDirection.getOrientation(i);
        if (connections[i] || redstoneConnections[i] || getDeviceOnSide(d) != null) {
            Vec3dCube c = sideBB.clone().rotate(d, Vec3d.center);
            aabbs.add(c);
        }
    }
    return aabbs;
}
Also used : ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Vec3dCube(uk.co.qmunity.lib.vec.Vec3dCube)

Example 17 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project BluePower by Qmunity.

the class PneumaticTube method updateConnections.

private void updateConnections() {
    if (getWorld() != null && !getWorld().isRemote) {
        int connectionCount = 0;
        boolean clearedCache = false;
        clearCache();
        for (int i = 0; i < 6; i++) {
            boolean oldState = connections[i];
            ForgeDirection d = ForgeDirection.getOrientation(i);
            TileEntity neighbor = getTileCache(d);
            connections[i] = IOHelper.canInterfaceWith(neighbor, d.getOpposite(), this, canConnectToInventories());
            if (!connections[i])
                connections[i] = neighbor instanceof ITubeConnection && ((ITubeConnection) neighbor).isConnectedTo(d.getOpposite());
            if (connections[i]) {
                connections[i] = isConnected(d, null);
            }
            if (connections[i])
                connectionCount++;
            if (!clearedCache && oldState != connections[i]) {
                if (Config.enableTubeCaching)
                    getLogic().clearNodeCaches();
                clearedCache = true;
            }
        }
        isCrossOver = connectionCount != 2;
        sendUpdatePacket();
    }
    initialized = true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ITubeConnection(com.bluepowermod.api.tube.ITubeConnection) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 18 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project BluePower by Qmunity.

the class PneumaticTube method onUpdate.

/**
     * Event called whenever a nearby block updates
     */
@Override
public void onUpdate() {
    if (getParent() != null && getWorld() != null) {
        // Don't to anything if propagation-related stuff is going on
        if (RedstoneApi.getInstance().shouldWiresHandleUpdates()) {
            getRedstoneConnectionCache().recalculateConnections();
            ForgeDirection d = ForgeDirection.UNKNOWN;
            for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) if (getDeviceOnSide(dir) != null)
                d = dir;
            RedstoneApi.getInstance().getRedstonePropagator(this, d).propagate();
            sendUpdatePacket();
        }
        // Cache and connection refresh
        clearCache();
        updateConnections();
    }
}
Also used : ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 19 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project BluePower by Qmunity.

the class TubeLogic method clearNodeCaches.

public void clearNodeCaches() {
    List<PneumaticTube> clearedTubes = new ArrayList<PneumaticTube>();
    Stack<PneumaticTube> todoTubes = new Stack<PneumaticTube>();
    clearNodeCache();
    boolean firstRun = true;
    todoTubes.push(tube);
    while (!todoTubes.isEmpty()) {
        PneumaticTube tube = todoTubes.pop();
        if (tube.getParent() != null && tube.getWorld() != null) {
            for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                PneumaticTube neighbor = tube.getPartCache(d);
                if (neighbor != null) {
                    if (!clearedTubes.contains(neighbor)) {
                        neighbor.getLogic().clearNodeCache();
                        clearedTubes.add(neighbor);
                        if (firstRun || !neighbor.isCrossOver)
                            todoTubes.push(neighbor);
                    }
                }
            }
        }
        firstRun = false;
    }
}
Also used : IPneumaticTube(com.bluepowermod.api.tube.IPneumaticTube) ArrayList(java.util.ArrayList) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Stack(java.util.Stack) ItemStack(net.minecraft.item.ItemStack) MessageRedirectTubeStack(com.bluepowermod.network.message.MessageRedirectTubeStack)

Example 20 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project BluePower by Qmunity.

the class TubeLogic method retrieveStack.

public boolean retrieveStack(TileEntity target, ForgeDirection dirToRetrieveInto, ItemStack filter, TubeColor color) {
    if (tube.getWorld() == null)
        return false;
    TubeStack stack = new TubeStack(filter, null, color);
    stack.setTarget(target, dirToRetrieveInto);
    Pair<ForgeDirection, TileEntity> result = getHeadingForItem(stack, false);
    if (result == null)
        return false;
    int fuzzySetting = 0;
    if (target instanceof IFuzzyRetrieving) {
        fuzzySetting = ((IFuzzyRetrieving) target).getFuzzySetting();
    }
    ItemStack extractedItem = null;
    if (result.getValue() instanceof TileManager) {
        // Exception for managers, the result can only end up as a manager if the pulling inventory was
        // a manager.
        TileEntity managedInventory = ((TileManager) result.getValue()).getTileCache(((TileManager) result.getValue()).getFacingDirection());
        extractedItem = IOHelper.extract(managedInventory, result.getKey().getOpposite(), filter, false, false, fuzzySetting);
    } else if (filter != null) {
        extractedItem = IOHelper.extract(result.getValue(), result.getKey().getOpposite(), filter, !(target instanceof TileManager), false, fuzzySetting);
    } else {
        extractedItem = IOHelper.extract(result.getValue(), result.getKey().getOpposite(), false);
    }
    if (extractedItem == null)
        throw new IllegalArgumentException("This isn't possible!");
    stack = new TubeStack(extractedItem, result.getKey().getOpposite(), color);
    stack.setTarget(target, dirToRetrieveInto);
    PneumaticTube tube = MultipartCompatibility.getPart(this.tube.getWorld(), result.getValue().xCoord - result.getKey().offsetX, result.getValue().yCoord - result.getKey().offsetY, result.getValue().zCoord - result.getKey().offsetZ, PneumaticTube.class);
    if (tube == null)
        throw new IllegalArgumentException("wieeeeerd!");
    return tube.getLogic().injectStack(stack, result.getKey().getOpposite(), false);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPneumaticTube(com.bluepowermod.api.tube.IPneumaticTube) IFuzzyRetrieving(com.bluepowermod.tile.IFuzzyRetrieving) MessageRedirectTubeStack(com.bluepowermod.network.message.MessageRedirectTubeStack) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemStack(net.minecraft.item.ItemStack) TileManager(com.bluepowermod.tile.tier3.TileManager)

Aggregations

ForgeDirection (net.minecraftforge.common.util.ForgeDirection)242 TileEntity (net.minecraft.tileentity.TileEntity)80 ItemStack (net.minecraft.item.ItemStack)47 ArrayList (java.util.ArrayList)29 Block (net.minecraft.block.Block)28 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)24 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)21 IInventory (net.minecraft.inventory.IInventory)19 FluidStack (net.minecraftforge.fluids.FluidStack)18 SideOnly (cpw.mods.fml.relauncher.SideOnly)17 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)17 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)17 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)16 HashMap (java.util.HashMap)12 Pair (logisticspipes.utils.tuples.Pair)11 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)10 World (net.minecraft.world.World)10 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)9 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)9 List (java.util.List)8