use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.
the class ModuleExtractor method tick.
@Override
public void tick() {
if (++currentTick < ticksToAction()) {
return;
}
currentTick = 0;
//Extract Item
IInventory realInventory = _service.getRealInventory();
if (realInventory == null) {
return;
}
ForgeDirection extractOrientation = _sneakyDirection;
if (extractOrientation == ForgeDirection.UNKNOWN) {
extractOrientation = _service.inventoryOrientation().getOpposite();
}
IInventoryUtil targetUtil = _service.getSneakyInventory(extractOrientation, true);
for (int i = 0; i < targetUtil.getSizeInventory(); i++) {
ItemStack slot = targetUtil.getStackInSlot(i);
if (slot == null) {
continue;
}
ItemIdentifier slotitem = ItemIdentifier.get(slot);
List<Integer> jamList = new LinkedList<>();
Pair<Integer, SinkReply> reply = _service.hasDestination(slotitem, true, jamList);
if (reply == null) {
continue;
}
int itemsleft = itemsToExtract();
while (reply != null) {
int count = Math.min(itemsleft, slot.stackSize);
count = Math.min(count, slotitem.getMaxStackSize());
if (reply.getValue2().maxNumberOfItems > 0) {
count = Math.min(count, reply.getValue2().maxNumberOfItems);
}
while (!_service.useEnergy(neededEnergy() * count) && count > 0) {
_service.spawnParticle(Particles.OrangeParticle, 2);
count--;
}
if (count <= 0) {
break;
}
ItemStack stackToSend = targetUtil.decrStackSize(i, count);
if (stackToSend == null || stackToSend.stackSize == 0) {
break;
}
count = stackToSend.stackSize;
_service.sendStack(stackToSend, reply, itemSendMode());
itemsleft -= count;
if (itemsleft <= 0) {
break;
}
slot = targetUtil.getStackInSlot(i);
if (slot == null) {
break;
}
jamList.add(reply.getValue1());
reply = _service.hasDestination(ItemIdentifier.get(slot), true, jamList);
}
break;
}
}
use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.
the class RequestRoutingLasersPacket method processPacket.
@Override
public void processPacket(EntityPlayer player) {
LogisticsTileGenericPipe tile = this.getPipe(player.worldObj);
if (tile == null) {
return;
}
if (tile.pipe instanceof CoreRoutedPipe) {
IRouter router = ((CoreRoutedPipe) tile.pipe).getRouter();
//this is here to allow players to manually trigger a network-wide LSA update
router.forceLsaUpdate();
List<List<ExitRoute>> exits = router.getRouteTable();
HashMap<ForgeDirection, ArrayList<ExitRoute>> routers = new HashMap<>();
for (List<ExitRoute> exit : exits) {
if (exit == null) {
continue;
}
for (ExitRoute e : exit) {
if (!routers.containsKey(e.exitOrientation)) {
routers.put(e.exitOrientation, new ArrayList<>());
}
if (!routers.get(e.exitOrientation).contains(e)) {
routers.get(e.exitOrientation).add(e);
}
}
}
ArrayList<LaserData> lasers = new ArrayList<>();
firstPipe = true;
for (final ForgeDirection dir : routers.keySet()) {
if (dir == ForgeDirection.UNKNOWN) {
continue;
}
handleRouteInDirection(tile, dir, routers.get(dir), lasers, EnumSet.allOf(PipeRoutingConnectionType.class), new Log() {
@Override
void log(String log) {
if (LPConstants.DEBUG) {
System.out.println(dir.name() + ": " + log);
}
}
});
}
lasers = compressLasers(lasers);
MainProxy.sendPacketToPlayer(PacketHandler.getPacket(RoutingLaserPacket.class).setLasers(lasers), player);
}
}
use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.
the class PipeItemsProviderLogistics method sendStack.
private int sendStack(ItemIdentifierStack stack, int maxCount, int destination, IAdditionalTargetInformation info) {
ItemIdentifier item = stack.getItem();
WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(container);
//@formatter:off
Iterator<Pair<IInventoryUtil, ForgeDirection>> iterator = worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).filter(adjacent -> !SimpleServiceLocator.pipeInformationManager.isItemPipe(adjacent.tileEntity)).map(adjacent -> new Pair<>(getAdaptedInventoryUtil(adjacent), adjacent.direction)).iterator();
while (iterator.hasNext()) {
Pair<IInventoryUtil, ForgeDirection> next = iterator.next();
int available = next.getValue1().itemCount(item);
if (available == 0) {
continue;
}
int wanted = Math.min(available, stack.getStackSize());
wanted = Math.min(wanted, maxCount);
wanted = Math.min(wanted, item.getMaxStackSize());
IRouter dRtr = SimpleServiceLocator.routerManager.getRouterUnsafe(destination, false);
if (dRtr == null) {
_orderManager.sendFailed();
return 0;
}
SinkReply reply = LogisticsManager.canSink(dRtr, null, true, stack.getItem(), null, true, false);
boolean defersend = false;
if (reply != null) {
// some pipes are not aware of the space in the adjacent inventory, so they return null
if (reply.maxNumberOfItems < wanted) {
wanted = reply.maxNumberOfItems;
if (wanted <= 0) {
_orderManager.deferSend();
return 0;
}
defersend = true;
}
}
if (!canUseEnergy(wanted * neededEnergy())) {
return -1;
}
ItemStack removed = next.getValue1().getMultipleItems(item, wanted);
if (removed == null || removed.stackSize == 0) {
continue;
}
int sent = removed.stackSize;
useEnergy(sent * neededEnergy());
IRoutedItem routedItem = SimpleServiceLocator.routedItemHelper.createNewTravelItem(removed);
routedItem.setDestination(destination);
routedItem.setTransportMode(TransportMode.Active);
routedItem.setAdditionalTargetInformation(info);
super.queueRoutedItem(routedItem, next.getValue2());
_orderManager.sendSuccessfull(sent, defersend, routedItem);
return sent;
}
_orderManager.sendFailed();
return 0;
}
use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.
the class CoreRoutedPipe method updateEntity.
@Override
public final void updateEntity() {
debug.tick();
spawnParticleTick();
if (stillNeedReplace) {
stillNeedReplace = false;
getWorld().notifyBlockChange(getX(), getY(), getZ(), getWorld().getBlock(getX(), getY(), getZ()));
/* TravelingItems are just held by a pipe, they don't need to know their world
* for(Triplet<IRoutedItem, ForgeDirection, ItemSendMode> item : _sendQueue) {
//assign world to any entityitem we created in readfromnbt
item.getValue1().getTravelingItem().setWorld(getWorld());
}*/
//first tick just create a router and do nothing.
firstInitialiseTick();
return;
}
if (repeatFor > 0) {
if (delayTo < System.currentTimeMillis()) {
delayTo = System.currentTimeMillis() + 200;
repeatFor--;
getWorld().markBlockForUpdate(getX(), getY(), getZ());
}
}
// remove old items _inTransit -- these should have arrived, but have probably been lost instead. In either case, it will allow a re-send so that another attempt to re-fill the inventory can be made.
while (_inTransitToMe.peek() != null && _inTransitToMe.peek().getTickToTimeOut() <= 0) {
final ItemRoutingInformation p = _inTransitToMe.poll();
if (LPConstants.DEBUG) {
LogisticsPipes.log.info("Timed Out: " + p.getItem().getFriendlyName() + " (" + p.hashCode() + ")");
}
debug.log("Timed Out: " + p.getItem().getFriendlyName() + " (" + p.hashCode() + ")");
}
//update router before ticking logic/transport
getRouter().update(getWorld().getTotalWorldTime() % Configs.LOGISTICS_DETECTION_FREQUENCY == _delayOffset || _initialInit || recheckConnections, this);
recheckConnections = false;
getOriginalUpgradeManager().securityTick();
super.updateEntity();
if (isNthTick(200)) {
getCacheHolder().trigger(null);
}
// from BaseRoutingLogic
if (--throttleTimeLeft <= 0) {
throttledUpdateEntity();
throttleTimeLeft = throttleTime;
}
ignoreDisableUpdateEntity();
_initialInit = false;
if (!_sendQueue.isEmpty()) {
if (getItemSendMode() == ItemSendMode.Normal) {
Triplet<IRoutedItem, ForgeDirection, ItemSendMode> itemToSend = _sendQueue.getFirst();
sendRoutedItem(itemToSend.getValue1(), itemToSend.getValue2());
_sendQueue.removeFirst();
for (int i = 0; i < 16 && !_sendQueue.isEmpty() && _sendQueue.getFirst().getValue3() == ItemSendMode.Fast; i++) {
if (!_sendQueue.isEmpty()) {
itemToSend = _sendQueue.getFirst();
sendRoutedItem(itemToSend.getValue1(), itemToSend.getValue2());
_sendQueue.removeFirst();
}
}
sendQueueChanged(false);
} else if (getItemSendMode() == ItemSendMode.Fast) {
for (int i = 0; i < 16; i++) {
if (!_sendQueue.isEmpty()) {
Triplet<IRoutedItem, ForgeDirection, ItemSendMode> itemToSend = _sendQueue.getFirst();
sendRoutedItem(itemToSend.getValue1(), itemToSend.getValue2());
_sendQueue.removeFirst();
}
}
sendQueueChanged(false);
} else if (getItemSendMode() == null) {
throw new UnsupportedOperationException("getItemSendMode() can't return null. " + this.getClass().getName());
} else {
throw new UnsupportedOperationException("getItemSendMode() returned unhandled value. " + getItemSendMode().name() + " in " + this.getClass().getName());
}
}
if (MainProxy.isClient(getWorld())) {
return;
}
checkTexturePowered();
if (!isEnabled()) {
return;
}
enabledUpdateEntity();
if (getLogisticsModule() == null) {
return;
}
getLogisticsModule().tick();
}
use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.
the class CoreRoutedPipe method readFromNBT.
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
synchronized (routerIdLock) {
routerId = nbttagcompound.getString("routerId");
}
stat_lifetime_sent = nbttagcompound.getLong("stat_lifetime_sent");
stat_lifetime_recieved = nbttagcompound.getLong("stat_lifetime_recieved");
stat_lifetime_relayed = nbttagcompound.getLong("stat_lifetime_relayed");
if (getLogisticsModule() != null) {
getLogisticsModule().readFromNBT(nbttagcompound);
}
upgradeManager.readFromNBT(nbttagcompound.getCompoundTag("upgradeManager"));
powerHandler.readFromNBT(nbttagcompound.getCompoundTag("powerHandler"));
_sendQueue.clear();
NBTTagList sendqueue = nbttagcompound.getTagList("sendqueue", nbttagcompound.getId());
for (int i = 0; i < sendqueue.tagCount(); i++) {
NBTTagCompound tagentry = sendqueue.getCompoundTagAt(i);
NBTTagCompound tagentityitem = tagentry.getCompoundTag("entityitem");
LPTravelingItemServer item = new LPTravelingItemServer(tagentityitem);
ForgeDirection from = ForgeDirection.values()[tagentry.getByte("from")];
ItemSendMode mode = ItemSendMode.values()[tagentry.getByte("mode")];
_sendQueue.add(new Triplet<>(item, from, mode));
}
for (int i = 0; i < 6; i++) {
if (nbttagcompound.getBoolean("PipeSign_" + i)) {
int type = nbttagcompound.getInteger("PipeSign_" + i + "_type");
Class<? extends IPipeSign> typeClass = ItemPipeSignCreator.signTypes.get(type);
try {
signItem[i] = typeClass.newInstance();
signItem[i].init(this, ForgeDirection.getOrientation(i));
signItem[i].readFromNBT(nbttagcompound.getCompoundTag("PipeSign_" + i + "_tags"));
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
}
Aggregations