Compare commits

..

12 Commits

Author SHA1 Message Date
PrototypeTrousers ff1091d252 add toolitps to cells 2023-02-06 13:26:59 -03:00
PrototypeTrousers dd2f1c6dc7 attempt to fix stacking issues 2023-01-28 23:45:14 -03:00
PrototypeTrousers f14407b87a attempted fixes for spatialIO, security and ShaderTech compat 2023-01-28 14:09:23 -03:00
PrototypeTrousers 04f006695e fix terminals not being usable on servers 2023-01-12 12:55:35 -03:00
PrototypeTrousers 4f36ccf64d bump version 2023-01-09 14:25:24 -03:00
PrototypeTrousers d9b4410c94 attempt to fix #197 2023-01-09 02:26:48 -03:00
PrototypeTrousers 9bbd0ad61b ASM Patch ItemStack packet size setter and getter. code from StackUp 2023-01-09 02:15:45 -03:00
MycroftJr 662a7805dd add ItemStack to/from NBT helpers (#202)
to simplify the "stackSize" NBT tag workaround
2023-01-09 01:10:35 -03:00
PrototypeTrousers c46eadec08 Merge branch 'revert-async-repo' into AE2-Omnifactory 2023-01-09 01:08:47 -03:00
PrototypeTrousers 148207f5c3 Merge branch 'gtceu-fix' into PrototypeTrousers/AE2-Omnifactory 2023-01-09 01:08:39 -03:00
PrototypeTrousers 653557bc65 wip. auto-crafting still broken 2023-01-07 18:25:31 -03:00
PrototypeTrousers dde87448a9 initial patch 2023-01-07 12:37:21 -03:00
34 changed files with 512 additions and 118 deletions
+2
View File
@@ -66,6 +66,8 @@ archivesBaseName = aebasename
jar {
manifest {
attributes 'FMLAT': 'appeng_at.cfg'
attributes "FMLCorePlugin": "appeng.core.AE2ELCore"
attributes "FMLCorePluginContainsFMLMod": "true"
}
from sourceSets.api.output
+1 -1
View File
@@ -4,7 +4,7 @@ aebuild=7
aegroup=appeng
aebasename=appliedenergistics2
extended=extended_life
extendedversion=v0.54.16
extendedversion=v0.54.20
#########################################################
# Versions #
#########################################################
@@ -0,0 +1,11 @@
package com.enderio.core.common.interfaces;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
public interface IOverlayRenderAware {
public void renderItemOverlayIntoGUI(@Nonnull ItemStack stack, int xPosition, int yPosition);
}
@@ -61,6 +61,7 @@ import java.util.List;
import java.util.*;
import static appeng.client.render.BlockPosHighlighter.hilightBlock;
import static appeng.helpers.ItemStackHelper.stackFromNBT;
public class GuiInterfaceConfigurationTerminal extends AEBaseGui implements IJEIGhostIngredients {
@@ -299,11 +300,7 @@ public class GuiInterfaceConfigurationTerminal extends AEBaseGui implements IJEI
for (int x = 0; x < current.getInventory().getSlots(); x++) {
final String which = Integer.toString(x);
if (invData.hasKey(which)) {
NBTTagCompound tag = invData.getCompoundTag(which);
current.getInventory().setStackInSlot(x, new ItemStack(tag));
if (tag.hasKey("stackSize")) {
current.getInventory().getStackInSlot(x).setCount(tag.getInteger("stackSize"));
}
current.getInventory().setStackInSlot(x, stackFromNBT(invData.getCompoundTag(which)));
}
}
} catch (final NumberFormatException ignored) {
@@ -52,6 +52,7 @@ import java.io.IOException;
import java.util.*;
import static appeng.client.render.BlockPosHighlighter.hilightBlock;
import static appeng.helpers.ItemStackHelper.stackFromNBT;
public class GuiInterfaceTerminal extends AEBaseGui {
@@ -321,7 +322,7 @@ public class GuiInterfaceTerminal extends AEBaseGui {
for (int x = 0; x < current.getInventory().getSlots(); x++) {
final String which = Integer.toString(x);
if (invData.hasKey(which)) {
current.getInventory().setStackInSlot(x, new ItemStack(invData.getCompoundTag(which)));
current.getInventory().setStackInSlot(x, stackFromNBT(invData.getCompoundTag(which)));
}
}
} catch (final NumberFormatException ignored) {
@@ -388,7 +388,10 @@ public abstract class AEBaseContainer extends Container {
if (Platform.itemComparisons().isSameItem(tis, t)) // t.isItemEqual(tis))
{
int maxSize = d.getSlotStackLimit();
int maxSize = t.getMaxStackSize();
if (maxSize > d.getSlotStackLimit()) {
maxSize = d.getSlotStackLimit();
}
int placeAble = maxSize - t.getCount();
@@ -50,6 +50,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import static appeng.helpers.ItemStackHelper.stackWriteToNBT;
public final class ContainerInterfaceConfigurationTerminal extends AEBaseContainer {
@@ -310,10 +312,7 @@ public final class ContainerInterfaceConfigurationTerminal extends AEBaseContain
ItemHandlerUtil.setStackInSlot(inv.client, x + offset, is.isEmpty() ? ItemStack.EMPTY : is.copy());
if (!is.isEmpty()) {
is.writeToNBT(itemNBT);
if (is.getCount() > Byte.MAX_VALUE) {
itemNBT.setInteger("stackSize", is.getCount());
}
stackWriteToNBT(is, itemNBT);
}
tag.setTag(Integer.toString(x + offset), itemNBT);
@@ -57,6 +57,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import static appeng.helpers.ItemStackHelper.stackWriteToNBT;
public final class ContainerInterfaceTerminal extends AEBaseContainer {
@@ -345,7 +347,7 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer {
ItemHandlerUtil.setStackInSlot(inv.client, x + offset, is.isEmpty() ? ItemStack.EMPTY : is.copy());
if (!is.isEmpty()) {
is.writeToNBT(itemNBT);
stackWriteToNBT(is, itemNBT);
}
tag.setTag(Integer.toString(x + offset), itemNBT);
@@ -38,6 +38,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import static appeng.helpers.ItemStackHelper.stackWriteToNBT;
public abstract class ContainerPatternEncoder extends ContainerMEMonitorable implements IAEAppEngInventory, IOptionalSlotHost, IContainerCraftingPacket {
private final AbstractPartEncoder patternTerminal;
@@ -526,10 +528,7 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp
final NBTTagCompound c = new NBTTagCompound();
if (!i.isEmpty()) {
i.writeToNBT(c);
if (i.getCount() > Byte.MAX_VALUE) {
c.setInteger("stackSize", i.getCount());
}
stackWriteToNBT(i, c);
}
return c;
@@ -40,7 +40,6 @@ import appeng.util.inv.AdaptorItemHandler;
import appeng.util.inv.WrapperCursorItemHandler;
import appeng.util.inv.WrapperInvItemHandler;
import appeng.util.item.AEItemStack;
import com.blamejared.recipestages.RecipeStages;
import com.blamejared.recipestages.recipes.RecipeStage;
import net.darkhax.gamestages.GameStageHelper;
import net.darkhax.itemstages.ItemStages;
@@ -55,9 +54,10 @@ import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -101,16 +101,21 @@ public class SlotCraftingTerm extends AppEngCraftingSlot {
@Override
public ItemStack getStack() {
if (Platform.isClient() && Loader.isModLoaded("itemstages")) {
final ItemStack item = super.getStack();
final String itemsStage = ItemStages.getStage(item);
final String enchantStage = ItemStages.getEnchantStage(item);
final EntityPlayer player = Minecraft.getMinecraft().player;
if ((itemsStage != null && !GameStageHelper.hasStage(player, itemsStage))
|| (enchantStage != null && !GameStageHelper.hasStage(player, enchantStage)))
return ItemStack.EMPTY;
return itemstageStack();
}
return super.getStack();
}
@SideOnly(Side.CLIENT)
ItemStack itemstageStack() {
final ItemStack item = super.getStack();
final String itemsStage = ItemStages.getStage(item);
final String enchantStage = ItemStages.getEnchantStage(item);
final EntityPlayer player = Minecraft.getMinecraft().player;
if ((itemsStage != null && !GameStageHelper.hasStage(player, itemsStage))
|| (enchantStage != null && !GameStageHelper.hasStage(player, enchantStage)))
return ItemStack.EMPTY;
return super.getStack();
}
@@ -196,7 +201,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot {
final String enchantStage = ItemStages.getEnchantStage(recipe.getRecipeOutput());
if ((itemsStage != null && !GameStageHelper.hasStage(player, itemsStage))
|| (enchantStage != null && !GameStageHelper.hasStage(player, enchantStage)))
|| (enchantStage != null && !GameStageHelper.hasStage(player, enchantStage)))
return null;
}
+58
View File
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2018, 2020 Adrian Siekierka
*
* This file is part of StackUp.
*
* StackUp is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* StackUp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with StackUp. If not, see <http://www.gnu.org/licenses/>.
*/
package appeng.core;
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
import javax.annotation.Nullable;
import java.util.Map;
@IFMLLoadingPlugin.Name("AE2ELCore")
@IFMLLoadingPlugin.MCVersion("1.12.2")
@IFMLLoadingPlugin.SortingIndex(1001)
@IFMLLoadingPlugin.TransformerExclusions("appeng.core.transformer")
public class AE2ELCore implements IFMLLoadingPlugin {
@Override
public String[] getASMTransformerClass() {
return new String[]{
"appeng.core.transformer.AE2ELTransformer"
};
}
@Override
public String getModContainerClass() {
return null;
}
@Nullable
@Override
public String getSetupClass() {
return null;
}
@Override
public void injectData(Map<String, Object> data) {
}
@Override
public String getAccessTransformerClass() {
return null;
}
}
@@ -4,10 +4,25 @@ package appeng.core.api;
import appeng.api.config.IncludeExclude;
import appeng.api.storage.ICellInventory;
import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.IClientHelper;
import appeng.core.localization.GuiText;
import appeng.fluids.items.FluidDummyItem;
import appeng.fluids.util.AEFluidStack;
import appeng.util.item.AEItemStack;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.oredict.OreDictionary;
import org.lwjgl.input.Keyboard;
import java.util.Collection;
import java.util.List;
@@ -27,16 +42,72 @@ public class ApiClientHelper implements IClientHelper {
.getLocal());
}
IItemList<?> itemList = cellInventory.getChannel().createList();
if (handler.isPreformatted()) {
final String list = (handler.getIncludeExcludeMode() == IncludeExclude.WHITELIST ? GuiText.Included : GuiText.Excluded).getLocal();
if (handler.isFuzzy()) {
lines.add(GuiText.Partitioned.getLocal() + " - " + list + ' ' + GuiText.Fuzzy.getLocal());
lines.add("[" + GuiText.Partitioned.getLocal() + "]" + " - " + list + ' ' + GuiText.Fuzzy.getLocal());
} else {
lines.add(GuiText.Partitioned.getLocal() + " - " + list + ' ' + GuiText.Precise.getLocal());
lines.add("[" + GuiText.Partitioned.getLocal() + "]" + " - " + list + ' ' + GuiText.Precise.getLocal());
}
if (Minecraft.getMinecraft().gameSettings.advancedItemTooltips || Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
IItemHandler inv = cellInventory.getConfigInventory();
cellInventory.getAvailableItems((IItemList) itemList);
for (int i = 0; i < inv.getSlots(); i++) {
final ItemStack is = inv.getStackInSlot(i);
if (!is.isEmpty()) {
if (cellInventory.getChannel() instanceof IItemStorageChannel) {
if (!handler.isFuzzy()) {
final IAEItemStack ais = AEItemStack.fromItemStack(is);
IAEItemStack stocked = ((IItemList<IAEItemStack>) itemList).findPrecise(ais);
lines.add("[" + is.getDisplayName() + "]" + ": " + (stocked == null ? "0" : String.valueOf(stocked.getStackSize())));
} else {
final IAEItemStack ais = AEItemStack.fromItemStack(is);
Collection<IAEItemStack> stocked = ((IItemList<IAEItemStack>) itemList).findFuzzy(ais, handler.getCellInv().getFuzzyMode());
int[] ids = OreDictionary.getOreIDs(is);
long size = 0;
for (IAEItemStack ist : stocked) {
size += ist.getStackSize();
}
if (is.getItem().isDamageable()) {
lines.add("[" + is.getDisplayName() + "]" + ": " + size);
} else if (ids.length > 0) {
StringBuilder sb = new StringBuilder();
for (int j : ids) {
sb.append(OreDictionary.getOreName(j)).append(", ");
}
lines.add("[{" + sb.substring(0, sb.length() - 2) + "}]" + ": " + size);
}
}
} else if (cellInventory.getChannel() instanceof IFluidStorageChannel) {
final AEFluidStack ais;
if (is.getItem() instanceof FluidDummyItem) {
ais = AEFluidStack.fromFluidStack(((FluidDummyItem) is.getItem()).getFluidStack(is));
} else {
ais = AEFluidStack.fromFluidStack(FluidUtil.getFluidContained(is));
}
IAEFluidStack stocked = ((IItemList<IAEFluidStack>) itemList).findPrecise(ais);
lines.add("[" + is.getDisplayName() + "]" + ": " + (stocked == null ? "0" : String.valueOf(stocked.getStackSize())));
}
}
}
}
} else {
if (Minecraft.getMinecraft().gameSettings.advancedItemTooltips || Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
cellInventory.getAvailableItems((IItemList) itemList);
for (IAEStack<?> s : itemList) {
if (s instanceof IAEItemStack) {
lines.add(((IAEItemStack) s).getDefinition().getDisplayName() + ": " + s.getStackSize());
} else if (s instanceof IAEFluidStack) {
lines.add(((IAEFluidStack) s).getFluidStack().getLocalizedName() + ": " + s.getStackSize() + "mB");
}
}
}
}
}
}
@@ -28,6 +28,7 @@ package appeng.core.api.imc;
import appeng.api.AEApi;
import appeng.core.AELog;
import appeng.core.api.IIMCProcessor;
import net.minecraft.launchwrapper.Launch;
import net.minecraftforge.fml.common.event.FMLInterModComms.IMCMessage;
@@ -37,7 +38,7 @@ public class IMCSpatial implements IIMCProcessor {
public void process(final IMCMessage m) {
try {
final Class classInstance = Class.forName(m.getStringValue());
final Class classInstance = Class.forName(m.getStringValue(), false, Launch.classLoader);
AEApi.instance().registries().movable().whiteListTileEntity(classInstance);
} catch (final ClassNotFoundException e) {
AELog.info("Bad Class Registered: " + m.getStringValue() + " by " + m.getSender());
@@ -63,6 +63,8 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import static appeng.helpers.ItemStackHelper.stackFromNBT;
public class PacketJEIRecipe extends AppEngPacket {
@@ -85,7 +87,7 @@ public class PacketJEIRecipe extends AppEngPacket {
if (list.tagCount() > 0) {
this.recipe.add(new ItemStack[list.tagCount()]);
for (int y = 0; y < list.tagCount(); y++) {
this.recipe.get(x)[y] = new ItemStack(list.getCompoundTagAt(y));
this.recipe.get(x)[y] = stackFromNBT(list.getCompoundTagAt(y));
}
} else {
this.recipe.add(emptyArray);
@@ -97,7 +99,7 @@ public class PacketJEIRecipe extends AppEngPacket {
final NBTTagList outputList = comp.getTagList("outputs", 10);
this.output = new ArrayList<>();
for (int z = 0; z < outputList.tagCount(); z++) {
this.output.add(new ItemStack(outputList.getCompoundTagAt(z)));
this.output.add(stackFromNBT(outputList.getCompoundTagAt(z)));
}
}
}
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2018, 2020 Adrian Siekierka
*
* This file is part of StackUp.
*
* StackUp is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* StackUp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with StackUp. If not, see <http://www.gnu.org/licenses/>.
*/
package appeng.core.transformer;
import net.minecraft.launchwrapper.IClassTransformer;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.ClassNode;
import java.util.function.Consumer;
public class AE2ELTransformer implements IClassTransformer {
@Override
public byte[] transform(String name, String transformedName, byte[] basicClass) {
transformedName = transformedName.replace('/', '.');
byte[] data = basicClass;
Consumer<ClassNode> consumer = (n) -> {
};
Consumer<ClassNode> emptyConsumer = consumer;
if ("net.minecraft.item.ItemStack".equals(transformedName)) {
consumer = consumer.andThen(ItemStackPatch::patchCountGetSet);
}
if (consumer != emptyConsumer) {
return processNode(basicClass, consumer);
} else {
return data;
}
}
public static byte[] processNode(byte[] data, Consumer<ClassNode> classNodeConsumer) {
ClassReader reader = new ClassReader(data);
ClassNode nodeOrig = new ClassNode();
reader.accept(nodeOrig, 0);
classNodeConsumer.accept(nodeOrig);
ClassWriter writer = new ClassWriter(0);
nodeOrig.accept(writer);
return writer.toByteArray();
}
}
@@ -0,0 +1,98 @@
/*
* Copyright (c) 2018, 2020 Adrian Siekierka
*
* This file is part of StackUp.
*
* StackUp is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* StackUp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with StackUp. If not, see <http://www.gnu.org/licenses/>.
*/
package appeng.core.transformer;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import java.util.ListIterator;
public final class ItemStackPatch {
private ItemStackPatch() {
}
public static void patchCountGetSet(ClassNode node) {
for (MethodNode mn : node.methods) {
if ("<init>".equals(mn.name)) {
ListIterator<AbstractInsnNode> it = mn.instructions.iterator();
while (it.hasNext()) {
AbstractInsnNode in = it.next();
if (in instanceof LdcInsnNode && "Count".equals(((LdcInsnNode) in).cst)) {
AbstractInsnNode in2 = it.next();
if (in2.getOpcode() == Opcodes.INVOKEVIRTUAL) {
// :thinking:
boolean patched = false;
MethodInsnNode min2 = (MethodInsnNode) in2;
if (min2.name.equals("getByte")) {
min2.name = "getInteger";
patched = true;
} else if (min2.name.equals("func_74771_c")) {
min2.name = "func_74762_e";
patched = true;
}
if (patched) {
min2.desc = "(Ljava/lang/String;)I";
System.out.println("Patched ItemStack Count getter!");
}
}
}
}
} else if ("func_77955_b".equals(mn.name) || "writeToNBT".equals(mn.name)) {
ListIterator<AbstractInsnNode> it = mn.instructions.iterator();
while (it.hasNext()) {
AbstractInsnNode in = it.next();
if (in instanceof LdcInsnNode && "Count".equals(((LdcInsnNode) in).cst)) {
it.next();
it.next();
it.next();
AbstractInsnNode in2 = it.next();
if (in2.getOpcode() == Opcodes.INVOKEVIRTUAL) {
// :thinking:
boolean patched = false;
MethodInsnNode min2 = (MethodInsnNode) in2;
if (min2.name.equals("setByte")) {
min2.name = "setInteger";
patched = true;
} else if (min2.name.equals("func_74774_a")) {
min2.name = "func_74768_a";
patched = true;
}
if (patched) {
min2.desc = "(Ljava/lang/String;I)V";
System.out.println("Patched ItemStack Count setter!");
// Remove I2B cast
it.previous();
it.previous();
it.remove();
}
}
}
}
}
}
}
}
@@ -41,7 +41,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@Optional.Interface(iface = "gregtech.api.items.IToolItem", modid = "gregtech")
public class CraftingTreeNode {
// what slot!
@@ -101,6 +101,8 @@ import net.minecraftforge.items.wrapper.RangedWrapper;
import javax.annotation.Nullable;
import java.util.*;
import static appeng.helpers.ItemStackHelper.*;
public class DualityInterface implements IGridTickable, IStorageMonitorable, IInventoryDestination, IAEAppEngInventory, IConfigManagerHost, ICraftingProvider, IUpgradeableHost {
public static final int NUMBER_OF_STORAGE_SLOTS = 9;
@@ -208,12 +210,8 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
final NBTTagList waitingToSend = new NBTTagList();
if (this.waitingToSend != null) {
for (final ItemStack is : this.waitingToSend) {
final NBTTagCompound item = new NBTTagCompound();
is.writeToNBT(item);
if (is.getCount() > Byte.MAX_VALUE) {
item.setInteger("stackSize", is.getCount());
}
waitingToSend.appendTag(item);
final NBTTagCompound itemNBT = stackToNBT(is);
waitingToSend.appendTag(itemNBT);
}
}
data.setTag("waitingToSend", waitingToSend);
@@ -225,12 +223,8 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
NBTTagList waitingListSided = new NBTTagList();
if (this.waitingToSendFacing.containsKey(s)) {
for (final ItemStack is : this.waitingToSendFacing.get(s)) {
final NBTTagCompound item = new NBTTagCompound();
is.writeToNBT(item);
if (is.getCount() > Byte.MAX_VALUE) {
item.setInteger("stackSize", is.getCount());
}
waitingListSided.appendTag(item);
final NBTTagCompound itemNBT = stackToNBT(is);
waitingListSided.appendTag(itemNBT);
}
sidedWaitList.setTag(s.name(), waitingListSided);
}
@@ -246,10 +240,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
for (int x = 0; x < waitingList.tagCount(); x++) {
final NBTTagCompound c = waitingList.getCompoundTagAt(x);
if (c != null) {
final ItemStack is = new ItemStack(c);
if (c.hasKey("stackSize")) {
is.setCount(c.getInteger("stackSize"));
}
final ItemStack is = stackFromNBT(c);
this.addToSendList(is);
}
}
@@ -264,10 +255,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
for (int x = 0; x < w.tagCount(); x++) {
final NBTTagCompound c = w.getCompoundTagAt(x);
if (c != null) {
final ItemStack is = new ItemStack(c);
if (c.hasKey("stackSize")) {
is.setCount(c.getInteger("stackSize"));
}
final ItemStack is = stackFromNBT(c);
this.addToSendListFacing(is, EnumFacing.getFront(s.getIndex()));
}
}
@@ -28,6 +28,8 @@ import net.minecraft.util.text.TextFormatting;
import java.util.ArrayList;
import java.util.List;
import static appeng.helpers.ItemStackHelper.stackFromNBT;
public class InvalidPatternHelper {
@@ -89,11 +91,14 @@ public class InvalidPatternHelper {
private final ItemStack stack;
public PatternIngredient(NBTTagCompound tag) {
this.stack = new ItemStack(tag);
this.stack = stackFromNBT(tag);
if (this.stack.isEmpty()) {
this.id = tag.getString("id");
this.count = tag.getByte("Count");
if (tag.hasKey("stackSize")) {
this.count = tag.getInteger("stackSize");
}
this.damage = Math.max(0, tag.getShort("Damage"));
}
}
@@ -0,0 +1,30 @@
package appeng.helpers;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
/**
* Methods to help with the added "stackSize" NBT tag to get around "Count" being written and read as a byte.
*/
public class ItemStackHelper {
public static ItemStack stackFromNBT(NBTTagCompound itemNBT) {
ItemStack is = new ItemStack(itemNBT);
if (itemNBT.hasKey("stackSize")) {
is.setCount(itemNBT.getInteger("stackSize"));
}
return is;
}
public static void stackWriteToNBT(ItemStack is, NBTTagCompound itemNBT) {
is.writeToNBT(itemNBT);
if (is.getCount() > Byte.MAX_VALUE) {
itemNBT.setInteger("stackSize", is.getCount());
}
}
public static NBTTagCompound stackToNBT(ItemStack is) {
NBTTagCompound itemNBT = new NBTTagCompound();
stackWriteToNBT(is, itemNBT);
return itemNBT;
}
}
@@ -40,6 +40,8 @@ import net.minecraftforge.common.crafting.IShapedRecipe;
import java.util.*;
import static appeng.helpers.ItemStackHelper.stackFromNBT;
public class PatternHelper implements ICraftingPatternDetails, Comparable<PatternHelper> {
@@ -91,11 +93,7 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
for (int x = 0; x < inTag.tagCount(); x++) {
NBTTagCompound ingredient = inTag.getCompoundTagAt(x);
final ItemStack gs = new ItemStack(ingredient);
if (ingredient.hasKey("stackSize")) {
gs.setCount(ingredient.getInteger("stackSize"));
}
final ItemStack gs = stackFromNBT(ingredient);
if (!ingredient.hasNoTags() && gs.isEmpty()) {
throw new IllegalArgumentException("No pattern here!");
@@ -126,11 +124,7 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
for (int x = 0; x < outTag.tagCount(); x++) {
NBTTagCompound resultItemTag = outTag.getCompoundTagAt(x);
final ItemStack gs = new ItemStack(resultItemTag);
if (resultItemTag.hasKey("stackSize")) {
gs.setCount(resultItemTag.getInteger("stackSize"));
}
final ItemStack gs = stackFromNBT(resultItemTag);
if (!resultItemTag.hasNoTags() && gs.isEmpty()) {
throw new IllegalArgumentException("No pattern here!");
@@ -0,0 +1,74 @@
package appeng.integration.modules.gregtech;
import net.minecraft.item.ItemStack;
import net.minecraft.launchwrapper.Launch;
import net.minecraftforge.fml.relauncher.ReflectionHelper;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class ToolClass {
private static Class<?> GTToolClass;
private static Method getMaxItemDamage = null;
private static Method getItemDamage = null;
static {
try {
GTToolClass = Class.forName("gregtech.api.items.IToolItem", false, Launch.classLoader);
getItemDamage = ReflectionHelper.findMethod(GTToolClass, "getItemDamage", null, ItemStack.class);
getMaxItemDamage = ReflectionHelper.findMethod(GTToolClass, "getMaxItemDamage", null, ItemStack.class);
} catch (ClassNotFoundException ignored) {
try {
GTToolClass = Class.forName("gregtech.api.items.toolitem.IGTTool", false, Launch.classLoader);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
}
private static final Enum<Interfaces> GTToolInterface = getGTToolInterface();
public static Class<?> getGTToolClass() {
if (GTToolClass == null) {
System.out.printf("TToolClass == null");
}
return GTToolClass;
}
public static Enum<Interfaces> getGTToolInterface() {
if (GTToolClass.getName().equals("IToolItem")) {
return Interfaces.ITOOLITEM;
} else {
return Interfaces.IGTTOOL;
}
}
public static int getGTMaxDamage(ItemStack itemStack) {
if (GTToolInterface == Interfaces.ITOOLITEM) {
try {
return (int) getMaxItemDamage.invoke(itemStack.getItem(), itemStack);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
} else {
return itemStack.getMaxDamage();
}
}
public static int getGTitemDamage(ItemStack itemStack) {
if (GTToolInterface == Interfaces.ITOOLITEM) {
try {
return (int) getItemDamage.invoke(itemStack.getItem(), itemStack);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
} else {
return itemStack.getItemDamage();
}
}
enum Interfaces {
ITOOLITEM,
IGTTOOL
}
}
@@ -48,6 +48,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static appeng.helpers.ItemStackHelper.stackToNBT;
class RecipeTransferHandler<T extends Container> implements IRecipeTransferHandler<T> {
@@ -108,8 +110,7 @@ class RecipeTransferHandler<T extends Container> implements IRecipeTransferHandl
if (!ingredient.isInput()) {
ItemStack output = ingredient.getDisplayedIngredient();
if (output != null) {
final NBTTagCompound tag = new NBTTagCompound();
output.writeToNBT(tag);
final NBTTagCompound tag = stackToNBT(output);
outputs.appendTag(tag);
}
continue;
@@ -140,8 +141,7 @@ class RecipeTransferHandler<T extends Container> implements IRecipeTransferHandl
}
for (final ItemStack is : list) {
final NBTTagCompound tag = new NBTTagCompound();
is.writeToNBT(tag);
final NBTTagCompound tag = stackToNBT(is);
tags.appendTag(tag);
}
+4 -6
View File
@@ -138,16 +138,14 @@ public class SecurityCache implements ISecurityGrid {
@Override
public boolean hasPermission(final int playerID, final SecurityPermissions perm) {
if (playerID == -1) {
return true;
}
if (this.isAvailable()) {
final EnumSet<SecurityPermissions> perms = this.playerPerms.get(playerID);
if (perms == null) {
if (playerID == -1) // no default?
{
return false;
} else {
return this.hasPermission(-1, perm);
}
return this.hasPermission(-1, perm);
}
return perms.contains(perm);
@@ -138,18 +138,12 @@ public final class CompassService {
public void kill() {
this.executor.shutdown();
try {
this.executor.awaitTermination(6, TimeUnit.MINUTES);
this.jobSize = 0;
for (final CompassReader cr : this.worldSet.values()) {
cr.close();
}
this.worldSet.clear();
} catch (final InterruptedException e) {
// wrap this up..
this.jobSize = 0;
for (final CompassReader cr : this.worldSet.values()) {
cr.close();
}
this.worldSet.clear();
}
private CompassReader getReader(final World w) {
+7 -4
View File
@@ -39,6 +39,9 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import static appeng.helpers.ItemStackHelper.stackFromNBT;
import static appeng.helpers.ItemStackHelper.stackWriteToNBT;
public abstract class AEBaseInvTile extends AEBaseTile implements IAEAppEngInventory {
@@ -50,7 +53,7 @@ public abstract class AEBaseInvTile extends AEBaseTile implements IAEAppEngInven
final NBTTagCompound opt = data.getCompoundTag("inv");
for (int x = 0; x < inv.getSlots(); x++) {
final NBTTagCompound item = opt.getCompoundTag("item" + x);
ItemHandlerUtil.setStackInSlot(inv, x, new ItemStack(item));
ItemHandlerUtil.setStackInSlot(inv, x, stackFromNBT(item));
}
}
}
@@ -65,12 +68,12 @@ public abstract class AEBaseInvTile extends AEBaseTile implements IAEAppEngInven
if (inv != EmptyHandler.INSTANCE) {
final NBTTagCompound opt = new NBTTagCompound();
for (int x = 0; x < inv.getSlots(); x++) {
final NBTTagCompound item = new NBTTagCompound();
final NBTTagCompound itemNBT = new NBTTagCompound();
final ItemStack is = inv.getStackInSlot(x);
if (!is.isEmpty()) {
is.writeToNBT(item);
stackWriteToNBT(is, itemNBT);
}
opt.setTag("item" + x, item);
opt.setTag("item" + x, itemNBT);
}
data.setTag("inv", opt);
}
@@ -80,6 +80,9 @@ import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import static appeng.helpers.ItemStackHelper.stackFromNBT;
import static appeng.helpers.ItemStackHelper.stackWriteToNBT;
public class TileMolecularAssembler extends AENetworkInvTile implements IUpgradeableHost, IConfigManagerHost, IGridTickable, ICraftingMachine, IPowerChannelState {
private final InventoryCrafting craftingInv;
@@ -288,7 +291,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
final ItemStack pattern = this.myPlan.getPattern();
if (!pattern.isEmpty()) {
final NBTTagCompound compound = new NBTTagCompound();
pattern.writeToNBT(compound);
stackWriteToNBT(pattern, compound);
data.setTag("myPlan", compound);
data.setInteger("pushDirection", this.pushDirection.ordinal());
}
@@ -303,7 +306,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
public void readFromNBT(final NBTTagCompound data) {
super.readFromNBT(data);
if (data.hasKey("myPlan")) {
final ItemStack myPat = new ItemStack(data.getCompoundTag("myPlan"));
final ItemStack myPat = stackFromNBT(data.getCompoundTag("myPlan"));
if (!myPat.isEmpty() && myPat.getItem() instanceof ItemEncodedPattern) {
final World w = this.getWorld();
@@ -35,6 +35,9 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import static appeng.helpers.ItemStackHelper.stackFromNBT;
import static appeng.helpers.ItemStackHelper.stackToNBT;
public class AppEngInternalInventory extends ItemStackHandler implements Iterable<ItemStack> {
protected boolean enableClientEvents = false;
@@ -162,12 +165,8 @@ public class AppEngInternalInventory extends ItemStackHandler implements Iterabl
for (int i = 0; i < stacks.size(); i++) {
ItemStack is = stacks.get(i);
if (!is.isEmpty()) {
NBTTagCompound itemTag = new NBTTagCompound();
NBTTagCompound itemTag = stackToNBT(is);
itemTag.setInteger("Slot", i);
if (is.getCount() > Byte.MAX_VALUE) {
itemTag.setInteger("stackSize", stacks.get(i).getCount());
}
stacks.get(i).writeToNBT(itemTag);
nbtTagList.appendTag(itemTag);
}
}
@@ -196,11 +195,7 @@ public class AppEngInternalInventory extends ItemStackHandler implements Iterabl
NBTTagCompound itemTags = tagList.getCompoundTagAt(i);
int slot = itemTags.getInteger("Slot");
if (slot >= 0 && slot < stacks.size()) {
stacks.set(slot, new ItemStack(itemTags));
if (itemTags.hasKey("stackSize")) {
int stackSize = itemTags.getInteger("stackSize");
stacks.get(slot).setCount(stackSize);
}
stacks.set(slot, stackFromNBT(itemTags));
}
}
onLoad();
@@ -71,6 +71,8 @@ import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import static appeng.helpers.ItemStackHelper.stackFromNBT;
public class TileSecurityStation extends AENetworkTile implements ITerminalHost, IAEAppEngInventory, ILocatable, IConfigManagerHost, ISecurityProvider, IColorableTile {
@@ -175,7 +177,7 @@ public class TileSecurityStation extends AENetworkTile implements ITerminalHost,
for (final Object key : storedItems.getKeySet()) {
final NBTBase obj = storedItems.getTag((String) key);
if (obj instanceof NBTTagCompound) {
this.inventory.getStoredItems().add(AEItemStack.fromItemStack(new ItemStack((NBTTagCompound) obj)));
this.inventory.getStoredItems().add(AEItemStack.fromItemStack(stackFromNBT((NBTTagCompound) obj)));
}
}
}
+2 -3
View File
@@ -56,6 +56,7 @@ import appeng.fluids.util.AEFluidStack;
import appeng.hooks.TickHandler;
import appeng.integration.Integrations;
import appeng.integration.modules.bogosorter.InventoryBogoSortModule;
import appeng.integration.modules.gregtech.ToolClass;
import appeng.me.GridAccessException;
import appeng.me.GridNode;
import appeng.me.helpers.AENetworkProxy;
@@ -67,7 +68,6 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import gregtech.api.block.machines.BlockMachine;
import gregtech.api.items.IToolItem;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.util.GTUtility;
import ic2.api.item.ICustomDamageItem;
@@ -126,7 +126,6 @@ import java.util.*;
* @version rv2
* @since rv0
*/
@Optional.Interface(iface = "gregtech.api.items.IToolItem", modid = "gregtech")
@Optional.Interface(iface = "ic2.api.item.ICustomDamageItem", modid = "IC2")
public class Platform {
@@ -1417,7 +1416,7 @@ public class Platform {
//consider methods below moving to a compability class
public static boolean isGTDamageableItem(Item item) {
return ((GTLoaded) && item instanceof IToolItem);
return ((GTLoaded) && ToolClass.getGTToolClass().isAssignableFrom(item.getClass()));
}
public static MetaTileEntity getMetaTileEntity(IBlockAccess world, BlockPos pos) {
@@ -23,9 +23,9 @@ import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.core.Api;
import appeng.integration.modules.gregtech.ToolClass;
import appeng.util.Platform;
import com.google.common.primitives.Ints;
import gregtech.api.items.IToolItem;
import ic2.api.item.ICustomDamageItem;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.Item;
@@ -326,7 +326,7 @@ public class AEItemStack extends AEStack<IAEItemStack> implements IAEItemStack {
} else if (a.getItem().isDamageable()) {
return a.getItemDamage() > 1 == b.getItemDamage() > 1;
} else if (Platform.isGTDamageableItem(a.getItem())) {
return ((IToolItem) a.getItem()).getItemDamage(a) > 1 == ((IToolItem) b.getItem()).getItemDamage(b) > 1;
return (ToolClass.getGTitemDamage(a) > 1 == ToolClass.getGTitemDamage(b) > 1);
}
} else {
float percentDamageOfA = 0;
@@ -338,8 +338,8 @@ public class AEItemStack extends AEStack<IAEItemStack> implements IAEItemStack {
percentDamageOfA = (float) a.getItemDamage() / a.getMaxDamage();
percentDamageOfB = (float) b.getItemDamage() / b.getMaxDamage();
} else if (Platform.isGTDamageableItem(a.getItem())) {
percentDamageOfA = (float) ((IToolItem) a.getItem()).getItemDamage(a) / ((IToolItem) a.getItem()).getMaxItemDamage(a);
percentDamageOfB = (float) ((IToolItem) b.getItem()).getItemDamage(b) / ((IToolItem) b.getItem()).getMaxItemDamage(b);
percentDamageOfA = (float) ToolClass.getGTitemDamage(a) / ToolClass.getGTMaxDamage(a);
percentDamageOfB = (float) ToolClass.getGTitemDamage(b) / ToolClass.getGTMaxDamage(b);
}
return percentDamageOfA > mode.breakPoint == percentDamageOfB > mode.breakPoint;
@@ -20,9 +20,9 @@ package appeng.util.item;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.data.IAEItemStack;
import appeng.integration.modules.gregtech.ToolClass;
import appeng.util.Platform;
import com.google.common.base.Preconditions;
import gregtech.api.items.IToolItem;
import ic2.api.item.ICustomDamageItem;
import it.unimi.dsi.fastutil.objects.Object2ObjectAVLTreeMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectSortedMap;
@@ -154,8 +154,8 @@ class FuzzyItemVariantList extends ItemVariantList {
maxDamage = ((ICustomDamageItem) stack.getItem()).getMaxCustomDamage(stack);
damage = ((ICustomDamageItem) stack.getItem()).getCustomDamage(stack);
} else if (Platform.isGTDamageableItem(stack.getItem())) {
maxDamage = ((IToolItem) stack.getItem()).getMaxItemDamage(stack);
damage = ((IToolItem) stack.getItem()).getItemDamage(stack);
maxDamage = ToolClass.getGTMaxDamage(stack);
damage = ToolClass.getGTitemDamage(stack);
} else {
maxDamage = stack.getMaxDamage();
damage = stack.getItemDamage();
@@ -189,8 +189,8 @@ class FuzzyItemVariantList extends ItemVariantList {
maxDamage = ((ICustomDamageItem) stack.getItem()).getMaxCustomDamage(stack);
damage = ((ICustomDamageItem) stack.getItem()).getCustomDamage(stack);
} else if (Platform.isGTDamageableItem(stack.getItem())) {
maxDamage = ((IToolItem) stack.getItem()).getMaxItemDamage(stack);
damage = ((IToolItem) stack.getItem()).getItemDamage(stack);
maxDamage = ToolClass.getGTMaxDamage(stack);
damage = ToolClass.getGTitemDamage(stack);
} else {
maxDamage = stack.getMaxDamage();
damage = stack.getItemDamage();
@@ -1,6 +1,6 @@
{
"parent": "appliedenergistics2:part/p2p/p2p_tunnel_base",
"textures": {
"type": "blocks/redstone_block"
"type": "appliedenergistics2:blocks/redstone_p2p"
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 140 B