Search in sources :

Example 36 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.

the class CoreRoutedPipe method writeToNBT.

@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
    super.writeToNBT(nbttagcompound);
    synchronized (routerIdLock) {
        if (routerId == null || routerId.isEmpty()) {
            if (router != null) {
                routerId = router.getId().toString();
            } else {
                routerId = UUID.randomUUID().toString();
            }
        }
    }
    nbttagcompound.setString("routerId", routerId);
    nbttagcompound.setLong("stat_lifetime_sent", stat_lifetime_sent);
    nbttagcompound.setLong("stat_lifetime_recieved", stat_lifetime_recieved);
    nbttagcompound.setLong("stat_lifetime_relayed", stat_lifetime_relayed);
    if (getLogisticsModule() != null) {
        getLogisticsModule().writeToNBT(nbttagcompound);
    }
    NBTTagCompound upgradeNBT = new NBTTagCompound();
    upgradeManager.writeToNBT(upgradeNBT);
    nbttagcompound.setTag("upgradeManager", upgradeNBT);
    NBTTagCompound powerNBT = new NBTTagCompound();
    powerHandler.writeToNBT(powerNBT);
    if (!powerNBT.hasNoTags()) {
        nbttagcompound.setTag("powerHandler", powerNBT);
    }
    NBTTagList sendqueue = new NBTTagList();
    for (Triplet<IRoutedItem, ForgeDirection, ItemSendMode> p : _sendQueue) {
        NBTTagCompound tagentry = new NBTTagCompound();
        NBTTagCompound tagentityitem = new NBTTagCompound();
        p.getValue1().writeToNBT(tagentityitem);
        tagentry.setTag("entityitem", tagentityitem);
        tagentry.setByte("from", (byte) (p.getValue2().ordinal()));
        tagentry.setByte("mode", (byte) (p.getValue3().ordinal()));
        sendqueue.appendTag(tagentry);
    }
    nbttagcompound.setTag("sendqueue", sendqueue);
    for (int i = 0; i < 6; i++) {
        if (signItem[i] != null) {
            nbttagcompound.setBoolean("PipeSign_" + i, true);
            int signType = -1;
            List<Class<? extends IPipeSign>> typeClasses = ItemPipeSignCreator.signTypes;
            for (int j = 0; j < typeClasses.size(); j++) {
                if (typeClasses.get(j) == signItem[i].getClass()) {
                    signType = j;
                    break;
                }
            }
            nbttagcompound.setInteger("PipeSign_" + i + "_type", signType);
            NBTTagCompound tag = new NBTTagCompound();
            signItem[i].writeToNBT(tag);
            nbttagcompound.setTag("PipeSign_" + i + "_tags", tag);
        } else {
            nbttagcompound.setBoolean("PipeSign_" + i, false);
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) IPipeSign(logisticspipes.pipes.signs.IPipeSign) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 37 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.

the class CoreUnroutedPipe method getDistanceTo.

public double getDistanceTo(int destinationint, ForgeDirection ignore, ItemIdentifier ident, boolean isActive, double travled, double max, List<DoubleCoordinates> visited) {
    double lowest = Integer.MAX_VALUE;
    for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
        if (ignore == dir) {
            continue;
        }
        IPipeInformationProvider information = SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(container.getNextConnectedTile(dir));
        if (information != null) {
            DoubleCoordinates pos = new DoubleCoordinates(information);
            if (visited.contains(pos)) {
                continue;
            }
            visited.add(pos);
            lowest = information.getDistanceTo(destinationint, dir.getOpposite(), ident, isActive, travled, Math.min(max, lowest), visited);
            visited.remove(pos);
        }
    }
    return lowest;
}
Also used : IPipeInformationProvider(logisticspipes.routing.pathfinder.IPipeInformationProvider) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 38 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.

the class CoreUnroutedPipe method getOpenOrientation.

/**
	 * If this pipe is open on one side, return it.
	 */
public ForgeDirection getOpenOrientation() {
    int connectionsNum = 0;
    ForgeDirection targetOrientation = ForgeDirection.UNKNOWN;
    for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
        if (container.isPipeConnected(o)) {
            connectionsNum++;
            if (connectionsNum == 1) {
                targetOrientation = o;
            }
        }
    }
    if (connectionsNum > 1 || connectionsNum == 0) {
        return ForgeDirection.UNKNOWN;
    }
    return targetOrientation.getOpposite();
}
Also used : ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 39 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.

