use of net.minecraft.tileentity.TileEntity in project BluePower by Qmunity.
the class TileTransposer method pullItem.
protected void pullItem() {
ForgeDirection dir = getOutputDirection().getOpposite();
TileEntity inputTE = getTileCache(dir);
ItemStack extractedStack = IOHelper.extractOneItem(inputTE, dir.getOpposite());
if (extractedStack != null)
addItemToOutputBuffer(extractedStack);
}
use of net.minecraft.tileentity.TileEntity in project LogisticsPipes by RS485.
the class ModuleCrafter method enabledUpdateEntity.
public void enabledUpdateEntity() {
if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
if (_service.isNthTick(6)) {
cacheAreAllOrderesToBuffer();
}
if (_service.getItemOrderManager().isFirstOrderWatched()) {
TileEntity tile = lastAccessedCrafter.get();
if (tile != null) {
_service.getItemOrderManager().setMachineProgress(SimpleServiceLocator.machineProgressProvider.getProgressForTile(tile));
} else {
_service.getItemOrderManager().setMachineProgress((byte) 0);
}
}
} else {
cachedAreAllOrderesToBuffer = false;
}
if (!_service.isNthTick(6)) {
return;
}
waitingForCraft = false;
if ((!_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA))) {
if (getUpgradeManager().getCrafterCleanup() > 0) {
List<AdjacentTileEntity> crafters = locateCrafters();
ItemStack extracted = null;
for (AdjacentTileEntity adjacentCrafter : crafters) {
extracted = extractFiltered(adjacentCrafter, _cleanupInventory, cleanupModeIsExclude, getUpgradeManager().getCrafterCleanup() * 3);
if (extracted != null && extracted.stackSize > 0) {
break;
}
}
if (extracted != null && extracted.stackSize > 0) {
_service.queueRoutedItem(SimpleServiceLocator.routedItemHelper.createNewTravelItem(extracted), ForgeDirection.UP);
_service.getCacheHolder().trigger(CacheTypes.Inventory);
}
}
return;
}
waitingForCraft = true;
List<AdjacentTileEntity> adjacentCrafters = locateCrafters();
if (adjacentCrafters.size() < 1) {
if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
_service.getItemOrderManager().sendFailed();
}
return;
}
List<ItemIdentifierStack> wanteditem = getCraftedItems();
if (wanteditem == null || wanteditem.isEmpty()) {
return;
}
_service.spawnParticle(Particles.VioletParticle, 2);
int itemsleft = itemsToExtract();
int stacksleft = stacksToExtract();
while (itemsleft > 0 && stacksleft > 0 && (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA))) {
// fetch but not remove.
LogisticsItemOrder nextOrder = _service.getItemOrderManager().peekAtTopRequest(ResourceType.CRAFTING, ResourceType.EXTRA);
int maxtosend = Math.min(itemsleft, nextOrder.getResource().stack.getStackSize());
maxtosend = Math.min(nextOrder.getResource().getItem().getMaxStackSize(), maxtosend);
// retrieve the new crafted items
ItemStack extracted = null;
AdjacentTileEntity adjacent = null;
for (AdjacentTileEntity adjacentCrafter : adjacentCrafters) {
adjacent = adjacentCrafter;
extracted = extract(adjacent, nextOrder.getResource(), maxtosend);
if (extracted != null && extracted.stackSize > 0) {
break;
}
}
if (extracted == null || extracted.stackSize == 0) {
_service.getItemOrderManager().deferSend();
break;
}
_service.getCacheHolder().trigger(CacheTypes.Inventory);
lastAccessedCrafter = new WeakReference<>(adjacent.tileEntity);
// send the new crafted items to the destination
ItemIdentifier extractedID = ItemIdentifier.get(extracted);
while (extracted.stackSize > 0) {
if (!doesExtractionMatch(nextOrder, extractedID)) {
LogisticsItemOrder startOrder = nextOrder;
if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
do {
_service.getItemOrderManager().deferSend();
nextOrder = _service.getItemOrderManager().peekAtTopRequest(ResourceType.CRAFTING, ResourceType.EXTRA);
} while (!doesExtractionMatch(nextOrder, extractedID) && startOrder != nextOrder);
}
if (startOrder == nextOrder) {
int numtosend = Math.min(extracted.stackSize, extractedID.getMaxStackSize());
if (numtosend == 0) {
break;
}
stacksleft -= 1;
itemsleft -= numtosend;
ItemStack stackToSend = extracted.splitStack(numtosend);
//Route the unhandled item
_service.sendStack(stackToSend, -1, ItemSendMode.Normal, null);
continue;
}
}
int numtosend = Math.min(extracted.stackSize, extractedID.getMaxStackSize());
numtosend = Math.min(numtosend, nextOrder.getResource().stack.getStackSize());
if (numtosend == 0) {
break;
}
stacksleft -= 1;
itemsleft -= numtosend;
ItemStack stackToSend = extracted.splitStack(numtosend);
if (nextOrder.getDestination() != null) {
SinkReply reply = LogisticsManager.canSink(nextOrder.getDestination().getRouter(), null, true, ItemIdentifier.get(stackToSend), null, true, false);
boolean defersend = false;
if (reply == null || reply.bufferMode != BufferMode.NONE || reply.maxNumberOfItems < 1) {
defersend = true;
}
IRoutedItem item = SimpleServiceLocator.routedItemHelper.createNewTravelItem(stackToSend);
item.setDestination(nextOrder.getDestination().getRouter().getSimpleID());
item.setTransportMode(TransportMode.Active);
item.setAdditionalTargetInformation(nextOrder.getInformation());
_service.queueRoutedItem(item, adjacent.direction);
_service.getItemOrderManager().sendSuccessfull(stackToSend.stackSize, defersend, item);
} else {
_service.sendStack(stackToSend, -1, ItemSendMode.Normal, nextOrder.getInformation());
_service.getItemOrderManager().sendSuccessfull(stackToSend.stackSize, false, null);
}
if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
// fetch but not remove.
nextOrder = _service.getItemOrderManager().peekAtTopRequest(ResourceType.CRAFTING, ResourceType.EXTRA);
}
}
}
}
use of net.minecraft.tileentity.TileEntity in project LogisticsPipes by RS485.
the class RemoteOrderer method getPipe.
public static PipeItemsRemoteOrdererLogistics getPipe(ItemStack stack) {
if (stack == null) {
return null;
}
if (!stack.hasTagCompound()) {
return null;
}
if (!stack.stackTagCompound.hasKey("connectedPipe-x") || !stack.stackTagCompound.hasKey("connectedPipe-y") || !stack.stackTagCompound.hasKey("connectedPipe-z")) {
return null;
}
if (!stack.stackTagCompound.hasKey("connectedPipe-world-dim")) {
return null;
}
int dim = stack.stackTagCompound.getInteger("connectedPipe-world-dim");
World world = DimensionManager.getWorld(dim);
if (world == null) {
return null;
}
TileEntity tile = world.getTileEntity(stack.stackTagCompound.getInteger("connectedPipe-x"), stack.stackTagCompound.getInteger("connectedPipe-y"), stack.stackTagCompound.getInteger("connectedPipe-z"));
if (!(tile instanceof LogisticsTileGenericPipe)) {
return null;
}
CoreUnroutedPipe pipe = ((LogisticsTileGenericPipe) tile).pipe;
if (pipe instanceof PipeItemsRemoteOrdererLogistics) {
return (PipeItemsRemoteOrdererLogistics) pipe;
}
return null;
}
use of net.minecraft.tileentity.TileEntity in project LogisticsPipes by RS485.
the class CoordinatesPacket method getTileOrPipe.
@SuppressWarnings("unchecked")
public </**
* Retrieves tileEntity or CoreUnroutedPipe at packet coordinates if any.
*
* @param world
* @param clazz
* @return TileEntity
*/
T> T getTileOrPipe(World world, Class<T> clazz) {
if (world == null) {
targetNotFound("World was null");
return null;
}
if (!world.blockExists(getPosX(), getPosY(), getPosZ())) {
targetNotFound("Couldn't find " + clazz.getName());
return null;
}
final TileEntity tile = world.getTileEntity(getPosX(), getPosY(), getPosZ());
if (tile != null) {
if (clazz.isAssignableFrom(tile.getClass())) {
return (T) tile;
}
if (tile instanceof LogisticsTileGenericPipe) {
if (((LogisticsTileGenericPipe) tile).pipe != null && clazz.isAssignableFrom(((LogisticsTileGenericPipe) tile).pipe.getClass())) {
return (T) ((LogisticsTileGenericPipe) tile).pipe;
}
targetNotFound("Couldn't find " + clazz.getName() + ", found pipe with " + tile.getClass());
return null;
}
} else {
targetNotFound("Couldn't find " + clazz.getName());
return null;
}
targetNotFound("Couldn't find " + clazz.getName() + ", found " + tile.getClass());
return null;
}
use of net.minecraft.tileentity.TileEntity in project LogisticsPipes by RS485.
the class LogisticsCraftingOverlayHandler method overlayRecipe.
@Override
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
TileEntity tile;
LogisticsBaseGuiScreen gui;
if (firstGui instanceof GuiLogisticsCraftingTable) {
tile = ((GuiLogisticsCraftingTable) firstGui)._crafter;
gui = (GuiLogisticsCraftingTable) firstGui;
} else if (firstGui instanceof GuiRequestTable) {
tile = ((GuiRequestTable) firstGui)._table.container;
gui = (GuiRequestTable) firstGui;
} else {
return;
}
ItemStack[] stack = new ItemStack[9];
ItemStack[][] stacks = new ItemStack[9][];
boolean hasCanidates = false;
NEISetCraftingRecipe packet = PacketHandler.getPacket(NEISetCraftingRecipe.class);
for (PositionedStack ps : recipe.getIngredientStacks(recipeIndex)) {
int x = (ps.relx - 25) / 18;
int y = (ps.rely - 6) / 18;
int slot = x + y * 3;
if (x < 0 || x > 2 || y < 0 || y > 2 || slot < 0 || slot > 8) {
FMLClientHandler.instance().getClient().thePlayer.sendChatMessage("Internal Error. This button is broken.");
return;
}
if (slot < 9) {
stack[slot] = ps.items[0];
List<ItemStack> list = new ArrayList<>(Arrays.asList(ps.items));
Iterator<ItemStack> iter = list.iterator();
while (iter.hasNext()) {
ItemStack wildCardCheckStack = iter.next();
if (wildCardCheckStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
iter.remove();
wildCardCheckStack.getItem().getSubItems(wildCardCheckStack.getItem(), wildCardCheckStack.getItem().getCreativeTab(), list);
iter = list.iterator();
}
}
stacks[slot] = list.toArray(new ItemStack[0]);
if (stacks[slot].length > 1) {
hasCanidates = true;
} else if (stacks[slot].length == 1) {
stack[slot] = stacks[slot][0];
}
}
}
if (hasCanidates) {
gui.setSubGui(new GuiRecipeImport(tile, stacks));
} else {
MainProxy.sendPacketToServer(packet.setContent(stack).setPosX(tile.xCoord).setPosY(tile.yCoord).setPosZ(tile.zCoord));
}
}
Aggregations