Search in sources :

Example 61 with ForgeDirection

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

the class SideConfigDisplay method updateSelection.

private void updateSelection(Vector3d start, Vector3d end) {
    start.add(origin);
    end.add(origin);
    List<MovingObjectPosition> hits = new ArrayList<>();
    LogisticsBlockGenericPipe.ignoreSideRayTrace = true;
    for (DoubleCoordinates bc : configurables) {
        Block block = world.getBlock(bc.getXInt(), bc.getYInt(), bc.getZInt());
        if (block != null) {
            if (block instanceof LogisticsBlockGenericPipe) {
                cachedLPBlockTrace = LogisticsPipes.LogisticsPipeBlock.doRayTrace(world, bc.getXInt(), bc.getYInt(), bc.getZInt(), Vec3.createVectorHelper(start.x, start.y, start.z), Vec3.createVectorHelper(end.x, end.y, end.z));
            } else {
                cachedLPBlockTrace = null;
            }
            MovingObjectPosition hit = block.collisionRayTrace(world, bc.getXInt(), bc.getYInt(), bc.getZInt(), Vec3.createVectorHelper(start.x, start.y, start.z), Vec3.createVectorHelper(end.x, end.y, end.z));
            if (hit != null) {
                hits.add(hit);
            }
        }
    }
    LogisticsBlockGenericPipe.ignoreSideRayTrace = false;
    selection = null;
    MovingObjectPosition hit = getClosestHit(Vec3.createVectorHelper(start.x, start.y, start.z), hits);
    if (hit != null) {
        TileEntity te = world.getTileEntity(hit.blockX, hit.blockY, hit.blockZ);
        if (te != null) {
            ForgeDirection face = ForgeDirection.getOrientation(hit.sideHit);
            selection = new SelectedFace(te, face, hit);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) LogisticsBlockGenericPipe(logisticspipes.pipes.basic.LogisticsBlockGenericPipe) ArrayList(java.util.ArrayList) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Block(net.minecraft.block.Block) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 62 with ForgeDirection

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

the class PipeFluidTransportLogistics method computeFluidUpdate.

/**
	 * Computes the PacketFluidUpdate packet for transmission to a client
	 * 
	 * @param initPacket
	 *            everything is sent, no delta stuff ( first packet )
	 * @param persistChange
	 *            The render cache change is persisted
	 * @return PacketFluidUpdate liquid update packet
	 */
private ModernPacket computeFluidUpdate(boolean initPacket, boolean persistChange) {
    boolean changed = false;
    if (initClient > 0) {
        initClient--;
        if (initClient == 1) {
            changed = true;
        }
    }
    FluidStack[] renderCache = this.renderCache.clone();
    for (ForgeDirection dir : PipeFluidTransportLogistics.orientations) {
        FluidStack current;
        if (dir != ForgeDirection.UNKNOWN) {
            current = sideTanks[dir.ordinal()].getFluid();
        } else {
            current = internalTank.getFluid();
        }
        FluidStack prev = renderCache[dir.ordinal()];
        if (prev == null && current == null) {
            continue;
        }
        if (prev == null && current != null) {
            changed = true;
            renderCache[dir.ordinal()] = current.copy();
            continue;
        }
        if (prev != null && current == null) {
            changed = true;
            renderCache[dir.ordinal()] = null;
            continue;
        }
        if (prev.getFluidID() != current.getFluidID() || initPacket) {
            changed = true;
            renderCache[dir.ordinal()] = new FluidStack(current.getFluid(), renderCache[dir.ordinal()].amount);
        }
        if (prev.amount != current.amount || initPacket) {
            changed = true;
            renderCache[dir.ordinal()].amount = current.amount;
        }
    }
    if (persistChange) {
        this.renderCache = renderCache;
    }
    if (changed || initPacket) {
        return PacketHandler.getPacket(PipeFluidUpdate.class).setRenderCache(renderCache).setPosX(container.xCoord).setPosY(container.yCoord).setPosZ(container.zCoord).setChunkDataPacket(initPacket);
    }
    return null;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) PipeFluidUpdate(logisticspipes.network.packets.pipe.PipeFluidUpdate)

Example 63 with ForgeDirection

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

the class PipeFluidTransportLogistics method writeToNBT.

@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
    super.writeToNBT(nbttagcompound);
    for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
        NBTTagCompound subTag = new NBTTagCompound();
        sideTanks[direction.ordinal()].writeToNBT(subTag);
        nbttagcompound.setTag("tank[" + direction.ordinal() + "]", subTag);
    }
    NBTTagCompound subTag = new NBTTagCompound();
    internalTank.writeToNBT(subTag);
    nbttagcompound.setTag("tank[middle]", subTag);
}
Also used : ForgeDirection(net.minecraftforge.common.util.ForgeDirection) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 64 with ForgeDirection

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

