use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.
the class TEControl method validate.
public static void validate(final TileEntity tile) {
final World world = tile.getWorldObj();
if (world == null) {
return;
}
if (!MainProxy.isServer(world)) {
return;
}
if (tile.getClass().getName().startsWith("net.minecraft.tileentity")) {
return;
}
final DoubleCoordinates pos = new DoubleCoordinates(tile);
if (pos.getXInt() == 0 && pos.getYInt() <= 0 && pos.getZInt() == 0) {
return;
}
if (SimpleServiceLocator.pipeInformationManager.isPipe(tile, false, ConnectionPipeType.UNDEFINED) || SimpleServiceLocator.specialtileconnection.isType(tile)) {
((ILPTEInformation) tile).setObject(new LPTileEntityObject());
((ILPTEInformation) tile).getObject().initialised = LPTickHandler.getWorldInfo(world).getWorldTick();
if (((ILPTEInformation) tile).getObject().initialised < 5) {
return;
}
QueuedTasks.queueTask(() -> {
if (!SimpleServiceLocator.pipeInformationManager.isPipe(tile, true, ConnectionPipeType.UNDEFINED)) {
return null;
}
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) {
if (SimpleServiceLocator.pipeInformationManager.isItemPipe(nextTile)) {
SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(nextTile).refreshTileCacheOnSide(dir.getOpposite());
}
if (SimpleServiceLocator.pipeInformationManager.isItemPipe(tile)) {
SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(tile).refreshTileCacheOnSide(dir);
SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(tile).refreshTileCacheOnSide(dir.getOpposite());
}
for (ITileEntityChangeListener listener : new ArrayList<>(((ILPTEInformation) nextTile).getObject().changeListeners)) {
listener.pipeAdded(pos, dir.getOpposite());
}
}
}
return null;
});
}
}
use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.
the class TEControl method invalidate.
public static void invalidate(final TileEntity tile) {
final World world = tile.getWorldObj();
if (world == null) {
return;
}
if (!MainProxy.isServer(world)) {
return;
}
if (tile instanceof LogisticsTileGenericPipe && ((LogisticsTileGenericPipe) tile).isRoutingPipe()) {
return;
}
if (((ILPTEInformation) tile).getObject() != null) {
QueuedTasks.queueTask(() -> {
DoubleCoordinates pos = new DoubleCoordinates(tile);
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) {
if (SimpleServiceLocator.pipeInformationManager.isItemPipe(nextTile)) {
SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(nextTile).refreshTileCacheOnSide(dir.getOpposite());
}
}
}
for (ITileEntityChangeListener listener : new ArrayList<>(((ILPTEInformation) tile).getObject().changeListeners)) {
listener.pipeRemoved(pos);
}
return null;
});
}
}
use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.
the class PipeTransportLogistics method resolveRoutedDestination.
public ForgeDirection resolveRoutedDestination(LPTravelingItemServer data) {
ForgeDirection blocked = null;
if (data.getDestinationUUID() == null) {
ItemIdentifierStack stack = data.getItemIdentifierStack();
ItemRoutingInformation result = getRoutedPipe().getQueuedForItemStack(stack);
if (result != null) {
data.setInformation(result);
data.getInfo().setItem(stack);
blocked = data.input.getOpposite();
}
}
if (data.getItemIdentifierStack() != null) {
getRoutedPipe().relayedItem(data.getItemIdentifierStack().getStackSize());
}
if (data.getDestination() >= 0 && !getRoutedPipe().getRouter().hasRoute(data.getDestination(), data.getTransportMode() == TransportMode.Active, data.getItemIdentifierStack().getItem()) && data.getBufferCounter() < MAX_DESTINATION_UNREACHABLE_BUFFER) {
_itemBuffer.add(new Triplet<>(data.getItemIdentifierStack(), new Pair<>(_bufferTimeOut, data.getBufferCounter()), data));
return null;
}
ForgeDirection value;
if (getRoutedPipe().stillNeedReplace() || getRoutedPipe().initialInit()) {
data.setDoNotBuffer(false);
value = ForgeDirection.UNKNOWN;
} else {
value = getRoutedPipe().getRouteLayer().getOrientationForItem(data, blocked);
}
if (value == null && MainProxy.isClient(getWorld())) {
return null;
} else if (value == null) {
LogisticsPipes.log.fatal("THIS IS NOT SUPPOSED TO HAPPEN!");
return ForgeDirection.UNKNOWN;
}
if (value == ForgeDirection.UNKNOWN && !data.getDoNotBuffer() && data.getBufferCounter() < 5) {
_itemBuffer.add(new Triplet<>(data.getItemIdentifierStack(), new Pair<>(_bufferTimeOut, data.getBufferCounter()), null));
return null;
}
if (value != ForgeDirection.UNKNOWN && !getRoutedPipe().getRouter().isRoutedExit(value)) {
if (!isItemExitable(data.getItemIdentifierStack())) {
return null;
}
}
data.resetDelay();
return value;
}
use of net.minecraftforge.common.util.ForgeDirection in project SimplyJetpacks by Tonius.
the class ItemJetpackFueller method onUsingTick.
@Override
public void onUsingTick(ItemStack itemStack, EntityPlayer player, int count) {
MovingObjectPosition blockPos = BlockHelper.getCurrentMovingObjectPosition(player, true);
if (blockPos == null || blockPos.sideHit < 0) {
player.setItemInUse(null, 1);
} else {
player.setItemInUse(itemStack, this.getMaxItemUseDuration(itemStack));
if (player.worldObj.isRemote) {
return;
}
ItemStack chestplate = player.getCurrentArmor(2);
if (chestplate == null || !(chestplate.getItem() instanceof ItemPack)) {
return;
}
ItemPack packItem = (ItemPack) chestplate.getItem();
PackBase pack = packItem.getPack(chestplate);
if (pack == null) {
return;
}
FuelType fuelType = pack.fuelType;
ForgeDirection pullSide = ForgeDirection.values()[blockPos.sideHit];
player.worldObj.getBlock(blockPos.blockX, blockPos.blockY, blockPos.blockZ);
TileEntity tile = player.worldObj.getTileEntity(blockPos.blockX, blockPos.blockY, blockPos.blockZ);
int toPull = Math.min(pack.fuelPerTickIn, packItem.getMaxFuelStored(chestplate) - packItem.getFuelStored(chestplate));
int pulled = 0;
if (fuelType == FuelType.ENERGY && tile instanceof IEnergyProvider) {
IEnergyProvider energyTile = (IEnergyProvider) tile;
pulled = energyTile.extractEnergy(pullSide, toPull, false);
} else if (fuelType == FuelType.FLUID) {
if (tile instanceof IFluidHandler) {
IFluidHandler fluidTile = (IFluidHandler) tile;
FluidStack fluid = fluidTile.drain(pullSide, toPull, false);
if (fluid == null || !fluid.getFluid().getName().equals(pack.fuelFluid)) {
return;
}
fluid = fluidTile.drain(pullSide, toPull, true);
pulled = fluid.amount;
}
}
if (pulled > 0) {
packItem.addFuel(chestplate, pulled, false);
}
}
}
use of net.minecraftforge.common.util.ForgeDirection in project PneumaticCraft by MineMaarten.
the class PathFinderDrone method findPathOptions.
/**
* populates pathOptions with available points and returns the number of options found (args: unused1, currentPoint,
* unused2, targetPoint, maxDistance)
*/
private int findPathOptions(Entity par1Entity, PathPoint par2PathPoint, PathPoint par3PathPoint, PathPoint par4PathPoint, float par5) {
int i = 0;
byte b0 = 0;
if (getVerticalOffset(par1Entity, par2PathPoint.xCoord, par2PathPoint.yCoord + 1, par2PathPoint.zCoord, par3PathPoint) == 1) {
b0 = 1;
}
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
PathPoint safePoint = getSafePoint(par1Entity, par2PathPoint.xCoord + dir.offsetX, par2PathPoint.yCoord + dir.offsetY, par2PathPoint.zCoord + dir.offsetZ, par3PathPoint, b0);
if (safePoint != null && !safePoint.isFirst && safePoint.distanceTo(par4PathPoint) < par5) {
pathOptions[i++] = safePoint;
}
}
return i;
}
Aggregations