Compare commits

...

12 Commits

Author SHA1 Message Date
PrototypeTrousers 1eec160b74 look for damageable items of the same type if substitutions are disabled 2022-10-24 16:09:22 -03:00
PrototypeTrousers de23b62493 some JEI work. missing player inventory check 2022-10-22 00:06:18 -03:00
Yang Xizhi 2b6299f2b0 fix expended pattern terminal can't place item manually (#161) 2022-10-20 16:35:20 -03:00
Yang Xizhi b495c972c4 add dev jar artifacts (#160) 2022-10-20 16:35:11 -03:00
PrototypeTrousers 7722dcc720 bump version. remove dead maven repo 2022-10-19 18:16:44 -03:00
PrototypeTrousers c4d5add5f1 allow part interfaces to be copied 2022-10-19 18:05:04 -03:00
PrototypeTrousers 348e6436b8 fix processing patterns encoding as invalid 2022-10-19 18:00:01 -03:00
PrototypeTrousers 92457ac680 bump version 2022-10-18 23:59:25 -03:00
PrototypeTrousers 9e53737635 Merge branch 'jei-transfer-highlight' into AE2-Omnifactory 2022-10-18 23:58:58 -03:00
PrototypeTrousers 0e0729166f Fix WCT invisible stacksizes, OOB when opening pattern terminal
FIx security station card slot being reaaally off
2022-10-18 23:56:40 -03:00
PrototypeTrousers 15a1e8f150 attempt to fix fluid interfaces capacity desync 2022-10-18 20:51:52 -03:00
PrototypeTrousers b443f1ce57 refactor pattern encoding terminals 2022-10-18 20:48:20 -03:00
21 changed files with 926 additions and 1172 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ aebuild=7
aegroup=appeng
aebasename=appliedenergistics2
extended=extended_life
extendedversion=v0.54.0
extendedversion=v0.54.2
#########################################################
# Versions #
#########################################################
+8
View File
@@ -60,8 +60,16 @@ task sourceJar(type: Jar, overwrite: true) {
classifier = 'sources'
}
task devJar(type: Jar, overwrite: true) {
from sourceSets.api.output
from sourceSets.main.output
classifier = 'dev'
}
artifacts {
archives apiJar
archives javadocJar
archives sourceJar
archives devJar
}
-5
View File
@@ -38,11 +38,6 @@ repositories {
url "http://dvs1.progwml6.com/files/maven"
}
maven {
name = "Tesla repo"
url "https://maven.mcmoddev.com"
}
maven {
name "Ellpeck"
url "https://maven.ellpeck.de"
@@ -899,7 +899,10 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain
if (s instanceof SlotPlayerInv || s instanceof SlotPlayerHotBar) {
super.drawSlot(s);
} else if (s instanceof AppEngSlot) {
((AppEngSlot) s).setDisplay(true);
AppEngSlot appEngSlot = ((AppEngSlot) s);
appEngSlot.setDisplay(true);
appEngSlot.setReturnAsSingleStack(true);
this.zLevel = 100.0F;
this.itemRender.zLevel = 100.0F;
@@ -913,7 +916,7 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain
// Annoying but easier than trying to splice into render item
super.drawSlot(s);
this.stackSizeRenderer.renderStackSize(this.fontRenderer, AEItemStack.fromItemStack(((AppEngSlot) s).getDisplayStack()), s.xPos, s.yPos);
this.stackSizeRenderer.renderStackSize(this.fontRenderer, AEItemStack.fromItemStack(appEngSlot.getDisplayStack()), s.xPos, s.yPos);
return;
} else {
super.drawSlot(s);
@@ -1,55 +1,33 @@
package appeng.container.implementations;
import appeng.api.AEApi;
import appeng.api.definitions.IDefinitions;
import appeng.api.storage.ITerminalHost;
import appeng.container.slot.*;
import appeng.helpers.IContainerCraftingPacket;
import appeng.parts.reporting.PartExpandedProcessingPatternTerminal;
import appeng.util.Platform;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import appeng.container.slot.OptionalSlotFake;
import appeng.container.slot.SlotFakeCraftingMatrix;
import appeng.container.slot.SlotPatternOutputs;
import appeng.container.slot.SlotRestrictedInput;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.PlayerInvWrapper;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import static appeng.helpers.PatternHelper.PROCESSING_INPUT_LIMIT;
import static appeng.helpers.PatternHelper.PROCESSING_OUTPUT_LIMIT;
public class ContainerExpandedProcessingPatternTerm extends ContainerMEMonitorable implements IAEAppEngInventory, IOptionalSlotHost, IContainerCraftingPacket {
private final IItemHandler crafting;
private final SlotFakeCraftingMatrix[] gridSlots = new SlotFakeCraftingMatrix[PROCESSING_INPUT_LIMIT];
private final OptionalSlotFake[] outputSlots = new OptionalSlotFake[PROCESSING_OUTPUT_LIMIT];
private final SlotRestrictedInput patternSlotIN;
private final SlotRestrictedInput patternSlotOUT;
private final PartExpandedProcessingPatternTerminal expandedProcessingPatternTerminal;
public class ContainerExpandedProcessingPatternTerm extends ContainerPatternEncoder {
public ContainerExpandedProcessingPatternTerm(InventoryPlayer ip, ITerminalHost monitorable) {
super(ip, monitorable, false);
this.expandedProcessingPatternTerminal = (PartExpandedProcessingPatternTerminal) monitorable;
this.craftingSlots = new SlotFakeCraftingMatrix[PROCESSING_INPUT_LIMIT];
this.outputSlots = new OptionalSlotFake[PROCESSING_OUTPUT_LIMIT];
final IItemHandler patternInv = this.getExpandedPatternTerminal().getInventoryByName("pattern");
final IItemHandler output = this.getExpandedPatternTerminal().getInventoryByName("output");
final IItemHandler patternInv = this.getPart().getInventoryByName("pattern");
final IItemHandler output = this.getPart().getInventoryByName("output");
this.crafting = this.getExpandedPatternTerminal().getInventoryByName("crafting");
this.crafting = this.getPart().getInventoryByName("crafting");
for (int y = 0; y < 4; y++) {
for (int x = 0; x < 4; x++) {
this.addSlotToContainer(this.gridSlots[x + y * 4] = new SlotFakeCraftingMatrix(this.crafting, x + y * 4, 4 + x * 18, -85 + y * 18));
this.addSlotToContainer(this.craftingSlots[x + y * 4] = new SlotFakeCraftingMatrix(this.crafting, x + y * 4, 4 + x * 18, -85 + y * 18));
}
}
@@ -67,124 +45,7 @@ public class ContainerExpandedProcessingPatternTerm extends ContainerMEMonitorab
this.patternSlotOUT.setStackLimit(1);
this.bindPlayerInventory(ip, 0, 0);
}
@Override
public ItemStack transferStackInSlot(final EntityPlayer p, final int idx) {
if (Platform.isClient()) {
return ItemStack.EMPTY;
}
if (this.inventorySlots.get(idx) instanceof SlotPlayerInv || this.inventorySlots.get(idx) instanceof SlotPlayerHotBar) {
final AppEngSlot clickSlot = (AppEngSlot) this.inventorySlots.get(idx); // require AE SLots!
ItemStack itemStack = clickSlot.getStack();
if (AEApi.instance().definitions().materials().blankPattern().isSameAs(itemStack)) {
IItemHandler patternInv = this.getExpandedPatternTerminal().getInventoryByName("pattern");
ItemStack remainder = patternInv.insertItem(0, itemStack, false);
clickSlot.putStack(remainder);
}
}
return super.transferStackInSlot(p, idx);
}
@Override
public void saveChanges() {
}
@Override
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) {
}
public void encodeAndMoveToInventory() {
encode();
ItemStack output = this.patternSlotOUT.getStack();
if (!output.isEmpty()) {
if (!getPlayerInv().addItemStackToInventory(output)) {
getPlayerInv().player.dropItem(output, false);
}
this.patternSlotOUT.putStack(ItemStack.EMPTY);
}
}
public void encode() {
ItemStack output = this.patternSlotOUT.getStack();
final ItemStack[] in = this.getInputs();
final ItemStack[] out = this.getOutputs();
// if there is no input, this would be silly.
if (in == null || out == null) {
return;
}
// first check the output slots, should either be null, or a pattern
if (!output.isEmpty() && !this.isPattern(output)) {
return;
} // if nothing is there we should snag a new pattern.
else if (output.isEmpty()) {
output = this.patternSlotIN.getStack();
if (output.isEmpty() || !this.isPattern(output)) {
return; // no blanks.
}
// remove one, and clear the input slot.
output.setCount(output.getCount() - 1);
if (output.getCount() == 0) {
this.patternSlotIN.putStack(ItemStack.EMPTY);
}
// add a new encoded pattern.
Optional<ItemStack> maybePattern = AEApi.instance().definitions().items().encodedPattern().maybeStack(1);
if (maybePattern.isPresent()) {
output = maybePattern.get();
this.patternSlotOUT.putStack(output);
}
}
// encode the slot.
final NBTTagCompound encodedValue = new NBTTagCompound();
final NBTTagList tagIn = new NBTTagList();
final NBTTagList tagOut = new NBTTagList();
for (final ItemStack i : in) {
tagIn.appendTag(this.createItemTag(i));
}
for (final ItemStack i : out) {
tagOut.appendTag(this.createItemTag(i));
}
encodedValue.setTag("in", tagIn);
encodedValue.setTag("out", tagOut);
encodedValue.setBoolean("crafting", false);
encodedValue.setBoolean("substitute", false);
output.setTagCompound(encodedValue);
}
boolean isPattern(final ItemStack output) {
if (output.isEmpty()) {
return false;
}
final IDefinitions definitions = AEApi.instance().definitions();
boolean isPattern = definitions.items().encodedPattern().isSameAs(output);
isPattern |= definitions.materials().blankPattern().isSameAs(output);
return isPattern;
}
NBTBase createItemTag(final ItemStack i) {
final NBTTagCompound c = new NBTTagCompound();
if (!i.isEmpty()) {
i.writeToNBT(c);
}
return c;
}
@Override
@@ -192,261 +53,8 @@ public class ContainerExpandedProcessingPatternTerm extends ContainerMEMonitorab
return true;
}
protected ItemStack[] getInputs() {
final ItemStack[] input = new ItemStack[16];
boolean hasValue = false;
for (int x = 0; x < this.gridSlots.length; x++) {
input[x] = this.gridSlots[x].getStack();
if (!input[x].isEmpty()) {
hasValue = true;
}
}
if (hasValue) {
return input;
}
return null;
}
protected ItemStack[] getOutputs() {
final List<ItemStack> list = new ArrayList<>(3);
boolean hasValue = false;
for (final OptionalSlotFake outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
if (!out.isEmpty() && out.getCount() > 0) {
list.add(out);
hasValue = true;
}
}
if (hasValue) {
return list.toArray(new ItemStack[0]);
}
return null;
}
public void clear() {
for (final Slot s : this.gridSlots) {
s.putStack(ItemStack.EMPTY);
}
for (final Slot s : this.outputSlots) {
s.putStack(ItemStack.EMPTY);
}
this.detectAndSendChanges();
}
@Override
public IItemHandler getInventoryByName(final String name) {
if (name.equals("player")) {
return new PlayerInvWrapper(this.getInventoryPlayer());
}
return this.getExpandedPatternTerminal().getInventoryByName(name);
}
@Override
public boolean useRealItems() {
public boolean isCraftingMode() {
return false;
}
public PartExpandedProcessingPatternTerminal getExpandedPatternTerminal() {
return this.expandedProcessingPatternTerminal;
}
public void multiply(int multiple) {
ItemStack[] input = new ItemStack[gridSlots.length];
boolean canMultiplyInputs = true;
boolean canMultiplyOutputs = true;
for (int x = 0; x < this.gridSlots.length; x++) {
input[x] = this.gridSlots[x].getStack();
if (!input[x].isEmpty() && input[x].getCount() * multiple > input[x].getMaxStackSize()) {
canMultiplyInputs = false;
}
}
for (final OptionalSlotFake outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
if (!out.isEmpty() && out.getCount() * multiple > out.getMaxStackSize()) {
canMultiplyOutputs = false;
}
}
if (canMultiplyInputs && canMultiplyOutputs) {
for (SlotFakeCraftingMatrix craftingSlot : this.gridSlots) {
ItemStack stack = craftingSlot.getStack();
if (!stack.isEmpty()) {
craftingSlot.getStack().setCount(stack.getCount() * multiple);
}
}
for (OptionalSlotFake outputSlot : this.outputSlots) {
ItemStack stack = outputSlot.getStack();
if (!stack.isEmpty()) {
outputSlot.getStack().setCount(stack.getCount() * multiple);
}
}
}
}
public void divide(int divide) {
ItemStack[] input = new ItemStack[gridSlots.length];
boolean canDivideInputs = true;
boolean canDivideOutputs = true;
for (int x = 0; x < this.gridSlots.length; x++) {
input[x] = this.gridSlots[x].getStack();
if (!input[x].isEmpty() && input[x].getCount() % divide != 0) {
canDivideInputs = false;
}
}
for (final OptionalSlotFake outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
if (!out.isEmpty() && out.getCount() % divide != 0) {
canDivideOutputs = false;
}
}
if (canDivideInputs && canDivideOutputs) {
for (SlotFakeCraftingMatrix craftingSlot : this.gridSlots) {
ItemStack stack = craftingSlot.getStack();
if (!stack.isEmpty()) {
craftingSlot.getStack().setCount(stack.getCount() / divide);
}
}
for (OptionalSlotFake outputSlot : this.outputSlots) {
ItemStack stack = outputSlot.getStack();
if (!stack.isEmpty()) {
outputSlot.getStack().setCount(stack.getCount() / divide);
}
}
}
}
public void increase(int increase) {
ItemStack[] input = new ItemStack[gridSlots.length];
boolean canIncreaseInputs = true;
boolean canIncreaseOutputs = true;
for (int x = 0; x < this.gridSlots.length; x++) {
input[x] = this.gridSlots[x].getStack();
if (!input[x].isEmpty() && input[x].getCount() + increase > input[x].getMaxStackSize()) {
canIncreaseInputs = false;
}
}
for (final OptionalSlotFake outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
if (!out.isEmpty() && out.getCount() + increase > out.getMaxStackSize()) {
canIncreaseOutputs = false;
}
}
if (canIncreaseInputs && canIncreaseOutputs) {
for (SlotFakeCraftingMatrix craftingSlot : this.gridSlots) {
ItemStack stack = craftingSlot.getStack();
if (!stack.isEmpty()) {
craftingSlot.getStack().setCount(stack.getCount() + increase);
}
}
for (OptionalSlotFake outputSlot : this.outputSlots) {
ItemStack stack = outputSlot.getStack();
if (!stack.isEmpty()) {
outputSlot.getStack().setCount(stack.getCount() + increase);
}
}
}
}
public void decrease(int decrease) {
ItemStack[] input = new ItemStack[gridSlots.length];
boolean canDecreaseInputs = true;
boolean canDecreaseOutputs = true;
for (int x = 0; x < this.gridSlots.length; x++) {
input[x] = this.gridSlots[x].getStack();
if (!input[x].isEmpty() && input[x].getCount() - decrease < 1) {
canDecreaseInputs = false;
}
}
for (final OptionalSlotFake outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
if (!out.isEmpty() && out.getCount() - decrease < 1) {
canDecreaseOutputs = false;
}
}
if (canDecreaseInputs && canDecreaseOutputs) {
for (SlotFakeCraftingMatrix craftingSlot : this.gridSlots) {
ItemStack stack = craftingSlot.getStack();
if (!stack.isEmpty()) {
craftingSlot.getStack().setCount(stack.getCount() - decrease);
}
}
for (OptionalSlotFake outputSlot : this.outputSlots) {
ItemStack stack = outputSlot.getStack();
if (!stack.isEmpty()) {
outputSlot.getStack().setCount(stack.getCount() - decrease);
}
}
}
}
public void maximizeCount() {
ItemStack[] input = new ItemStack[gridSlots.length];
boolean canGrowInputs = true;
boolean canGrowOutputs = true;
int maxInputStackGrowth = 0;
int maxOutputStackGrowth = 0;
for (int x = 0; x < this.gridSlots.length; x++) {
input[x] = this.gridSlots[x].getStack();
if (!input[x].isEmpty() && input[x].getMaxStackSize() - input[x].getCount() > maxInputStackGrowth) {
maxInputStackGrowth = input[x].getMaxStackSize() - input[x].getCount();
}
if (!input[x].isEmpty() && input[x].getCount() + maxInputStackGrowth > input[x].getMaxStackSize()) {
canGrowInputs = false;
}
}
for (final OptionalSlotFake outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
{
maxOutputStackGrowth = out.getMaxStackSize() - out.getCount();
}
if (!out.isEmpty() && out.getCount() + maxOutputStackGrowth > out.getMaxStackSize()) {
canGrowOutputs = false;
}
}
if (canGrowInputs && canGrowOutputs) {
int maxStackGrowth = Math.min(maxInputStackGrowth, maxOutputStackGrowth);
for (SlotFakeCraftingMatrix craftingSlot : this.gridSlots) {
ItemStack stack = craftingSlot.getStack();
if (!stack.isEmpty()) {
craftingSlot.getStack().setCount(stack.getCount() + maxStackGrowth);
}
}
for (OptionalSlotFake outputSlot : this.outputSlots) {
ItemStack stack = outputSlot.getStack();
if (!stack.isEmpty()) {
outputSlot.getStack().setCount(stack.getCount() + maxStackGrowth);
}
}
}
}
@Override
public void onSlotChange(final Slot s) {
if (s == this.patternSlotOUT && Platform.isServer()) {
for (final IContainerListener listener : this.listeners) {
for (final Slot slot : this.inventorySlots) {
if (slot instanceof OptionalSlotFake || slot instanceof SlotFakeCraftingMatrix) {
listener.sendSlotContents(this, slot.slotNumber, slot.getStack());
}
}
if (listener instanceof EntityPlayerMP) {
((EntityPlayerMP) listener).isChangingQuantityOnly = false;
}
}
this.detectAndSendChanges();
}
}
}
@@ -0,0 +1,550 @@
package appeng.container.implementations;
import appeng.api.AEApi;
import appeng.api.definitions.IDefinitions;
import appeng.api.storage.ITerminalHost;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.AppEngSlot;
import appeng.container.slot.IOptionalSlotHost;
import appeng.container.slot.OptionalSlotFake;
import appeng.container.slot.SlotFakeCraftingMatrix;
import appeng.container.slot.SlotPatternTerm;
import appeng.container.slot.SlotPlayerHotBar;
import appeng.container.slot.SlotPlayerInv;
import appeng.container.slot.SlotRestrictedInput;
import appeng.helpers.IContainerCraftingPacket;
import appeng.parts.reporting.AbstractPartEncoder;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.util.Platform;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
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.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.PlayerInvWrapper;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public abstract class ContainerPatternEncoder extends ContainerMEMonitorable implements IAEAppEngInventory, IOptionalSlotHost, IContainerCraftingPacket {
private final AbstractPartEncoder patternTerminal;
final AppEngInternalInventory cOut = new AppEngInternalInventory(null, 1);
protected IItemHandler crafting;
protected SlotPatternTerm craftSlot;
protected SlotRestrictedInput patternSlotIN;
protected SlotRestrictedInput patternSlotOUT;
private IRecipe currentRecipe;
protected SlotFakeCraftingMatrix[] craftingSlots;
protected OptionalSlotFake[] outputSlots;
@GuiSync(97)
public boolean craftingMode = true;
@GuiSync(96)
public boolean substitute = false;
public ContainerPatternEncoder(InventoryPlayer ip, ITerminalHost monitorable) {
super(ip, monitorable);
patternTerminal = (AbstractPartEncoder) monitorable;
}
protected ContainerPatternEncoder(InventoryPlayer ip, ITerminalHost monitorable, boolean bindInventory) {
super(ip, monitorable, bindInventory);
patternTerminal = (AbstractPartEncoder) monitorable;
}
@Override
public ItemStack transferStackInSlot(final EntityPlayer p, final int idx) {
if (Platform.isClient()) {
return ItemStack.EMPTY;
}
if (this.inventorySlots.get(idx) instanceof SlotPlayerInv || this.inventorySlots.get(idx) instanceof SlotPlayerHotBar) {
final AppEngSlot clickSlot = (AppEngSlot) this.inventorySlots.get(idx); // require AE SLots!
ItemStack itemStack = clickSlot.getStack();
if (AEApi.instance().definitions().materials().blankPattern().isSameAs(itemStack)) {
IItemHandler patternInv = this.getPart().getInventoryByName("pattern");
ItemStack remainder = patternInv.insertItem(0, itemStack, false);
clickSlot.putStack(remainder);
}
}
return super.transferStackInSlot(p, idx);
}
public AbstractPartEncoder getPart() {
return this.patternTerminal;
}
@Override
public abstract boolean isSlotEnabled(int idx);
@Override
public IItemHandler getInventoryByName(String name) {
if (name.equals("player")) {
return new PlayerInvWrapper(this.getInventoryPlayer());
}
return this.getPart().getInventoryByName(name);
}
@Override
public boolean useRealItems() {
return false;
}
@Override
public void saveChanges() {
}
@Override
public void onChangeInventory(IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack) {
}
@Override
public void putStackInSlot(int slotID, ItemStack stack) {
super.putStackInSlot(slotID, stack);
this.getAndUpdateOutput();
}
protected void updateOrderOfOutputSlots() {
if (!this.isCraftingMode()) {
if (craftSlot != null) {
this.craftSlot.xPos = -9000;
}
for (int y = 0; y < 3; y++) {
this.outputSlots[y].xPos = this.outputSlots[y].getX();
}
} else {
if (craftSlot != null) {
this.craftSlot.xPos = this.craftSlot.getX();
}
for (int y = 0; y < 3; y++) {
this.outputSlots[y].xPos = -9000;
}
}
}
@Override
public void onSlotChange(final Slot s) {
if (s == this.patternSlotOUT && Platform.isServer()) {
for (final IContainerListener listener : this.listeners) {
for (final Slot slot : this.inventorySlots) {
if (slot instanceof OptionalSlotFake || slot instanceof SlotFakeCraftingMatrix) {
listener.sendSlotContents(this, slot.slotNumber, slot.getStack());
}
}
if (listener instanceof EntityPlayerMP) {
((EntityPlayerMP) listener).isChangingQuantityOnly = false;
}
}
this.detectAndSendChanges();
}
}
public void encodeAndMoveToInventory() {
encode();
ItemStack output = this.patternSlotOUT.getStack();
if (!output.isEmpty()) {
if (!getPlayerInv().addItemStackToInventory(output)) {
getPlayerInv().player.dropItem(output, false);
}
this.patternSlotOUT.putStack(ItemStack.EMPTY);
}
}
public void encode() {
ItemStack output = this.patternSlotOUT.getStack();
final ItemStack[] in = this.getInputs();
final ItemStack[] out = this.getOutputs();
// if there is no input, this would be silly.
if (in == null || out == null) {
return;
}
// first check the output slots, should either be null, or a pattern
if (!output.isEmpty() && !this.isPattern(output)) {
return;
} // if nothing is there we should snag a new pattern.
else if (output.isEmpty()) {
output = this.patternSlotIN.getStack();
if (output.isEmpty() || !this.isPattern(output)) {
return; // no blanks.
}
// remove one, and clear the input slot.
output.setCount(output.getCount() - 1);
if (output.getCount() == 0) {
this.patternSlotIN.putStack(ItemStack.EMPTY);
}
// add a new encoded pattern.
Optional<ItemStack> maybePattern = AEApi.instance().definitions().items().encodedPattern().maybeStack(1);
if (maybePattern.isPresent()) {
output = maybePattern.get();
this.patternSlotOUT.putStack(output);
}
}
// encode the slot.
final NBTTagCompound encodedValue = new NBTTagCompound();
final NBTTagList tagIn = new NBTTagList();
final NBTTagList tagOut = new NBTTagList();
for (final ItemStack i : in) {
tagIn.appendTag(this.createItemTag(i));
}
for (final ItemStack i : out) {
tagOut.appendTag(this.createItemTag(i));
}
encodedValue.setTag("in", tagIn);
encodedValue.setTag("out", tagOut);
encodedValue.setBoolean("crafting", this.isCraftingMode());
encodedValue.setBoolean("substitute", this.isSubstitute());
output.setTagCompound(encodedValue);
}
public void multiply(int multiple) {
ItemStack[] input = new ItemStack[craftingSlots.length];
boolean canMultiplyInputs = true;
boolean canMultiplyOutputs = true;
for (int x = 0; x < this.craftingSlots.length; x++) {
input[x] = this.craftingSlots[x].getStack();
if (!input[x].isEmpty() && input[x].getCount() * multiple < 1) {
canMultiplyInputs = false;
}
}
for (final OptionalSlotFake outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
if (!out.isEmpty() && out.getCount() * multiple < 1) {
canMultiplyOutputs = false;
}
}
if (canMultiplyInputs && canMultiplyOutputs) {
for (SlotFakeCraftingMatrix craftingSlot : this.craftingSlots) {
ItemStack stack = craftingSlot.getStack();
if (!stack.isEmpty()) {
craftingSlot.getStack().setCount(stack.getCount() * multiple);
}
}
for (OptionalSlotFake outputSlot : this.outputSlots) {
ItemStack stack = outputSlot.getStack();
if (!stack.isEmpty()) {
outputSlot.getStack().setCount(stack.getCount() * multiple);
}
}
}
}
public void divide(int divide) {
ItemStack[] input = new ItemStack[craftingSlots.length];
boolean canDivideInputs = true;
boolean canDivideOutputs = true;
for (int x = 0; x < this.craftingSlots.length; x++) {
input[x] = this.craftingSlots[x].getStack();
if (!input[x].isEmpty() && input[x].getCount() % divide != 0) {
canDivideInputs = false;
}
}
for (final OptionalSlotFake outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
if (!out.isEmpty() && out.getCount() % divide != 0) {
canDivideOutputs = false;
}
}
if (canDivideInputs && canDivideOutputs) {
for (SlotFakeCraftingMatrix craftingSlot : this.craftingSlots) {
ItemStack stack = craftingSlot.getStack();
if (!stack.isEmpty()) {
craftingSlot.getStack().setCount(stack.getCount() / divide);
}
}
for (OptionalSlotFake outputSlot : this.outputSlots) {
ItemStack stack = outputSlot.getStack();
if (!stack.isEmpty()) {
outputSlot.getStack().setCount(stack.getCount() / divide);
}
}
}
}
public void increase(int increase) {
ItemStack[] input = new ItemStack[craftingSlots.length];
boolean canIncreaseInputs = true;
boolean canIncreaseOutputs = true;
for (int x = 0; x < this.craftingSlots.length; x++) {
input[x] = this.craftingSlots[x].getStack();
if (!input[x].isEmpty() && input[x].getCount() + increase < 1) {
canIncreaseInputs = false;
}
}
for (final OptionalSlotFake outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
if (!out.isEmpty() && out.getCount() + increase < 1) {
canIncreaseOutputs = false;
}
}
if (canIncreaseInputs && canIncreaseOutputs) {
for (SlotFakeCraftingMatrix craftingSlot : this.craftingSlots) {
ItemStack stack = craftingSlot.getStack();
if (!stack.isEmpty()) {
craftingSlot.getStack().setCount(stack.getCount() + increase);
}
}
for (OptionalSlotFake outputSlot : this.outputSlots) {
ItemStack stack = outputSlot.getStack();
if (!stack.isEmpty()) {
outputSlot.getStack().setCount(stack.getCount() + increase);
}
}
}
}
public void decrease(int decrease) {
ItemStack[] input = new ItemStack[craftingSlots.length];
boolean canDecreaseInputs = true;
boolean canDecreaseOutputs = true;
for (int x = 0; x < this.craftingSlots.length; x++) {
input[x] = this.craftingSlots[x].getStack();
if (!input[x].isEmpty() && input[x].getCount() - decrease < 1) {
canDecreaseInputs = false;
}
}
for (final OptionalSlotFake outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
if (!out.isEmpty() && out.getCount() - decrease < 1) {
canDecreaseOutputs = false;
}
}
if (canDecreaseInputs && canDecreaseOutputs) {
for (SlotFakeCraftingMatrix craftingSlot : this.craftingSlots) {
ItemStack stack = craftingSlot.getStack();
if (!stack.isEmpty()) {
craftingSlot.getStack().setCount(stack.getCount() - decrease);
}
}
for (OptionalSlotFake outputSlot : this.outputSlots) {
ItemStack stack = outputSlot.getStack();
if (!stack.isEmpty()) {
outputSlot.getStack().setCount(stack.getCount() - decrease);
}
}
}
}
public void maximizeCount() {
ItemStack[] input = new ItemStack[craftingSlots.length];
boolean canGrowInputs = true;
boolean canGrowOutputs = true;
int maxInputStackGrowth = 0;
int maxOutputStackGrowth = 0;
for (int x = 0; x < this.craftingSlots.length; x++) {
input[x] = this.craftingSlots[x].getStack();
if (!input[x].isEmpty() && input[x].getMaxStackSize() - input[x].getCount() > maxInputStackGrowth) {
maxInputStackGrowth = input[x].getMaxStackSize() - input[x].getCount();
}
if (!input[x].isEmpty() && input[x].getCount() + maxInputStackGrowth > input[x].getMaxStackSize()) {
canGrowInputs = false;
}
}
for (final OptionalSlotFake outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
{
maxOutputStackGrowth = out.getMaxStackSize() - out.getCount();
}
if (!out.isEmpty() && out.getCount() + maxOutputStackGrowth > out.getMaxStackSize()) {
canGrowOutputs = false;
}
}
if (canGrowInputs && canGrowOutputs) {
int maxStackGrowth = Math.min(maxInputStackGrowth, maxOutputStackGrowth);
for (SlotFakeCraftingMatrix craftingSlot : this.craftingSlots) {
ItemStack stack = craftingSlot.getStack();
if (!stack.isEmpty()) {
craftingSlot.getStack().setCount(stack.getCount() + maxStackGrowth);
}
}
for (OptionalSlotFake outputSlot : this.outputSlots) {
ItemStack stack = outputSlot.getStack();
if (!stack.isEmpty()) {
outputSlot.getStack().setCount(stack.getCount() + maxStackGrowth);
}
}
}
}
protected ItemStack[] getInputs() {
final ItemStack[] input = new ItemStack[craftingSlots.length];
boolean hasValue = false;
for (int x = 0; x < this.craftingSlots.length; x++) {
input[x] = this.craftingSlots[x].getStack();
if (!input[x].isEmpty()) {
hasValue = true;
}
}
if (hasValue) {
return input;
}
return null;
}
protected ItemStack[] getOutputs() {
if (this.isCraftingMode()) {
final ItemStack out = this.getAndUpdateOutput();
if (!out.isEmpty() && out.getCount() > 0) {
return new ItemStack[]{out};
}
} else {
final List<ItemStack> list = new ArrayList<>(outputSlots.length);
boolean hasValue = false;
for (final OptionalSlotFake outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
if (!out.isEmpty() && out.getCount() > 0) {
list.add(out);
hasValue = true;
}
}
if (hasValue) {
return list.toArray(new ItemStack[0]);
}
}
return null;
}
protected ItemStack getAndUpdateOutput() {
final World world = this.getPlayerInv().player.world;
final InventoryCrafting ic = new InventoryCrafting(this, 3, 3);
for (int x = 0; x < ic.getSizeInventory(); x++) {
ic.setInventorySlotContents(x, this.crafting.getStackInSlot(x));
}
if (this.currentRecipe == null || !this.currentRecipe.matches(ic, world)) {
this.currentRecipe = CraftingManager.findMatchingRecipe(ic, world);
}
final ItemStack is;
if (this.currentRecipe == null) {
is = ItemStack.EMPTY;
} else {
is = this.currentRecipe.getCraftingResult(ic);
}
this.cOut.setStackInSlot(0, is);
return is;
}
public boolean isCraftingMode() {
return this.craftingMode;
}
void setCraftingMode(final boolean craftingMode) {
this.craftingMode = craftingMode;
}
boolean isSubstitute() {
return this.substitute;
}
public void setSubstitute(final boolean substitute) {
this.substitute = substitute;
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
if (Platform.isServer()) {
if (this.isCraftingMode() != this.getPart().isCraftingRecipe()) {
this.setCraftingMode(this.getPart().isCraftingRecipe());
this.updateOrderOfOutputSlots();
}
this.substitute = this.getPart().isSubstitution();
}
}
@Override
public void onUpdate(final String field, final Object oldValue, final Object newValue) {
super.onUpdate(field, oldValue, newValue);
if (field.equals("craftingMode")) {
this.getAndUpdateOutput();
this.updateOrderOfOutputSlots();
}
}
boolean isPattern(final ItemStack output) {
if (output.isEmpty()) {
return false;
}
final IDefinitions definitions = AEApi.instance().definitions();
boolean isPattern = definitions.items().encodedPattern().isSameAs(output);
isPattern |= definitions.materials().blankPattern().isSameAs(output);
return isPattern;
}
NBTBase createItemTag(final ItemStack i) {
final NBTTagCompound c = new NBTTagCompound();
if (!i.isEmpty()) {
i.writeToNBT(c);
if (i.getCount() > i.getMaxStackSize()) {
c.setInteger("stackSize", i.getCount());
}
}
return c;
}
public void clear() {
for (final Slot s : this.craftingSlots) {
s.putStack(ItemStack.EMPTY);
}
for (final Slot s : this.outputSlots) {
s.putStack(ItemStack.EMPTY);
}
this.detectAndSendChanges();
this.getAndUpdateOutput();
}
}
@@ -21,7 +21,6 @@ package appeng.container.implementations;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.definitions.IDefinitions;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.channels.IItemStorageChannel;
@@ -39,16 +38,11 @@ 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.PartPatternTerminal;
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;
@@ -62,43 +56,22 @@ import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.PlayerInvWrapper;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEAppEngInventory, IOptionalSlotHost, IContainerCraftingPacket {
public class ContainerPatternTerm extends ContainerPatternEncoder {
private final PartPatternTerminal patternTerminal;
private final AppEngInternalInventory cOut = new AppEngInternalInventory(null, 1);
private final IItemHandler crafting;
private final SlotFakeCraftingMatrix[] craftingSlots = new SlotFakeCraftingMatrix[9];
private final OptionalSlotFake[] outputSlots = new OptionalSlotFake[3];
private final SlotPatternTerm craftSlot;
private final SlotRestrictedInput patternSlotIN;
private final SlotRestrictedInput patternSlotOUT;
private IRecipe currentRecipe;
@GuiSync(97)
public boolean craftingMode = true;
@GuiSync(96)
public boolean substitute = false;
public ContainerPatternTerm(final InventoryPlayer ip, final ITerminalHost monitorable) {
super(ip, monitorable, false);
this.patternTerminal = (PartPatternTerminal) monitorable;
final IItemHandler patternInv = this.getPatternTerminal().getInventoryByName("pattern");
final IItemHandler output = this.getPatternTerminal().getInventoryByName("output");
this.craftingSlots = new SlotFakeCraftingMatrix[9];
this.outputSlots = new OptionalSlotFake[3];
this.crafting = this.getPatternTerminal().getInventoryByName("crafting");
final IItemHandler patternInv = this.getPart().getInventoryByName("pattern");
final IItemHandler output = this.getPart().getInventoryByName("output");
this.crafting = this.getPart().getInventoryByName("crafting");
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 3; x++) {
@@ -110,7 +83,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
.getPowerSource(), monitorable, this.crafting, patternInv, this.cOut, 110, -76 + 18, this, 2, this));
this.craftSlot.setIIcon(-1);
for (int y = 0; y < 3; y++) {
for (int y = 0; y < this.outputSlots.length; y++) {
this.addSlotToContainer(this.outputSlots[y] = new SlotPatternOutputs(output, this, y, 110, -76 + y * 18, 0, 0, 1));
this.outputSlots[y].setRenderDisabled(false);
this.outputSlots[y].setIIcon(-1);
@@ -129,391 +102,13 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
this.updateOrderOfOutputSlots();
}
@Override
public ItemStack transferStackInSlot(final EntityPlayer p, final int idx) {
if (Platform.isClient()) {
return ItemStack.EMPTY;
}
if (this.inventorySlots.get(idx) instanceof SlotPlayerInv || this.inventorySlots.get(idx) instanceof SlotPlayerHotBar) {
final AppEngSlot clickSlot = (AppEngSlot) this.inventorySlots.get(idx); // require AE SLots!
ItemStack itemStack = clickSlot.getStack();
if (AEApi.instance().definitions().materials().blankPattern().isSameAs(itemStack)) {
IItemHandler patternInv = this.getPatternTerminal().getInventoryByName("pattern");
ItemStack remainder = patternInv.insertItem(0, itemStack, false);
clickSlot.putStack(remainder);
}
}
return super.transferStackInSlot(p, idx);
}
private void updateOrderOfOutputSlots() {
if (!this.isCraftingMode()) {
this.craftSlot.xPos = -9000;
for (int y = 0; y < 3; y++) {
this.outputSlots[y].xPos = this.outputSlots[y].getX();
}
} else {
this.craftSlot.xPos = this.craftSlot.getX();
for (int y = 0; y < 3; y++) {
this.outputSlots[y].xPos = -9000;
}
}
}
@Override
public void putStackInSlot(int slotID, ItemStack stack) {
super.putStackInSlot(slotID, stack);
this.getAndUpdateOutput();
}
protected ItemStack getAndUpdateOutput() {
final World world = this.getPlayerInv().player.world;
final InventoryCrafting ic = new InventoryCrafting(this, 3, 3);
for (int x = 0; x < ic.getSizeInventory(); x++) {
ic.setInventorySlotContents(x, this.crafting.getStackInSlot(x));
}
if (this.currentRecipe == null || !this.currentRecipe.matches(ic, world)) {
this.currentRecipe = CraftingManager.findMatchingRecipe(ic, world);
}
final ItemStack is;
if (this.currentRecipe == null) {
is = ItemStack.EMPTY;
} else {
is = this.currentRecipe.getCraftingResult(ic);
}
this.cOut.setStackInSlot(0, is);
return is;
}
@Override
public void saveChanges() {
}
@Override
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) {
}
public void encodeAndMoveToInventory() {
encode();
ItemStack output = this.patternSlotOUT.getStack();
if (!output.isEmpty()) {
if (!getPlayerInv().addItemStackToInventory(output)) {
getPlayerInv().player.dropItem(output, false);
}
this.patternSlotOUT.putStack(ItemStack.EMPTY);
}
}
public void encode() {
ItemStack output = this.patternSlotOUT.getStack();
final ItemStack[] in = this.getInputs();
final ItemStack[] out = this.getOutputs();
// if there is no input, this would be silly.
if (in == null || out == null) {
return;
}
// first check the output slots, should either be null, or a pattern
if (!output.isEmpty() && !this.isPattern(output)) {
return;
} // if nothing is there we should snag a new pattern.
else if (output.isEmpty()) {
output = this.patternSlotIN.getStack();
if (output.isEmpty() || !this.isPattern(output)) {
return; // no blanks.
}
// remove one, and clear the input slot.
output.setCount(output.getCount() - 1);
if (output.getCount() == 0) {
this.patternSlotIN.putStack(ItemStack.EMPTY);
}
// add a new encoded pattern.
Optional<ItemStack> maybePattern = AEApi.instance().definitions().items().encodedPattern().maybeStack(1);
if (maybePattern.isPresent()) {
output = maybePattern.get();
this.patternSlotOUT.putStack(output);
}
}
// encode the slot.
final NBTTagCompound encodedValue = new NBTTagCompound();
final NBTTagList tagIn = new NBTTagList();
final NBTTagList tagOut = new NBTTagList();
for (final ItemStack i : in) {
tagIn.appendTag(this.createItemTag(i));
}
for (final ItemStack i : out) {
tagOut.appendTag(this.createItemTag(i));
}
encodedValue.setTag("in", tagIn);
encodedValue.setTag("out", tagOut);
encodedValue.setBoolean("crafting", this.isCraftingMode());
encodedValue.setBoolean("substitute", this.isSubstitute());
output.setTagCompound(encodedValue);
}
public void multiply(int multiple) {
ItemStack[] input = new ItemStack[9];
boolean canMultiplyInputs = true;
boolean canMultiplyOutputs = true;
for (int x = 0; x < this.craftingSlots.length; x++) {
input[x] = this.craftingSlots[x].getStack();
if (!input[x].isEmpty() && input[x].getCount() * multiple < 0) {
canMultiplyInputs = false;
}
}
for (final OptionalSlotFake outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
if (!out.isEmpty() && out.getCount() * multiple < 0) {
canMultiplyOutputs = false;
}
}
if (canMultiplyInputs && canMultiplyOutputs) {
for (SlotFakeCraftingMatrix craftingSlot : this.craftingSlots) {
ItemStack stack = craftingSlot.getStack();
if (!stack.isEmpty())
craftingSlot.getStack().setCount(stack.getCount() * multiple);
}
for (OptionalSlotFake outputSlot : this.outputSlots) {
ItemStack stack = outputSlot.getStack();
if (!stack.isEmpty())
outputSlot.getStack().setCount(stack.getCount() * multiple);
}
}
}
public void divide(int divide) {
ItemStack[] input = new ItemStack[9];
boolean canDivideInputs = true;
boolean canDivideOutputs = true;
for (int x = 0; x < this.craftingSlots.length; x++) {
input[x] = this.craftingSlots[x].getStack();
if (!input[x].isEmpty() && input[x].getCount() % divide != 0) {
canDivideInputs = false;
}
}
for (final OptionalSlotFake outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
if (!out.isEmpty() && out.getCount() % divide != 0) {
canDivideOutputs = false;
}
}
if (canDivideInputs && canDivideOutputs) {
for (SlotFakeCraftingMatrix craftingSlot : this.craftingSlots) {
ItemStack stack = craftingSlot.getStack();
if (!stack.isEmpty())
craftingSlot.getStack().setCount(stack.getCount() / divide);
}
for (OptionalSlotFake outputSlot : this.outputSlots) {
ItemStack stack = outputSlot.getStack();
if (!stack.isEmpty())
outputSlot.getStack().setCount(stack.getCount() / divide);
}
}
}
public void increase(int increase) {
ItemStack[] input = new ItemStack[9];
boolean canIncreaseInputs = true;
boolean canIncreaseOutputs = true;
for (int x = 0; x < this.craftingSlots.length; x++) {
input[x] = this.craftingSlots[x].getStack();
if (!input[x].isEmpty() && input[x].getCount() + increase < 0) {
canIncreaseInputs = false;
}
}
for (final OptionalSlotFake outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
if (!out.isEmpty() && out.getCount() + increase < 0) {
canIncreaseOutputs = false;
}
}
if (canIncreaseInputs && canIncreaseOutputs) {
for (SlotFakeCraftingMatrix craftingSlot : this.craftingSlots) {
ItemStack stack = craftingSlot.getStack();
if (!stack.isEmpty())
craftingSlot.getStack().setCount(stack.getCount() + increase);
}
for (OptionalSlotFake outputSlot : this.outputSlots) {
ItemStack stack = outputSlot.getStack();
if (!stack.isEmpty())
outputSlot.getStack().setCount(stack.getCount() + increase);
}
}
}
public void decrease(int decrease) {
ItemStack[] input = new ItemStack[9];
boolean canDecreaseInputs = true;
boolean canDecreaseOutputs = true;
for (int x = 0; x < this.craftingSlots.length; x++) {
input[x] = this.craftingSlots[x].getStack();
if (!input[x].isEmpty() && input[x].getCount() - decrease < 1) {
canDecreaseInputs = false;
}
}
for (final OptionalSlotFake outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
if (!out.isEmpty() && out.getCount() - decrease < 1) {
canDecreaseOutputs = false;
}
}
if (canDecreaseInputs && canDecreaseOutputs) {
for (SlotFakeCraftingMatrix craftingSlot : this.craftingSlots) {
ItemStack stack = craftingSlot.getStack();
if (!stack.isEmpty())
craftingSlot.getStack().setCount(stack.getCount() - decrease);
}
for (OptionalSlotFake outputSlot : this.outputSlots) {
ItemStack stack = outputSlot.getStack();
if (!stack.isEmpty())
outputSlot.getStack().setCount(stack.getCount() - decrease);
}
}
}
public void maximizeCount() {
ItemStack[] input = new ItemStack[9];
boolean canGrowInputs = true;
boolean canGrowOutputs = true;
int maxInputStackGrowth = 0;
int maxOutputStackGrowth = 0;
for (int x = 0; x < this.craftingSlots.length; x++) {
input[x] = this.craftingSlots[x].getStack();
if (!input[x].isEmpty() && input[x].getMaxStackSize() - input[x].getCount() > maxInputStackGrowth) {
maxInputStackGrowth = input[x].getMaxStackSize() - input[x].getCount();
}
if (!input[x].isEmpty() && input[x].getCount() + maxInputStackGrowth > input[x].getMaxStackSize()) {
canGrowInputs = false;
}
}
for (final OptionalSlotFake outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
{
maxOutputStackGrowth = out.getMaxStackSize() - out.getCount();
}
if (!out.isEmpty() && out.getCount() + maxOutputStackGrowth > out.getMaxStackSize()) {
canGrowOutputs = false;
}
}
if (canGrowInputs && canGrowOutputs) {
int maxStackGrowth = Math.min(maxInputStackGrowth, maxOutputStackGrowth);
for (SlotFakeCraftingMatrix craftingSlot : this.craftingSlots) {
ItemStack stack = craftingSlot.getStack();
if (!stack.isEmpty())
craftingSlot.getStack().setCount(stack.getCount() + maxStackGrowth);
}
for (OptionalSlotFake outputSlot : this.outputSlots) {
ItemStack stack = outputSlot.getStack();
if (!stack.isEmpty())
outputSlot.getStack().setCount(stack.getCount() + maxStackGrowth);
}
}
}
protected ItemStack[] getInputs() {
final ItemStack[] input = new ItemStack[9];
boolean hasValue = false;
for (int x = 0; x < this.craftingSlots.length; x++) {
input[x] = this.craftingSlots[x].getStack();
if (!input[x].isEmpty()) {
hasValue = true;
}
}
if (hasValue) {
return input;
}
return null;
}
protected ItemStack[] getOutputs() {
if (this.isCraftingMode()) {
final ItemStack out = this.getAndUpdateOutput();
if (!out.isEmpty() && out.getCount() > 0) {
return new ItemStack[]{out};
}
} else {
final List<ItemStack> list = new ArrayList<>(3);
boolean hasValue = false;
for (final OptionalSlotFake outputSlot : this.outputSlots) {
final ItemStack out = outputSlot.getStack();
if (!out.isEmpty() && out.getCount() > 0) {
list.add(out);
hasValue = true;
}
}
if (hasValue) {
return list.toArray(new ItemStack[list.size()]);
}
}
return null;
}
boolean isPattern(final ItemStack output) {
if (output.isEmpty()) {
return false;
}
final IDefinitions definitions = AEApi.instance().definitions();
boolean isPattern = definitions.items().encodedPattern().isSameAs(output);
isPattern |= definitions.materials().blankPattern().isSameAs(output);
return isPattern;
}
NBTBase createItemTag(final ItemStack i) {
final NBTTagCompound c = new NBTTagCompound();
if (!i.isEmpty()) {
i.writeToNBT(c);
if (i.getCount() > i.getMaxStackSize()) {
c.setInteger("stackSize", i.getCount());
}
}
return c;
}
@Override
public boolean isSlotEnabled(final int idx) {
if (idx == 1) {
return Platform.isServer() ? !this.getPatternTerminal().isCraftingRecipe() : !this.isCraftingMode();
return Platform.isServer() ? !this.getPart().isCraftingRecipe() : !this.isCraftingMode();
} else if (idx == 2) {
return Platform.isServer() ? this.getPatternTerminal().isCraftingRecipe() : this.isCraftingMode();
return Platform.isServer() ? this.getPart().isCraftingRecipe() : this.isCraftingMode();
} else {
return false;
}
@@ -558,7 +153,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
return;
}
final IMEMonitor<IAEItemStack> storage = this.getPatternTerminal()
final IMEMonitor<IAEItemStack> storage = this.getPart()
.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
final IItemList<IAEItemStack> all = storage.getStorageList();
@@ -600,107 +195,10 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
if (!failed.isEmpty()) {
this.getCellInventory()
.injectItems(AEItemStack.fromItemStack(failed), Actionable.MODULATE,
new MachineSource(this.getPatternTerminal()));
new MachineSource(this.getPart()));
}
}
}
}
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
if (Platform.isServer()) {
if (this.isCraftingMode() != this.getPatternTerminal().isCraftingRecipe()) {
this.setCraftingMode(this.getPatternTerminal().isCraftingRecipe());
this.updateOrderOfOutputSlots();
}
this.substitute = this.patternTerminal.isSubstitution();
}
}
@Override
public void onUpdate(final String field, final Object oldValue, final Object newValue) {
super.onUpdate(field, oldValue, newValue);
if (field.equals("craftingMode")) {
this.getAndUpdateOutput();
this.updateOrderOfOutputSlots();
}
}
@Override
public void onSlotChange(final Slot s) {
if (s == this.patternSlotOUT && Platform.isServer()) {
for (final IContainerListener listener : this.listeners) {
for (final Slot slot : this.inventorySlots) {
if (slot instanceof OptionalSlotFake || slot instanceof SlotFakeCraftingMatrix) {
listener.sendSlotContents(this, slot.slotNumber, slot.getStack());
}
}
if (listener instanceof EntityPlayerMP) {
((EntityPlayerMP) listener).isChangingQuantityOnly = false;
}
}
this.detectAndSendChanges();
}
if (s == this.craftSlot && Platform.isClient()) {
this.getAndUpdateOutput();
}
}
public void clear() {
for (final Slot s : this.craftingSlots) {
s.putStack(ItemStack.EMPTY);
}
for (final Slot s : this.outputSlots) {
s.putStack(ItemStack.EMPTY);
}
this.detectAndSendChanges();
this.getAndUpdateOutput();
}
@Override
public IItemHandler getInventoryByName(final String name) {
if (name.equals("player")) {
return new PlayerInvWrapper(this.getInventoryPlayer());
}
return this.getPatternTerminal().getInventoryByName(name);
}
@Override
public boolean useRealItems() {
return false;
}
public void toggleSubstitute() {
this.substitute = !this.substitute;
this.detectAndSendChanges();
this.getAndUpdateOutput();
}
public boolean isCraftingMode() {
return this.craftingMode;
}
private void setCraftingMode(final boolean craftingMode) {
this.craftingMode = craftingMode;
}
public PartPatternTerminal getPatternTerminal() {
return this.patternTerminal;
}
boolean isSubstitute() {
return this.substitute;
}
public void setSubstitute(final boolean substitute) {
this.substitute = substitute;
}
}
@@ -61,7 +61,7 @@ public class ContainerSecurityStation extends ContainerMEMonitorable implements
this.securityBox = (TileSecurityStation) monitorable;
this.addSlotToContainer(this.configSlot = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.BIOMETRIC_CARD, this.securityBox
.getConfigSlot(), 0, 37, -33 + jeiOffset, ip));
.getConfigSlot(), 0, 37, -33, ip));
this.addSlotToContainer(
this.wirelessIn = new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.ENCODABLE_ITEM, this.wirelessEncoder, 0, 212, 10 + jeiOffset, ip));
@@ -46,6 +46,7 @@ public class AppEngSlot extends Slot {
private int IIcon = -1;
private hasCalculatedValidness isValid;
private boolean isDisplay = false;
private boolean returnAsSingleStack;
public AppEngSlot(final IItemHandler inv, final int idx, final int x, final int y) {
super(emptyInventory, idx, x, y);
@@ -94,16 +95,29 @@ public class AppEngSlot extends Slot {
return ItemStack.EMPTY;
}
if (this.isDisplay()) {
this.setDisplay(false);
ItemStack retStack = this.getDisplayStack().copy();
retStack.setCount(1);
return retStack;
if (this.returnAsSingleStack()) {
setReturnAsSingleStack(false);
ItemStack ret = this.getDisplayStack().copy();
ret.setCount(1);
return ret;
}
return this.getDisplayStack();
}
return this.itemHandler.getStackInSlot(this.index);
}
private boolean returnAsSingleStack() {
return this.returnAsSingleStack;
}
public void setReturnAsSingleStack(boolean returnAsSingleStack) {
this.returnAsSingleStack = returnAsSingleStack;
}
@Override
public void putStack(final ItemStack stack) {
if (this.isSlotEnabled()) {
@@ -133,7 +133,7 @@ public class PacketValueConfig extends AppEngPacket {
if (c instanceof ContainerPatternTerm) {
final ContainerPatternTerm cpt = (ContainerPatternTerm) c;
if (this.Name.equals("PatternTerminal.CraftMode")) {
cpt.getPatternTerminal().setCraftingRecipe(this.Value.equals("1"));
cpt.getPart().setCraftingRecipe(this.Value.equals("1"));
} else if (this.Name.equals("PatternTerminal.Encode")) {
if (this.Value.equals("2")) {
cpt.encodeAndMoveToInventory();
@@ -157,7 +157,7 @@ public class PacketValueConfig extends AppEngPacket {
} else if (this.Name.equals("PatternTerminal.MaximizeCount")) {
cpt.maximizeCount();
} else if (this.Name.equals("PatternTerminal.Substitute")) {
cpt.getPatternTerminal().setSubstitution(this.Value.equals("1"));
cpt.getPart().setSubstitution(this.Value.equals("1"));
}
} else if (c instanceof ContainerExpandedProcessingPatternTerm) {
final ContainerExpandedProcessingPatternTerm cept = (ContainerExpandedProcessingPatternTerm) c;
@@ -528,6 +528,7 @@ public class DualityFluidInterface implements IGridTickable, IStorageMonitorable
this.tanks.readFromNBT(data, "storage");
this.priority = data.getInteger("priority");
this.upgrades.readFromNBT(data, "upgrades");
this.tanks.setCapacity((int) (Math.pow(4, this.getInstalledUpgrades(Upgrades.CAPACITY) + 1) * Fluid.BUCKET_VOLUME));
this.readConfig();
}
@@ -43,12 +43,12 @@ import java.util.*;
public class PatternHelper implements ICraftingPatternDetails, Comparable<PatternHelper> {
private static final int CRAFTING_GRID_DIMENSION = 3;
public static final int CRAFTING_GRID_DIMENSION = 3;
private static final int CRAFTING_INPUT_LIMIT = CRAFTING_GRID_DIMENSION * CRAFTING_GRID_DIMENSION;
public static final int PROCESSING_INPUT_HEIGHT = 4;
public static final int PROCESSING_INPUT_WIDTH = 4;
public static final int PROCESSING_INPUT_LIMIT = PROCESSING_INPUT_HEIGHT * PROCESSING_INPUT_WIDTH;
private static final int CRAFTING_OUTPUT_LIMIT = 1;
public static final int CRAFTING_OUTPUT_LIMIT = 1;
public static final int PROCESSING_OUTPUT_LIMIT = 6;
private final ItemStack patternItem;
@@ -1,5 +1,6 @@
package appeng.integration.modules.jei;
import appeng.api.AEApi;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.AEBaseContainer;
@@ -7,17 +8,22 @@ import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketInventoryAction;
import appeng.helpers.InventoryAction;
import appeng.util.item.AEItemStack;
import com.google.common.base.Stopwatch;
import mezz.jei.api.gui.ITooltipCallback;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.translation.I18n;
import org.lwjgl.input.Mouse;
import java.util.List;
import java.util.concurrent.TimeUnit;
public class CraftableCallBack implements ITooltipCallback<ItemStack> {
private final IItemList<IAEItemStack> list;
private final Container container;
private final Stopwatch lastClicked = Stopwatch.createStarted();
public CraftableCallBack(Container container, IItemList<IAEItemStack> ir) {
this.list = ir;
@@ -26,18 +32,27 @@ public class CraftableCallBack implements ITooltipCallback<ItemStack> {
@Override
public void onTooltip(int slotIndex, boolean input, ItemStack ingredient, List<String> tooltip) {
if (!input) return;
if (list != null) {
AEItemStack stack = AEItemStack.fromItemStack(ingredient);
if (list.findPrecise(stack) != null) {
tooltip.add(I18n.translateToLocalFormatted("gui.appliedenergistics2.Missing"));
tooltip.add(I18n.translateToLocalFormatted("gui.tooltips.appliedenergistics2.Craftable"));
if (Mouse.isButtonDown(2)) {
((AEBaseContainer) container).setTargetStack(stack);
final PacketInventoryAction p = new PacketInventoryAction(InventoryAction.AUTO_CRAFT, container.getInventory().size(), 0);
NetworkHandler.instance().sendToServer(p);
IAEItemStack found = list.findPrecise(AEItemStack.fromItemStack(ingredient));
if (found != null) {
if (found.getStackSize() == 0) {
String line = "§c[" + I18n.translateToLocalFormatted("gui.appliedenergistics2.Missing") + "]";
tooltip.add(line);
}
if (found.isCraftable()) {
String line = "§1[" + I18n.translateToLocalFormatted("gui.tooltips.appliedenergistics2.Craftable") + "]";
tooltip.add(line);
if (Mouse.isButtonDown(2) && this.lastClicked.elapsed(TimeUnit.MILLISECONDS) > 200) {
this.lastClicked.reset().start();
((AEBaseContainer) container).setTargetStack(found);
final PacketInventoryAction p = new PacketInventoryAction(InventoryAction.AUTO_CRAFT, container.getInventory().size(), 0);
NetworkHandler.instance().sendToServer(p);
}
}
} else {
tooltip.add(I18n.translateToLocalFormatted("gui.appliedenergistics2.Missing"));
String line = "§c[" + I18n.translateToLocalFormatted("gui.appliedenergistics2.Missing") + "]";
tooltip.add(line);
}
}
}
@@ -1,6 +1,8 @@
package appeng.integration.modules.jei;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.client.gui.implementations.GuiCraftingTerm;
@@ -17,7 +19,10 @@ import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
import java.awt.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import static mezz.jei.api.recipe.transfer.IRecipeTransferError.Type.USER_FACING;
@@ -33,15 +38,16 @@ public class JEIMissingItem implements IRecipeTransferError {
IItemList<IAEItemStack> ir = g.getRepo().getList();
boolean found;
this.errored = false;
recipeLayout.getItemStacks().addTooltipCallback(new CraftableCallBack(container, ir));
IItemList<IAEItemStack> used = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
for (IGuiIngredient<?> i : recipeLayout.getItemStacks().getGuiIngredients().values()) {
found = false;
if (i.isInput() && i.getAllIngredients().size() > 0) {
for (Object o : i.getAllIngredients()) {
if (o instanceof ItemStack) {
ItemStack stack = (ItemStack) o;
List<?> allIngredients = i.getAllIngredients();
for (Object allIngredient : allIngredients) {
if (allIngredient instanceof ItemStack) {
ItemStack stack = (ItemStack) allIngredient;
if (!stack.isEmpty()) {
if (stack.getItem().isDamageable() || Platform.isGTDamageableItem(stack.getItem())) {
Collection<IAEItemStack> fuzzy = ir.findFuzzy(AEItemStack.fromItemStack(stack), FuzzyMode.IGNORE_ALL);
@@ -58,9 +64,12 @@ public class JEIMissingItem implements IRecipeTransferError {
} else {
IAEItemStack ext = ir.findPrecise(AEItemStack.fromItemStack(stack));
if (ext != null) {
if (ext.getStackSize() > 0) {
IAEItemStack usedStack = used.findPrecise(ext);
if (ext.getStackSize() > 0 && (usedStack == null || ext.getStackSize() > usedStack.getStackSize())) {
used.add(ext.copy().setStackSize(1));
found = true;
break;
} else {
found = false;
}
}
}
@@ -69,6 +78,7 @@ public class JEIMissingItem implements IRecipeTransferError {
}
if (!found) {
this.errored = true;
break;
}
}
}
@@ -91,15 +101,19 @@ public class JEIMissingItem implements IRecipeTransferError {
IItemList<IAEItemStack> ir = g.getRepo().getList();
boolean found;
boolean craftable;
int currentSlot = 0;
this.errored = false;
IItemList<IAEItemStack> used = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
for (IGuiIngredient<?> i : recipeLayout.getItemStacks().getGuiIngredients().values()) {
found = false;
craftable = false;
List<ItemStack> valid = new ArrayList<>();
if (i.isInput() && i.getAllIngredients().size() > 0) {
for (Object o : i.getAllIngredients()) {
if (o instanceof ItemStack) {
ItemStack stack = (ItemStack) o;
List<?> allIngredients = i.getAllIngredients();
for (Object allIngredient : allIngredients) {
if (allIngredient instanceof ItemStack) {
ItemStack stack = (ItemStack) allIngredient;
if (!stack.isEmpty()) {
if (stack.getItem().isDamageable() || Platform.isGTDamageableItem(stack.getItem())) {
Collection<IAEItemStack> fuzzy = ir.findFuzzy(AEItemStack.fromItemStack(stack), FuzzyMode.IGNORE_ALL);
@@ -108,6 +122,8 @@ public class JEIMissingItem implements IRecipeTransferError {
if (itemStack.getStackSize() > 0) {
if (itemStack.fuzzyComparison(AEItemStack.fromItemStack(stack), FuzzyMode.IGNORE_ALL)) {
found = true;
used.add(itemStack.copy().setStackSize(1));
valid.addAll(fuzzy.stream().map(IAEItemStack::createItemStack).collect(Collectors.toList()));
break;
}
} else {
@@ -120,29 +136,38 @@ public class JEIMissingItem implements IRecipeTransferError {
} else {
IAEItemStack ext = ir.findPrecise(AEItemStack.fromItemStack(stack));
if (ext != null) {
if (ext.getStackSize() > 0) {
break;
} else {
if (ext.isCraftable()) {
craftable = true;
IAEItemStack usedStack = used.findPrecise(ext);
if (ext.getStackSize() > 0 && (usedStack == null || usedStack.getStackSize() < ext.getStackSize())) {
used.add(ext.copy().setStackSize(1));
if (craftable) {
valid.clear();
}
valid.add(ext.copy().setStackSize(1).createItemStack());
found = true;
break;
} else if (ext.isCraftable()) {
valid.add(ext.copy().setStackSize(1).createItemStack());
craftable = true;
}
}
}
}
}
if (!found) {
if (craftable) {
i.drawHighlight(minecraft, new Color(0.0f, 0.0f, 1.0f, 0.4f), recipeX, recipeY);
} else {
i.drawHighlight(minecraft, new Color(1.0f, 0.0f, 0.0f, 0.4f), recipeX, recipeY);
}
this.errored = true;
}
if (!found) {
if (craftable) {
i.drawHighlight(minecraft, new Color(0.0f, 0.0f, 1.0f, 0.4f), recipeX, recipeY);
recipeLayout.getItemStacks().set(currentSlot, valid);
} else {
this.errored = false;
i.drawHighlight(minecraft, new Color(1.0f, 0.0f, 0.0f, 0.4f), recipeX, recipeY);
}
this.errored = true;
} else {
recipeLayout.getItemStacks().set(currentSlot, valid);
this.errored = false;
}
}
currentSlot++;
}
if (!this.errored) {
((RecipeLayout) recipeLayout).getRecipeTransferButton().init(Minecraft.getMinecraft().player.openContainer, Minecraft.getMinecraft().player);
@@ -639,9 +639,10 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU {
itemList = new ArrayList<>(1);
final IAEItemStack item = this.inventory.getItemList().findPrecise(input[x]);
if (item != null) {
itemList.add(item);
} else if (input[x].getDefinition().getItem().isDamageable() || Platform.isGTDamageableItem(input[x].getDefinition().getItem())) {
itemList.addAll(this.inventory.getItemList().findFuzzy(input[x], FuzzyMode.IGNORE_ALL));
}
}
+3 -3
View File
@@ -309,7 +309,7 @@ public abstract class AEBasePart implements IPart, IGridProxyable, IActionHost,
* @param from source of settings
* @param compound compound of source
*/
private void uploadSettings(final SettingsFrom from, final NBTTagCompound compound) {
public void uploadSettings(final SettingsFrom from, final NBTTagCompound compound, EntityPlayer player) {
if (compound != null) {
final IConfigManager cm = this.getConfigManager();
if (cm != null) {
@@ -359,7 +359,7 @@ public abstract class AEBasePart implements IPart, IGridProxyable, IActionHost,
* @param from source of settings
* @return compound of source
*/
private NBTTagCompound downloadSettings(final SettingsFrom from) {
protected NBTTagCompound downloadSettings(final SettingsFrom from) {
final NBTTagCompound output = new NBTTagCompound();
final IConfigManager cm = this.getConfigManager();
@@ -428,7 +428,7 @@ public abstract class AEBasePart implements IPart, IGridProxyable, IActionHost,
final String storedName = memoryCard.getSettingsName(memCardIS);
final NBTTagCompound data = memoryCard.getData(memCardIS);
if (name.equals(storedName)) {
this.uploadSettings(SettingsFrom.MEMORY_CARD, data);
this.uploadSettings(SettingsFrom.MEMORY_CARD, data, player);
memoryCard.notifyUser(player, MemoryCardMessages.SETTINGS_LOADED);
} else {
memoryCard.notifyUser(player, MemoryCardMessages.INVALID_MACHINE);
@@ -113,4 +113,5 @@ public abstract class PartBasicState extends AEBasePart implements IPowerChannel
private void setClientFlags(final int clientFlags) {
this.clientFlags = clientFlags;
}
}
@@ -22,6 +22,7 @@ package appeng.parts.misc;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.Upgrades;
import appeng.api.definitions.IMaterials;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.ICraftingLink;
import appeng.api.networking.crafting.ICraftingPatternDetails;
@@ -42,15 +43,19 @@ import appeng.api.storage.data.IAEStack;
import appeng.api.util.AECableType;
import appeng.api.util.IConfigManager;
import appeng.core.AppEng;
import appeng.core.localization.PlayerMessages;
import appeng.core.sync.GuiBridge;
import appeng.helpers.DualityInterface;
import appeng.helpers.IInterfaceHost;
import appeng.helpers.IPriorityHost;
import appeng.helpers.Reflected;
import appeng.items.misc.ItemEncodedPattern;
import appeng.items.parts.PartModels;
import appeng.parts.PartBasicState;
import appeng.parts.PartModel;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.util.Platform;
import appeng.util.SettingsFrom;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.IInventoryDestination;
import appeng.util.inv.InvOperation;
@@ -66,6 +71,7 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.PlayerMainInvWrapper;
import java.util.EnumSet;
import java.util.List;
@@ -275,4 +281,60 @@ public class PartInterface extends PartBasicState implements IGridTickable, ISto
public GuiBridge getGuiBridge() {
return GuiBridge.GUI_INTERFACE;
}
@Override
public NBTTagCompound downloadSettings(SettingsFrom from) {
NBTTagCompound output = super.downloadSettings(from);
if (from == SettingsFrom.MEMORY_CARD) {
final IItemHandler inv = this.getInventoryByName("patterns");
if (inv instanceof AppEngInternalInventory) {
((AppEngInternalInventory) inv).writeToNBT(output, "patterns");
}
}
return output;
}
@Override
public void uploadSettings(SettingsFrom from, NBTTagCompound compound, EntityPlayer player) {
super.uploadSettings(from, compound, player);
final IItemHandler inv = this.getInventoryByName("patterns");
if (inv instanceof AppEngInternalInventory) {
final AppEngInternalInventory target = (AppEngInternalInventory) inv;
AppEngInternalInventory tmp = new AppEngInternalInventory(null, target.getSlots());
tmp.readFromNBT(compound, "patterns");
PlayerMainInvWrapper playerInv = new PlayerMainInvWrapper(player.inventory);
final IMaterials materials = AEApi.instance().definitions().materials();
int missingPatternsToEncode = 0;
for (int i = 0; i < inv.getSlots(); i++) {
if (target.getStackInSlot(i).getItem() instanceof ItemEncodedPattern) {
ItemStack blank = materials.blankPattern().maybeStack(target.getStackInSlot(i).getCount()).get();
if (!player.addItemStackToInventory(blank)) {
player.dropItem(blank, true);
}
target.setStackInSlot(i, ItemStack.EMPTY);
}
}
for (int x = 0; x < tmp.getSlots(); x++) {
if (!tmp.getStackInSlot(x).isEmpty()) {
boolean found = false;
for (int i = 0; i < playerInv.getSlots(); i++) {
if (materials.blankPattern().isSameAs(playerInv.getStackInSlot(i))) {
target.setStackInSlot(x, tmp.getStackInSlot(x));
playerInv.getStackInSlot(i).shrink(1);
found = true;
break;
}
}
if (!found) {
missingPatternsToEncode++;
}
}
}
if (Platform.isServer() && missingPatternsToEncode > 0) {
player.sendMessage(PlayerMessages.MissingPatternsToEncode.get());
}
}
}
}
@@ -0,0 +1,152 @@
package appeng.parts.reporting;
import appeng.api.implementations.ICraftingPatternItem;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.parts.IPartModel;
import appeng.api.storage.data.IAEItemStack;
import appeng.core.sync.GuiBridge;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.util.inv.InvOperation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.items.IItemHandler;
import javax.annotation.Nonnull;
import java.util.List;
public abstract class AbstractPartEncoder extends AbstractPartTerminal {
protected AppEngInternalInventory crafting;
protected AppEngInternalInventory output;
protected AppEngInternalInventory pattern;
protected boolean craftingMode = true;
protected boolean substitute = false;
public AbstractPartEncoder(ItemStack is) {
super(is);
}
@Override
public void getDrops(final List<ItemStack> drops, final boolean wrenched) {
for (final ItemStack is : this.pattern) {
if (!is.isEmpty()) {
drops.add(is);
}
}
}
@Override
public void readFromNBT(final NBTTagCompound data) {
super.readFromNBT(data);
this.pattern.readFromNBT(data, "pattern");
this.output.readFromNBT(data, "outputList");
this.crafting.readFromNBT(data, "crafting");
}
@Override
public void writeToNBT(final NBTTagCompound data) {
super.writeToNBT(data);
this.pattern.writeToNBT(data, "pattern");
this.output.writeToNBT(data, "outputList");
this.crafting.writeToNBT(data, "crafting");
}
@Override
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) {
if (inv == this.pattern && slot == 1) {
final ItemStack is = this.pattern.getStackInSlot(1);
if (!is.isEmpty() && is.getItem() instanceof ICraftingPatternItem) {
final ICraftingPatternItem pattern = (ICraftingPatternItem) is.getItem();
final ICraftingPatternDetails details = pattern.getPatternForItem(is, this.getHost().getTile().getWorld());
if (details != null) {
this.setCraftingRecipe(details.isCraftable());
this.setSubstitution(details.canSubstitute());
for (int x = 0; x < this.crafting.getSlots() && x < details.getInputs().length; x++) {
final IAEItemStack item = details.getInputs()[x];
this.crafting.setStackInSlot(x, item == null ? ItemStack.EMPTY : item.createItemStack());
}
for (int x = 0; x < this.output.getSlots() && x < details.getOutputs().length; x++) {
final IAEItemStack item = details.getOutputs()[x];
this.output.setStackInSlot(x, item == null ? ItemStack.EMPTY : item.createItemStack());
}
}
}
} else if (inv == this.crafting) {
this.fixCraftingRecipes();
}
this.getHost().markForSave();
}
private void fixCraftingRecipes() {
if (this.isCraftingRecipe()) {
for (int x = 0; x < this.crafting.getSlots(); x++) {
final ItemStack is = this.crafting.getStackInSlot(x);
if (!is.isEmpty()) {
is.setCount(1);
}
}
}
}
public boolean isCraftingRecipe() {
return this.craftingMode;
}
public void setCraftingRecipe(final boolean craftingMode) {
this.craftingMode = craftingMode;
this.fixCraftingRecipes();
}
public boolean isSubstitution() {
return this.substitute;
}
public void setSubstitution(final boolean canSubstitute) {
this.substitute = canSubstitute;
}
@Override
public IItemHandler getInventoryByName(final String name) {
if (name.equals("crafting")) {
return this.crafting;
}
if (name.equals("output")) {
return this.output;
}
if (name.equals("pattern")) {
return this.pattern;
}
return super.getInventoryByName(name);
}
@Override
public GuiBridge getGui(final EntityPlayer p) {
int x = (int) p.posX;
int y = (int) p.posY;
int z = (int) p.posZ;
if (this.getHost().getTile() != null) {
x = this.getTile().getPos().getX();
y = this.getTile().getPos().getY();
z = this.getTile().getPos().getZ();
}
if (getGuiBridge().hasPermissions(this.getHost().getTile(), x, y, z, this.getSide(), p)) {
return getGuiBridge();
}
return GuiBridge.GUI_ME;
}
abstract public GuiBridge getGuiBridge();
@Nonnull
@Override
abstract public IPartModel getStaticModels();
}
@@ -1,29 +1,22 @@
package appeng.parts.reporting;
import appeng.api.implementations.ICraftingPatternItem;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.parts.IPartModel;
import appeng.api.storage.data.IAEItemStack;
import appeng.core.AppEng;
import appeng.core.sync.GuiBridge;
import appeng.helpers.Reflected;
import appeng.items.parts.PartModels;
import appeng.parts.PartModel;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.util.inv.InvOperation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.items.IItemHandler;
import java.util.List;
import javax.annotation.Nonnull;
import static appeng.helpers.PatternHelper.PROCESSING_INPUT_LIMIT;
import static appeng.helpers.PatternHelper.PROCESSING_OUTPUT_LIMIT;
public class PartExpandedProcessingPatternTerminal extends AbstractPartTerminal {
public class PartExpandedProcessingPatternTerminal extends AbstractPartEncoder {
@PartModels
public static final ResourceLocation MODEL_OFF = new ResourceLocation(AppEng.MOD_ID, "part/expanded_processing_pattern_terminal_off");
@PartModels
@@ -33,96 +26,31 @@ public class PartExpandedProcessingPatternTerminal extends AbstractPartTerminal
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_ON);
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL);
private final AppEngInternalInventory crafting = new AppEngInternalInventory(this, PROCESSING_INPUT_LIMIT);
private final AppEngInternalInventory output = new AppEngInternalInventory(this, PROCESSING_OUTPUT_LIMIT);
private final AppEngInternalInventory pattern = new AppEngInternalInventory(this, 2);
@Reflected
public PartExpandedProcessingPatternTerminal(final ItemStack is) {
super(is);
this.crafting = new AppEngInternalInventory(this, PROCESSING_INPUT_LIMIT);
this.output = new AppEngInternalInventory(this, PROCESSING_OUTPUT_LIMIT);
this.pattern = new AppEngInternalInventory(this, 2);
this.craftingMode = false;
}
@Override
public void getDrops(final List<ItemStack> drops, final boolean wrenched) {
for (final ItemStack is : this.pattern) {
if (!is.isEmpty()) {
drops.add(is);
}
}
public boolean isCraftingRecipe() {
return false;
}
@Override
public void readFromNBT(NBTTagCompound data) {
super.readFromNBT(data);
this.crafting.readFromNBT(data, "processingGrid");
this.pattern.readFromNBT(data, "pattern");
this.output.readFromNBT(data, "outputList");
public void setCraftingRecipe(final boolean craftingMode) {
// NO-OP
}
@Override
public void writeToNBT(NBTTagCompound data) {
super.writeToNBT(data);
this.crafting.writeToNBT(data, "processingGrid");
this.pattern.writeToNBT(data, "pattern");
this.output.writeToNBT(data, "outputList");
}
@Override
public GuiBridge getGui(final EntityPlayer p) {
int x = (int) p.posX;
int y = (int) p.posY;
int z = (int) p.posZ;
if (this.getHost().getTile() != null) {
x = this.getTile().getPos().getX();
y = this.getTile().getPos().getY();
z = this.getTile().getPos().getZ();
}
if (GuiBridge.GUI_EXPANDED_PROCESSING_PATTERN_TERMINAL.hasPermissions(this.getHost().getTile(), x, y, z, this.getSide(), p)) {
return GuiBridge.GUI_EXPANDED_PROCESSING_PATTERN_TERMINAL;
}
return GuiBridge.GUI_ME;
}
@Override
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) {
if (inv == this.pattern && slot == 1) {
final ItemStack is = this.pattern.getStackInSlot(1);
if (!is.isEmpty() && is.getItem() instanceof ICraftingPatternItem) {
final ICraftingPatternItem pattern = (ICraftingPatternItem) is.getItem();
final ICraftingPatternDetails details = pattern.getPatternForItem(is, this.getHost().getTile().getWorld());
if (details != null) {
for (int x = 0; x < this.crafting.getSlots() && x < details.getInputs().length; x++) {
final IAEItemStack item = details.getInputs()[x];
this.crafting.setStackInSlot(x, item == null ? ItemStack.EMPTY : item.createItemStack());
}
for (int x = 0; x < this.output.getSlots() && x < details.getOutputs().length; x++) {
final IAEItemStack item = details.getOutputs()[x];
this.output.setStackInSlot(x, item == null ? ItemStack.EMPTY : item.createItemStack());
}
}
}
}
this.getHost().markForSave();
}
@Override
public IItemHandler getInventoryByName(final String name) {
if (name.equals("crafting")) {
return this.crafting;
}
if (name.equals("output")) {
return this.output;
}
if (name.equals("pattern")) {
return this.pattern;
}
return super.getInventoryByName(name);
public GuiBridge getGuiBridge() {
return GuiBridge.GUI_EXPANDED_PROCESSING_PATTERN_TERMINAL;
}
@Nonnull
@Override
public IPartModel getStaticModels() {
return this.selectModel(MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL);
@@ -19,27 +19,24 @@
package appeng.parts.reporting;
import appeng.api.implementations.ICraftingPatternItem;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.parts.IPartModel;
import appeng.api.storage.data.IAEItemStack;
import appeng.core.AppEng;
import appeng.core.sync.GuiBridge;
import appeng.helpers.Reflected;
import appeng.items.parts.PartModels;
import appeng.parts.PartModel;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.util.inv.InvOperation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.items.IItemHandler;
import java.util.List;
import javax.annotation.Nonnull;
import static appeng.helpers.PatternHelper.CRAFTING_GRID_DIMENSION;
import static appeng.helpers.PatternHelper.CRAFTING_OUTPUT_LIMIT;
public class PartPatternTerminal extends AbstractPartTerminal {
public class PartPatternTerminal extends AbstractPartEncoder {
@PartModels
public static final ResourceLocation MODEL_OFF = new ResourceLocation(AppEng.MOD_ID, "part/pattern_terminal_off");
@@ -50,25 +47,12 @@ public class PartPatternTerminal extends AbstractPartTerminal {
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_ON);
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL);
private final AppEngInternalInventory crafting = new AppEngInternalInventory(this, 9);
private final AppEngInternalInventory output = new AppEngInternalInventory(this, 3);
private final AppEngInternalInventory pattern = new AppEngInternalInventory(this, 2);
private boolean craftingMode = true;
private boolean substitute = false;
@Reflected
public PartPatternTerminal(final ItemStack is) {
super(is);
}
@Override
public void getDrops(final List<ItemStack> drops, final boolean wrenched) {
for (final ItemStack is : this.pattern) {
if (!is.isEmpty()) {
drops.add(is);
}
}
this.crafting = new AppEngInternalInventory(this, CRAFTING_GRID_DIMENSION * CRAFTING_GRID_DIMENSION);
this.output = new AppEngInternalInventory(this, 3);
this.pattern = new AppEngInternalInventory(this, 2);
}
@Override
@@ -76,9 +60,6 @@ public class PartPatternTerminal extends AbstractPartTerminal {
super.readFromNBT(data);
this.setCraftingRecipe(data.getBoolean("craftingMode"));
this.setSubstitution(data.getBoolean("substitute"));
this.pattern.readFromNBT(data, "pattern");
this.output.readFromNBT(data, "outputList");
this.crafting.readFromNBT(data, "craftingGrid");
}
@Override
@@ -86,102 +67,14 @@ public class PartPatternTerminal extends AbstractPartTerminal {
super.writeToNBT(data);
data.setBoolean("craftingMode", this.craftingMode);
data.setBoolean("substitute", this.substitute);
this.pattern.writeToNBT(data, "pattern");
this.output.writeToNBT(data, "outputList");
this.crafting.writeToNBT(data, "craftingGrid");
}
@Override
public GuiBridge getGui(final EntityPlayer p) {
int x = (int) p.posX;
int y = (int) p.posY;
int z = (int) p.posZ;
if (this.getHost().getTile() != null) {
x = this.getTile().getPos().getX();
y = this.getTile().getPos().getY();
z = this.getTile().getPos().getZ();
}
if (GuiBridge.GUI_PATTERN_TERMINAL.hasPermissions(this.getHost().getTile(), x, y, z, this.getSide(), p)) {
return GuiBridge.GUI_PATTERN_TERMINAL;
}
return GuiBridge.GUI_ME;
}
@Override
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) {
if (inv == this.pattern && slot == 1) {
final ItemStack is = this.pattern.getStackInSlot(1);
if (!is.isEmpty() && is.getItem() instanceof ICraftingPatternItem) {
final ICraftingPatternItem pattern = (ICraftingPatternItem) is.getItem();
final ICraftingPatternDetails details = pattern.getPatternForItem(is, this.getHost().getTile().getWorld());
if (details != null) {
this.setCraftingRecipe(details.isCraftable());
this.setSubstitution(details.canSubstitute());
for (int x = 0; x < this.crafting.getSlots() && x < details.getInputs().length; x++) {
final IAEItemStack item = details.getInputs()[x];
this.crafting.setStackInSlot(x, item == null ? ItemStack.EMPTY : item.createItemStack());
}
for (int x = 0; x < this.output.getSlots() && x < details.getOutputs().length; x++) {
final IAEItemStack item = details.getOutputs()[x];
this.output.setStackInSlot(x, item == null ? ItemStack.EMPTY : item.createItemStack());
}
}
}
} else if (inv == this.crafting) {
this.fixCraftingRecipes();
}
this.getHost().markForSave();
}
private void fixCraftingRecipes() {
if (this.craftingMode) {
for (int x = 0; x < this.crafting.getSlots(); x++) {
final ItemStack is = this.crafting.getStackInSlot(x);
if (!is.isEmpty()) {
is.setCount(1);
}
}
}
}
public boolean isCraftingRecipe() {
return this.craftingMode;
}
public void setCraftingRecipe(final boolean craftingMode) {
this.craftingMode = craftingMode;
this.fixCraftingRecipes();
}
public boolean isSubstitution() {
return this.substitute;
}
public void setSubstitution(final boolean canSubstitute) {
this.substitute = canSubstitute;
}
@Override
public IItemHandler getInventoryByName(final String name) {
if (name.equals("crafting")) {
return this.crafting;
}
if (name.equals("output")) {
return this.output;
}
if (name.equals("pattern")) {
return this.pattern;
}
return super.getInventoryByName(name);
public GuiBridge getGuiBridge() {
return GuiBridge.GUI_PATTERN_TERMINAL;
}
@Nonnull
@Override
public IPartModel getStaticModels() {
return this.selectModel(MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL);