more fixes
This commit is contained in:
@@ -51,6 +51,7 @@ import appeng.core.AELog;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketMEInventoryUpdate;
|
||||
import appeng.core.sync.packets.PacketValueConfig;
|
||||
import appeng.helpers.WirelessTerminalGuiObject;
|
||||
import appeng.me.helpers.ChannelPowerSrc;
|
||||
import appeng.util.ConfigManager;
|
||||
import appeng.util.IConfigManagerHost;
|
||||
@@ -115,6 +116,9 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa
|
||||
|
||||
if (monitorable instanceof IPortableCell) {
|
||||
this.setPowerSource((IEnergySource) monitorable);
|
||||
if ( monitorable instanceof WirelessTerminalGuiObject) {
|
||||
this.networkNode = ((WirelessTerminalGuiObject) monitorable).getActionableNode();
|
||||
}
|
||||
} else if (monitorable instanceof IMEChest) {
|
||||
this.setPowerSource((IEnergySource) monitorable);
|
||||
} else if (monitorable instanceof IGridHost || monitorable instanceof IActionHost) {
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
package appeng.container.implementations;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.definitions.IDefinitions;
|
||||
import appeng.api.implementations.guiobjects.IGuiItemObject;
|
||||
import appeng.api.networking.security.IActionHost;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.ITerminalHost;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.container.ContainerNull;
|
||||
import appeng.container.guisync.GuiSync;
|
||||
import appeng.container.slot.AppEngSlot;
|
||||
import appeng.container.slot.IOptionalSlotHost;
|
||||
@@ -13,18 +20,23 @@ import appeng.container.slot.SlotPatternTerm;
|
||||
import appeng.container.slot.SlotPlayerHotBar;
|
||||
import appeng.container.slot.SlotPlayerInv;
|
||||
import appeng.container.slot.SlotRestrictedInput;
|
||||
import appeng.core.sync.packets.PacketPatternSlot;
|
||||
import appeng.helpers.IContainerCraftingPacket;
|
||||
import appeng.items.storage.ItemViewCell;
|
||||
import appeng.me.helpers.MachineSource;
|
||||
import appeng.parts.reporting.AbstractPartEncoder;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.AdaptorItemHandler;
|
||||
import appeng.util.inv.IAEAppEngInventory;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import appeng.util.inv.WrapperCursorItemHandler;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.IContainerListener;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.inventory.*;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
@@ -620,4 +632,98 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp
|
||||
this.detectAndSendChanges();
|
||||
this.getAndUpdateOutput();
|
||||
}
|
||||
|
||||
public void craftOrGetItem(final PacketPatternSlot packetPatternSlot) {
|
||||
if (packetPatternSlot.slotItem != null && this.getCellInventory() != null) {
|
||||
final IAEItemStack out = packetPatternSlot.slotItem.copy();
|
||||
InventoryAdaptor inv = new AdaptorItemHandler(new WrapperCursorItemHandler(this.getPlayerInv().player.inventory));
|
||||
final InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor(this.getPlayerInv().player);
|
||||
|
||||
if (packetPatternSlot.shift) {
|
||||
inv = playerInv;
|
||||
}
|
||||
|
||||
if (!inv.simulateAdd(out.createItemStack()).isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final IAEItemStack extracted = Platform.poweredExtraction(this.getPowerSource(), this.getCellInventory(), out, this.getActionSource());
|
||||
final EntityPlayer p = this.getPlayerInv().player;
|
||||
|
||||
if (extracted != null) {
|
||||
inv.addItems(extracted.createItemStack());
|
||||
if (p instanceof EntityPlayerMP) {
|
||||
this.updateHeld((EntityPlayerMP) p);
|
||||
}
|
||||
this.detectAndSendChanges();
|
||||
return;
|
||||
}
|
||||
|
||||
final InventoryCrafting ic = new InventoryCrafting(new ContainerNull(), 3, 3);
|
||||
final InventoryCrafting real = new InventoryCrafting(new ContainerNull(), 3, 3);
|
||||
|
||||
for (int x = 0; x < 9; x++) {
|
||||
ic.setInventorySlotContents(x, packetPatternSlot.pattern[x] == null ? ItemStack.EMPTY : packetPatternSlot.pattern[x].createItemStack());
|
||||
}
|
||||
|
||||
final IRecipe r = CraftingManager.findMatchingRecipe(ic, p.world);
|
||||
|
||||
if (r == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
IMEMonitor<IAEItemStack> storage = null;
|
||||
if (getPart() != null) {
|
||||
storage = this.getPart()
|
||||
.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
|
||||
} else if (iGuiItemObject != null) {
|
||||
storage = ((ITerminalHost)iGuiItemObject).getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
|
||||
}
|
||||
|
||||
final IItemList<IAEItemStack> all = storage.getStorageList();
|
||||
|
||||
final ItemStack is = r.getCraftingResult(ic);
|
||||
|
||||
for (int x = 0; x < ic.getSizeInventory(); x++) {
|
||||
if (!ic.getStackInSlot(x).isEmpty()) {
|
||||
final ItemStack pulled = Platform.extractItemsByRecipe(this.getPowerSource(), this.getActionSource(), storage, p.world, r, is, ic,
|
||||
ic.getStackInSlot(x), x, all, Actionable.MODULATE, ItemViewCell.createFilter(this.getViewCells()));
|
||||
real.setInventorySlotContents(x, pulled);
|
||||
}
|
||||
}
|
||||
|
||||
final IRecipe rr = CraftingManager.findMatchingRecipe(real, p.world);
|
||||
|
||||
if (rr == r && Platform.itemComparisons().isSameItem(rr.getCraftingResult(real), is)) {
|
||||
final InventoryCraftResult craftingResult = new InventoryCraftResult();
|
||||
craftingResult.setRecipeUsed(rr);
|
||||
|
||||
final SlotCrafting sc = new SlotCrafting(p, real, craftingResult, 0, 0, 0);
|
||||
sc.onTake(p, is);
|
||||
|
||||
for (int x = 0; x < real.getSizeInventory(); x++) {
|
||||
final ItemStack failed = playerInv.addItems(real.getStackInSlot(x));
|
||||
|
||||
if (!failed.isEmpty()) {
|
||||
p.dropItem(failed, false);
|
||||
}
|
||||
}
|
||||
|
||||
inv.addItems(is);
|
||||
if (p instanceof EntityPlayerMP) {
|
||||
this.updateHeld((EntityPlayerMP) p);
|
||||
}
|
||||
this.detectAndSendChanges();
|
||||
} else {
|
||||
for (int x = 0; x < real.getSizeInventory(); x++) {
|
||||
final ItemStack failed = real.getStackInSlot(x);
|
||||
if (!failed.isEmpty()) {
|
||||
this.getCellInventory()
|
||||
.injectItems(AEItemStack.fromItemStack(failed), Actionable.MODULATE,
|
||||
new MachineSource(this.getPart() != null? this.getPart() : (IActionHost) iGuiItemObject));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,36 +19,14 @@
|
||||
package appeng.container.implementations;
|
||||
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.ITerminalHost;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.container.ContainerNull;
|
||||
import appeng.container.slot.OptionalSlotFake;
|
||||
import appeng.container.slot.SlotFakeCraftingMatrix;
|
||||
import appeng.container.slot.SlotPatternOutputs;
|
||||
import appeng.container.slot.SlotPatternTerm;
|
||||
import appeng.container.slot.SlotRestrictedInput;
|
||||
import appeng.core.sync.packets.PacketPatternSlot;
|
||||
import appeng.items.storage.ItemViewCell;
|
||||
import appeng.me.helpers.MachineSource;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.AdaptorItemHandler;
|
||||
import appeng.util.inv.WrapperCursorItemHandler;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.InventoryCraftResult;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.inventory.SlotCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
|
||||
@@ -107,91 +85,4 @@ public class ContainerPatternTerm extends ContainerPatternEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
public void craftOrGetItem(final PacketPatternSlot packetPatternSlot) {
|
||||
if (packetPatternSlot.slotItem != null && this.getCellInventory() != null) {
|
||||
final IAEItemStack out = packetPatternSlot.slotItem.copy();
|
||||
InventoryAdaptor inv = new AdaptorItemHandler(new WrapperCursorItemHandler(this.getPlayerInv().player.inventory));
|
||||
final InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor(this.getPlayerInv().player);
|
||||
|
||||
if (packetPatternSlot.shift) {
|
||||
inv = playerInv;
|
||||
}
|
||||
|
||||
if (!inv.simulateAdd(out.createItemStack()).isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final IAEItemStack extracted = Platform.poweredExtraction(this.getPowerSource(), this.getCellInventory(), out, this.getActionSource());
|
||||
final EntityPlayer p = this.getPlayerInv().player;
|
||||
|
||||
if (extracted != null) {
|
||||
inv.addItems(extracted.createItemStack());
|
||||
if (p instanceof EntityPlayerMP) {
|
||||
this.updateHeld((EntityPlayerMP) p);
|
||||
}
|
||||
this.detectAndSendChanges();
|
||||
return;
|
||||
}
|
||||
|
||||
final InventoryCrafting ic = new InventoryCrafting(new ContainerNull(), 3, 3);
|
||||
final InventoryCrafting real = new InventoryCrafting(new ContainerNull(), 3, 3);
|
||||
|
||||
for (int x = 0; x < 9; x++) {
|
||||
ic.setInventorySlotContents(x, packetPatternSlot.pattern[x] == null ? ItemStack.EMPTY : packetPatternSlot.pattern[x].createItemStack());
|
||||
}
|
||||
|
||||
final IRecipe r = CraftingManager.findMatchingRecipe(ic, p.world);
|
||||
|
||||
if (r == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final IMEMonitor<IAEItemStack> storage = this.getPart()
|
||||
.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
|
||||
final IItemList<IAEItemStack> all = storage.getStorageList();
|
||||
|
||||
final ItemStack is = r.getCraftingResult(ic);
|
||||
|
||||
for (int x = 0; x < ic.getSizeInventory(); x++) {
|
||||
if (!ic.getStackInSlot(x).isEmpty()) {
|
||||
final ItemStack pulled = Platform.extractItemsByRecipe(this.getPowerSource(), this.getActionSource(), storage, p.world, r, is, ic,
|
||||
ic.getStackInSlot(x), x, all, Actionable.MODULATE, ItemViewCell.createFilter(this.getViewCells()));
|
||||
real.setInventorySlotContents(x, pulled);
|
||||
}
|
||||
}
|
||||
|
||||
final IRecipe rr = CraftingManager.findMatchingRecipe(real, p.world);
|
||||
|
||||
if (rr == r && Platform.itemComparisons().isSameItem(rr.getCraftingResult(real), is)) {
|
||||
final InventoryCraftResult craftingResult = new InventoryCraftResult();
|
||||
craftingResult.setRecipeUsed(rr);
|
||||
|
||||
final SlotCrafting sc = new SlotCrafting(p, real, craftingResult, 0, 0, 0);
|
||||
sc.onTake(p, is);
|
||||
|
||||
for (int x = 0; x < real.getSizeInventory(); x++) {
|
||||
final ItemStack failed = playerInv.addItems(real.getStackInSlot(x));
|
||||
|
||||
if (!failed.isEmpty()) {
|
||||
p.dropItem(failed, false);
|
||||
}
|
||||
}
|
||||
|
||||
inv.addItems(is);
|
||||
if (p instanceof EntityPlayerMP) {
|
||||
this.updateHeld((EntityPlayerMP) p);
|
||||
}
|
||||
this.detectAndSendChanges();
|
||||
} else {
|
||||
for (int x = 0; x < real.getSizeInventory(); x++) {
|
||||
final ItemStack failed = real.getStackInSlot(x);
|
||||
if (!failed.isEmpty()) {
|
||||
this.getCellInventory()
|
||||
.injectItems(AEItemStack.fromItemStack(failed), Actionable.MODULATE,
|
||||
new MachineSource(this.getPart()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,6 +139,8 @@ public class ContainerWirelessCraftingTerminal extends ContainerMEPortableCell i
|
||||
public IItemHandler getInventoryByName(final String name) {
|
||||
if (name.equals("player")) {
|
||||
return new PlayerInvWrapper(this.getInventoryPlayer());
|
||||
} else if (name.equals("crafting")) {
|
||||
return this.craftingGrid;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -225,6 +225,14 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder {
|
||||
super.onChangeInventory(inv, slot, mc, removedStack, newStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getInventoryByName(String name) {
|
||||
if (name.equals("crafting")) {
|
||||
return this.crafting;
|
||||
}
|
||||
return super.getInventoryByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useRealItems() {
|
||||
return false;
|
||||
|
||||
@@ -33,6 +33,7 @@ import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.container.implementations.ContainerExpandedProcessingPatternTerm;
|
||||
import appeng.container.implementations.ContainerPatternEncoder;
|
||||
import appeng.container.implementations.ContainerPatternTerm;
|
||||
import appeng.core.sync.AppEngPacket;
|
||||
import appeng.core.sync.network.INetworkInfo;
|
||||
@@ -252,7 +253,7 @@ public class PacketJEIRecipe extends AppEngPacket {
|
||||
|
||||
con.onCraftMatrixChanged(new WrapperInvItemHandler(craftMatrix));
|
||||
|
||||
if (this.output != null && ((con instanceof ContainerPatternTerm && !((ContainerPatternTerm) con).isCraftingMode()) || con instanceof ContainerExpandedProcessingPatternTerm)) {
|
||||
if (this.output != null && ((con instanceof ContainerPatternEncoder && !((ContainerPatternEncoder) con).isCraftingMode()))) {
|
||||
IItemHandler outputSlots = cct.getInventoryByName("output");
|
||||
for (int i = 0; i < outputSlots.getSlots(); ++i) {
|
||||
ItemHandlerUtil.setStackInSlot(outputSlots, i, ItemStack.EMPTY);
|
||||
|
||||
@@ -22,6 +22,7 @@ package appeng.core.sync.packets;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.container.implementations.ContainerPatternEncoder;
|
||||
import appeng.container.implementations.ContainerPatternTerm;
|
||||
import appeng.core.sync.AppEngPacket;
|
||||
import appeng.core.sync.network.INetworkInfo;
|
||||
@@ -98,9 +99,9 @@ public class PacketPatternSlot extends AppEngPacket {
|
||||
@Override
|
||||
public void serverPacketData(final INetworkInfo manager, final AppEngPacket packet, final EntityPlayer player) {
|
||||
final EntityPlayerMP sender = (EntityPlayerMP) player;
|
||||
if (sender.openContainer instanceof ContainerPatternTerm) {
|
||||
final ContainerPatternTerm patternTerminal = (ContainerPatternTerm) sender.openContainer;
|
||||
patternTerminal.craftOrGetItem(this);
|
||||
if (sender.openContainer instanceof ContainerPatternEncoder) {
|
||||
final ContainerPatternEncoder patternEncoder = (ContainerPatternEncoder) sender.openContainer;
|
||||
patternEncoder.craftOrGetItem(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,9 +27,7 @@ import appeng.api.definitions.IMaterials;
|
||||
import appeng.api.features.IGrinderRecipe;
|
||||
import appeng.api.features.IInscriberRecipe;
|
||||
import appeng.client.gui.AEGuiHandler;
|
||||
import appeng.container.implementations.ContainerCraftingTerm;
|
||||
import appeng.container.implementations.ContainerExpandedProcessingPatternTerm;
|
||||
import appeng.container.implementations.ContainerPatternTerm;
|
||||
import appeng.container.implementations.*;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.localization.GuiText;
|
||||
@@ -86,8 +84,10 @@ public class JEIPlugin implements IModPlugin {
|
||||
|
||||
// Allow recipe transfer from JEI to crafting and pattern terminal
|
||||
registry.getRecipeTransferRegistry().addRecipeTransferHandler(new RecipeTransferHandler<>(ContainerCraftingTerm.class), VanillaRecipeCategoryUid.CRAFTING);
|
||||
registry.getRecipeTransferRegistry().addRecipeTransferHandler(new RecipeTransferHandler<>(ContainerWirelessCraftingTerminal.class), VanillaRecipeCategoryUid.CRAFTING);
|
||||
registry.getRecipeTransferRegistry().addRecipeTransferHandler(new RecipeTransferHandler<>(ContainerPatternTerm.class), Constants.UNIVERSAL_RECIPE_TRANSFER_UID);
|
||||
registry.getRecipeTransferRegistry().addRecipeTransferHandler(new RecipeTransferHandler<>(ContainerExpandedProcessingPatternTerm.class), Constants.UNIVERSAL_RECIPE_TRANSFER_UID);
|
||||
registry.getRecipeTransferRegistry().addRecipeTransferHandler(new RecipeTransferHandler<>(ContainerWirelessPatternTerminal.class), Constants.UNIVERSAL_RECIPE_TRANSFER_UID);
|
||||
|
||||
aeGuiHandler = new AEGuiHandler();
|
||||
registry.addAdvancedGuiHandlers(aeGuiHandler);
|
||||
|
||||
@@ -20,6 +20,7 @@ package appeng.integration.modules.jei;
|
||||
|
||||
|
||||
import appeng.container.implementations.ContainerCraftingTerm;
|
||||
import appeng.container.implementations.ContainerPatternEncoder;
|
||||
import appeng.container.implementations.ContainerPatternTerm;
|
||||
import appeng.container.slot.SlotCraftingMatrix;
|
||||
import appeng.container.slot.SlotFakeCraftingMatrix;
|
||||
@@ -82,9 +83,9 @@ class RecipeTransferHandler<T extends Container> implements IRecipeTransferHandl
|
||||
return null;
|
||||
}
|
||||
|
||||
if (container instanceof ContainerPatternTerm) {
|
||||
if (container instanceof ContainerPatternEncoder) {
|
||||
try {
|
||||
if (!((ContainerPatternTerm) container).isCraftingMode()) {
|
||||
if (!((ContainerPatternEncoder) container).isCraftingMode()) {
|
||||
if (recipeType.equals(VanillaRecipeCategoryUid.CRAFTING)) {
|
||||
NetworkHandler.instance().sendToServer(new PacketValueConfig("PatternTerminal.CraftMode", "1"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user