the class PipeTransportLogistics method resolveUnroutedDestination.

public ForgeDirection resolveUnroutedDestination(LPTravelingItemServer data) {
    List<ForgeDirection> dirs = new ArrayList<>(Arrays.asList(ForgeDirection.VALID_DIRECTIONS));
    dirs.remove(data.input.getOpposite());
    Iterator<ForgeDirection> iter = dirs.iterator();
    while (iter.hasNext()) {
        ForgeDirection dir = iter.next();
        DoubleCoordinates pos = CoordinateUtils.add(getPipe().getLPPosition(), dir);
        TileEntity tile = pos.getTileEntity(getWorld());
        if (!SimpleServiceLocator.pipeInformationManager.isItemPipe(tile)) {
            iter.remove();
        } else if (!canPipeConnect(tile, dir)) {
            iter.remove();
        } else if (tile instanceof LogisticsTileGenericPipe && !((LogisticsTileGenericPipe) tile).canConnect(container, dir.getOpposite(), false)) {
            iter.remove();
        }
    }
    if (dirs.isEmpty()) {
        return ForgeDirection.UNKNOWN;
    }
    int num = new Random().nextInt(dirs.size());
    return dirs.get(num);
}
Also used : LogisticsPowerJunctionTileEntity(logisticspipes.blocks.powertile.LogisticsPowerJunctionTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) Random(java.util.Random) ArrayList(java.util.ArrayList) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 65 with ForgeDirection

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

the class TEControl method handleBlockUpdate.

public static void handleBlockUpdate(final World world, final LPWorldInfo info, int x, int y, int z) {
    if (info.getWorldTick() < 5) {
        return;
    }
    final DoubleCoordinates pos = new DoubleCoordinates(x, y, z);
    if (info.getUpdateQueued().contains(pos)) {
        return;
    }
    if (!pos.blockExists(world)) {
        return;
    }
    final TileEntity tile = pos.getTileEntity(world);
    if (SimpleServiceLocator.enderIOProxy.isBundledPipe(tile)) {
        QueuedTasks.queueTask(() -> {
            for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
                DoubleCoordinates newPos = CoordinateUtils.sum(pos, dir);
                if (!newPos.blockExists(world)) {
                    continue;
                }
                TileEntity nextTile = newPos.getTileEntity(world);
                if (nextTile instanceof LogisticsTileGenericPipe) {
                    ((LogisticsTileGenericPipe) nextTile).scheduleNeighborChange();
                }
            }
            return null;
        });
    }
    if (tile == null || ((ILPTEInformation) tile).getObject() == null) {
        return;
    }
    if (SimpleServiceLocator.pipeInformationManager.isItemPipe(tile) || SimpleServiceLocator.specialtileconnection.isType(tile)) {
        info.getUpdateQueued().add(pos);
        QueuedTasks.queueTask(() -> {
            for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
                DoubleCoordinates newPos = CoordinateUtils.sum(pos, dir);
                if (!newPos.blockExists(world)) {
                    continue;
                }
                TileEntity nextTile = newPos.getTileEntity(world);
                if (nextTile != null && ((ILPTEInformation) nextTile).getObject() != null) {
                    for (ITileEntityChangeListener listener : new ArrayList<>(((ILPTEInformation) nextTile).getObject().changeListeners)) {
                        listener.pipeModified(pos);
                    }
                }
            }
            for (ITileEntityChangeListener listener : new ArrayList<>(((ILPTEInformation) tile).getObject().changeListeners)) {
                listener.pipeModified(pos);
            }
            info.getUpdateQueued().remove(pos);
            return null;
        });
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ILPTEInformation(logisticspipes.asm.te.ILPTEInformation) ITileEntityChangeListener(logisticspipes.asm.te.ITileEntityChangeListener) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) ArrayList(java.util.ArrayList) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

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