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);
}
}
}
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;
}
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);
}
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);
}
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;
});
}
}
Aggregations