the class LogisticsBlockGenericPipe method doRayTrace.

private RaytraceResult doRayTrace(LogisticsTileGenericPipe tileG, CoreUnroutedPipe pipe, Vec3 origin, Vec3 direction) {
    if (tileG == null) {
        return null;
    }
    if (!LogisticsBlockGenericPipe.isValid(pipe)) {
        return null;
    }
    /**
		 * pipe hits along x, y, and z axis, gate (all 6 sides) [and
		 * wires+facades]
		 */
    MovingObjectPosition[] hits = new MovingObjectPosition[31];
    AxisAlignedBB[] boxes = new AxisAlignedBB[31];
    ForgeDirection[] sideHit = new ForgeDirection[31];
    Arrays.fill(sideHit, ForgeDirection.UNKNOWN);
    // pipe
    for (ForgeDirection side : LogisticsBlockGenericPipe.DIR_VALUES) {
        if (side == ForgeDirection.UNKNOWN || tileG.isPipeConnected(side)) {
            if (side != ForgeDirection.UNKNOWN && ignoreSideRayTrace)
                continue;
            AxisAlignedBB bb = getPipeBoundingBox(side);
            setBlockBounds(bb);
            boxes[side.ordinal()] = bb;
            hits[side.ordinal()] = super.collisionRayTrace(tileG.getWorldObj(), tileG.xCoord, tileG.yCoord, tileG.zCoord, origin, direction);
            sideHit[side.ordinal()] = side;
        }
    }
    for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
        if (tileG.getPipePluggable(side) != null) {
            if (side != ForgeDirection.UNKNOWN && ignoreSideRayTrace)
                continue;
            AxisAlignedBB bb = tileG.getPipePluggable(side).getBoundingBox(side);
            setBlockBounds(bb);
            boxes[7 + side.ordinal()] = bb;
            hits[7 + side.ordinal()] = super.collisionRayTrace(tileG.getWorldObj(), tileG.xCoord, tileG.yCoord, tileG.zCoord, origin, direction);
            sideHit[7 + side.ordinal()] = side;
        }
    }
    // TODO: check wires
    // get closest hit
    double minLengthSquared = Double.POSITIVE_INFINITY;
    int minIndex = -1;
    for (int i = 0; i < hits.length; i++) {
        MovingObjectPosition hit = hits[i];
        if (hit == null) {
            continue;
        }
        double lengthSquared = hit.hitVec.squareDistanceTo(origin);
        if (lengthSquared < minLengthSquared) {
            minLengthSquared = lengthSquared;
            minIndex = i;
        }
    }
    // reset bounds
    setBlockBounds(0, 0, 0, 1, 1, 1);
    if (minIndex == -1) {
        return null;
    } else {
        Part hitPart;
        if (minIndex < 7) {
            hitPart = Part.Pipe;
        } else {
            hitPart = Part.Pluggable;
        }
        return new RaytraceResult(hitPart, hits[minIndex], boxes[minIndex], sideHit[minIndex]);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 40 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.

the class PipeItemsSatelliteLogistics method updateInv.

private void updateInv(boolean force) {
    itemList.clear();
    for (ForgeDirection ori : ForgeDirection.VALID_DIRECTIONS) {
        if (!this.container.isPipeConnected(ori))
            continue;
        IInventory inv = getInventory(ori);
        if (inv != null) {
            for (int i = 0; i < inv.getSizeInventory(); i++) {
                if (inv.getStackInSlot(i) != null) {
                    addToList(ItemIdentifierStack.getFromStack(inv.getStackInSlot(i)));
                }
            }
        }
    }
    if (!itemList.equals(oldList) || force) {
        oldList.clear();
        oldList.addAll(itemList);
        MainProxy.sendToPlayerList(PacketHandler.getPacket(ChestContent.class).setIdentList(itemList).setPosX(getX()).setPosY(getY()).setPosZ(getZ()), localModeWatchers);
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ChestContent(logisticspipes.network.packets.hud.ChestContent)

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