Utils ported
This commit is contained in:
@@ -78,6 +78,7 @@ allprojects {
|
||||
|
||||
dependencies {
|
||||
compile project(":api")
|
||||
compile project(":core")
|
||||
}
|
||||
|
||||
subprojects {
|
||||
|
||||
@@ -90,6 +90,7 @@ import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.RayTraceContext;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.*;
|
||||
@@ -1152,4 +1153,8 @@ public class Platform {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public static boolean canStack(ItemStack a, ItemStack b) {
|
||||
return itemComparisons().isSameItem(a, b);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -42,7 +42,7 @@ import appeng.util.Platform;
|
||||
|
||||
public class PaintSplotchesBlock extends AEBaseTileBlock<PaintSplotchesBlockEntity> {
|
||||
public PaintSplotchesBlock() {
|
||||
super(defaultProps(Material.WATER, MaterialColor.AIR));
|
||||
super(defaultProps(Material.WATER, MaterialColor.CLEAR));
|
||||
this.setFullSize(false);
|
||||
this.setOpaque(false);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import net.minecraft.block.BlockRenderType;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.block.MaterialColor;
|
||||
import net.minecraft.block.material.PushReaction;
|
||||
import net.minecraft.block.piston.PistonBehavior;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -46,8 +46,8 @@ import appeng.block.AEBaseBlock;
|
||||
*/
|
||||
public class MatrixFrameBlock extends AEBaseBlock {
|
||||
|
||||
private static final Material MATERIAL = new Material(MaterialColor.AIR, false, true, true, false, false, false,
|
||||
false, PushReaction.PUSH_ONLY);
|
||||
private static final Material MATERIAL = new Material(MaterialColor.CLEAR, false, true, true, false, false, false,
|
||||
false, PistonBehavior.PUSH_ONLY);
|
||||
|
||||
public MatrixFrameBlock() {
|
||||
super(Settings.create(MATERIAL).strength(-1.0F, 6000000.0F).notSolid().noDrops());
|
||||
|
||||
@@ -36,7 +36,7 @@ import net.minecraft.client.util.InputMappings;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||
|
||||
@@ -315,7 +315,7 @@ public class InterfaceTerminalScreen extends AEBaseScreen<InterfaceTerminalConta
|
||||
|
||||
// Potential later use to filter by input
|
||||
// ListNBT inTag = encodedValue.getTagList( "in", 10 );
|
||||
final ListNBT outTag = encodedValue.getList("out", 10);
|
||||
final ListTag outTag = encodedValue.getList("out", 10);
|
||||
|
||||
for (int i = 0; i < outTag.size(); i++) {
|
||||
|
||||
|
||||
@@ -405,7 +405,7 @@ public abstract class AEBaseContainer extends Container {
|
||||
final ItemStack t = d.getStack().copy();
|
||||
|
||||
if (Platform.itemComparisons().isSameItem(t, tis)) {
|
||||
int maxSize = t.getMaxStackSize();
|
||||
int maxSize = t.getMaxCount();
|
||||
if (maxSize > d.getSlotStackLimit()) {
|
||||
maxSize = d.getSlotStackLimit();
|
||||
}
|
||||
@@ -449,7 +449,7 @@ public abstract class AEBaseContainer extends Container {
|
||||
final ItemStack t = d.getStack().copy();
|
||||
|
||||
if (Platform.itemComparisons().isSameItem(t, tis)) {
|
||||
int maxSize = t.getMaxStackSize();
|
||||
int maxSize = t.getMaxCount();
|
||||
if (maxSize > d.getSlotStackLimit()) {
|
||||
maxSize = d.getSlotStackLimit();
|
||||
}
|
||||
@@ -478,7 +478,7 @@ public abstract class AEBaseContainer extends Container {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int maxSize = tis.getMaxStackSize();
|
||||
int maxSize = tis.getMaxCount();
|
||||
if (maxSize > d.getSlotStackLimit()) {
|
||||
maxSize = d.getSlotStackLimit();
|
||||
}
|
||||
@@ -580,7 +580,7 @@ public abstract class AEBaseContainer extends Container {
|
||||
if (hand.isEmpty()) {
|
||||
is.setCount(Math.max(1, is.getCount() - 1));
|
||||
} else if (hand.isItemEqual(is)) {
|
||||
is.setCount(Math.min(is.getMaxStackSize(), is.getCount() + 1));
|
||||
is.setCount(Math.min(is.getMaxCount(), is.getCount() + 1));
|
||||
} else {
|
||||
is = hand.copy();
|
||||
is.setCount(1);
|
||||
@@ -632,7 +632,7 @@ public abstract class AEBaseContainer extends Container {
|
||||
IAEItemStack ais = slotItem.copy();
|
||||
ItemStack myItem = ais.createItemStack();
|
||||
|
||||
ais.setStackSize(myItem.getMaxStackSize());
|
||||
ais.setStackSize(myItem.getMaxCount());
|
||||
|
||||
final InventoryAdaptor adp = InventoryAdaptor.getAdaptor(player);
|
||||
myItem.setCount((int) ais.getStackSize());
|
||||
@@ -691,7 +691,7 @@ public abstract class AEBaseContainer extends Container {
|
||||
final ItemStack item = player.inventory.getItemStack();
|
||||
|
||||
if (!item.isEmpty()) {
|
||||
if (item.getCount() >= item.getMaxStackSize()) {
|
||||
if (item.getCount() >= item.getMaxCount()) {
|
||||
liftQty = 0;
|
||||
}
|
||||
if (!Platform.itemComparisons().isSameItem(slotItem.getDefinition(), item)) {
|
||||
@@ -726,7 +726,7 @@ public abstract class AEBaseContainer extends Container {
|
||||
if (player.inventory.getItemStack().isEmpty()) {
|
||||
if (slotItem != null) {
|
||||
IAEItemStack ais = slotItem.copy();
|
||||
ais.setStackSize(ais.getDefinition().getMaxStackSize());
|
||||
ais.setStackSize(ais.getDefinition().getMaxCount());
|
||||
ais = Platform.poweredExtraction(this.getPowerSource(), this.getCellInventory(), ais,
|
||||
this.getActionSource());
|
||||
if (ais != null) {
|
||||
@@ -758,7 +758,7 @@ public abstract class AEBaseContainer extends Container {
|
||||
if (player.inventory.getItemStack().isEmpty()) {
|
||||
if (slotItem != null) {
|
||||
IAEItemStack ais = slotItem.copy();
|
||||
final long maxSize = ais.getDefinition().getMaxStackSize();
|
||||
final long maxSize = ais.getDefinition().getMaxCount();
|
||||
ais.setStackSize(maxSize);
|
||||
ais = this.getCellInventory().extractItems(ais, Actionable.SIMULATE, this.getActionSource());
|
||||
|
||||
@@ -796,7 +796,7 @@ public abstract class AEBaseContainer extends Container {
|
||||
case CREATIVE_DUPLICATE:
|
||||
if (player.abilities.isCreativeMode && slotItem != null) {
|
||||
final ItemStack is = slotItem.createItemStack();
|
||||
is.setCount(is.getMaxStackSize());
|
||||
is.setCount(is.getMaxCount());
|
||||
player.inventory.setItemStack(is);
|
||||
this.updateHeld(player);
|
||||
}
|
||||
@@ -813,7 +813,7 @@ public abstract class AEBaseContainer extends Container {
|
||||
IAEItemStack ais = slotItem.copy();
|
||||
ItemStack myItem = ais.createItemStack();
|
||||
|
||||
ais.setStackSize(myItem.getMaxStackSize());
|
||||
ais.setStackSize(myItem.getMaxCount());
|
||||
|
||||
final InventoryAdaptor adp = InventoryAdaptor.getAdaptor(player);
|
||||
myItem.setCount((int) ais.getStackSize());
|
||||
|
||||
@@ -37,7 +37,7 @@ import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.INBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.wrapper.PlayerInvWrapper;
|
||||
@@ -237,8 +237,8 @@ public class PatternTermContainer extends MEMonitorableContainer
|
||||
// encode the slot.
|
||||
final CompoundTag encodedValue = new CompoundTag();
|
||||
|
||||
final ListNBT tagIn = new ListNBT();
|
||||
final ListNBT tagOut = new ListNBT();
|
||||
final ListTag tagIn = new ListTag();
|
||||
final ListTag tagOut = new ListTag();
|
||||
|
||||
for (final ItemStack i : in) {
|
||||
tagIn.add(this.createItemTag(i));
|
||||
|
||||
@@ -127,12 +127,12 @@ public class AppEngSlot extends Slot {
|
||||
|
||||
@Override
|
||||
public int getSlotStackLimit() {
|
||||
return this.itemHandler.getSlotLimit(this.index);
|
||||
return this.itemHandler.getMaxAmount(this.index, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemStackLimit(@Nonnull ItemStack stack) {
|
||||
return Math.min(this.getSlotStackLimit(), stack.getMaxStackSize());
|
||||
return Math.min(this.getSlotStackLimit(), stack.getMaxCount());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -108,11 +108,11 @@ public class CraftingTermSlot extends AppEngCraftingSlot {
|
||||
if (action == InventoryAction.CRAFT_SHIFT) // craft into player inventory...
|
||||
{
|
||||
ia = InventoryAdaptor.getAdaptor(who);
|
||||
maxTimesToCraft = (int) Math.floor((double) this.getStack().getMaxStackSize() / (double) howManyPerCraft);
|
||||
maxTimesToCraft = (int) Math.floor((double) this.getStack().getMaxCount() / (double) howManyPerCraft);
|
||||
} else if (action == InventoryAction.CRAFT_STACK) // craft into hand, full stack
|
||||
{
|
||||
ia = new AdaptorFixedInv(new WrapperCursorItemHandler(who.inventory));
|
||||
maxTimesToCraft = (int) Math.floor((double) this.getStack().getMaxStackSize() / (double) howManyPerCraft);
|
||||
maxTimesToCraft = (int) Math.floor((double) this.getStack().getMaxCount() / (double) howManyPerCraft);
|
||||
} else
|
||||
// pick up what was crafted...
|
||||
{
|
||||
|
||||
@@ -26,7 +26,7 @@ import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
@@ -61,7 +61,7 @@ public class JEIRecipePacket extends BasePacket {
|
||||
if (comp != null) {
|
||||
this.recipe = new ItemStack[9][];
|
||||
for (int x = 0; x < this.recipe.length; x++) {
|
||||
final ListNBT list = comp.getList("#" + x, 10);
|
||||
final ListTag list = comp.getList("#" + x, 10);
|
||||
if (list.size() > 0) {
|
||||
this.recipe[x] = new ItemStack[list.size()];
|
||||
for (int y = 0; y < list.size(); y++) {
|
||||
|
||||
@@ -106,7 +106,7 @@ public class ItemGenBlockEntity extends AEBaseBlockEntity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit(int slot) {
|
||||
public int getMaxAmount(int slot, ItemStack stack) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ public class FluidCellConfig extends CellConfig {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(int slot, ItemStack stack) {
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
if (stack.isEmpty() || stack.getItem() instanceof FluidDummyItem) {
|
||||
super.isItemValid(slot, stack);
|
||||
}
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.block.material.MaterialColor;
|
||||
import net.minecraft.block.material.PushReaction;
|
||||
import net.minecraft.block.MaterialColor;
|
||||
import net.minecraft.block.piston.PistonBehavior;
|
||||
|
||||
public class AEGlassMaterial {
|
||||
|
||||
public static final Material INSTANCE = new Material(MaterialColor.AIR, false, false, true, false, true, false,
|
||||
false, PushReaction.NORMAL);
|
||||
public static final Material INSTANCE = new Material(MaterialColor.CLEAR, false, false, true, false, false,
|
||||
false, PistonBehavior.NORMAL);
|
||||
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -209,7 +209,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
this.craftingTracker.writeToNBT(data);
|
||||
data.putInt("priority", this.priority);
|
||||
|
||||
final ListNBT waitingToSend = new ListNBT();
|
||||
final ListTag waitingToSend = new ListTag();
|
||||
if (this.waitingToSend != null) {
|
||||
for (final ItemStack is : this.waitingToSend) {
|
||||
final CompoundTag item = new CompoundTag();
|
||||
@@ -222,7 +222,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
|
||||
public void readFromNBT(final CompoundTag data) {
|
||||
this.waitingToSend = null;
|
||||
final ListNBT waitingList = data.getList("waitingToSend", 10);
|
||||
final ListTag waitingList = data.getList("waitingToSend", 10);
|
||||
if (waitingList != null) {
|
||||
for (int x = 0; x < waitingList.size(); x++) {
|
||||
final CompoundTag c = waitingList.getCompound(x);
|
||||
@@ -311,7 +311,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
boolean found = false;
|
||||
|
||||
for (int x = 0; x < accountedFor.length; x++) {
|
||||
final ItemStack is = this.patterns.getStackInSlot(x);
|
||||
final ItemStack is = this.patterns.getInvStack(x);
|
||||
if (details.getPattern() == is) {
|
||||
accountedFor[x] = found = true;
|
||||
}
|
||||
@@ -325,7 +325,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
|
||||
for (int x = 0; x < accountedFor.length; x++) {
|
||||
if (!accountedFor[x]) {
|
||||
this.addToCraftingList(this.patterns.getStackInSlot(x));
|
||||
this.addToCraftingList(this.patterns.getInvStack(x));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,7 +357,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
req = null;
|
||||
}
|
||||
|
||||
final ItemStack stored = this.storage.getStackInSlot(slot);
|
||||
final ItemStack stored = this.storage.getInvStack(slot);
|
||||
|
||||
if (req == null && !stored.isEmpty()) {
|
||||
final IAEItemStack work = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
@@ -44,8 +44,8 @@ public class InvalidPatternHelper {
|
||||
throw new IllegalArgumentException("No pattern here!");
|
||||
}
|
||||
|
||||
final ListNBT inTag = encodedValue.getList("in", 10);
|
||||
final ListNBT outTag = encodedValue.getList("out", 10);
|
||||
final ListTag inTag = encodedValue.getList("in", 10);
|
||||
final ListTag outTag = encodedValue.getList("out", 10);
|
||||
this.isCrafting = encodedValue.getBoolean("crafting");
|
||||
|
||||
this.canSubstitute = this.isCrafting && encodedValue.getBoolean("substitute");
|
||||
|
||||
@@ -31,7 +31,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.ICraftingRecipe;
|
||||
import net.minecraft.recipe.RecipeType;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
@@ -67,8 +67,8 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
||||
throw new IllegalArgumentException("No pattern here!");
|
||||
}
|
||||
|
||||
final ListNBT inTag = encodedValue.getList("in", 10);
|
||||
final ListNBT outTag = encodedValue.getList("out", 10);
|
||||
final ListTag inTag = encodedValue.getList("in", 10);
|
||||
final ListTag outTag = encodedValue.getList("out", 10);
|
||||
this.isCrafting = encodedValue.getBoolean("crafting");
|
||||
|
||||
this.canSubstitute = this.isCrafting && encodedValue.getBoolean("substitute");
|
||||
|
||||
@@ -29,7 +29,7 @@ import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
|
||||
import mezz.jei.api.gui.IRecipeLayout;
|
||||
import mezz.jei.api.gui.ingredient.IGuiIngredient;
|
||||
@@ -78,7 +78,7 @@ class RecipeTransferHandler<T extends Container> implements IRecipeTransferHandl
|
||||
for (final Slot slot : container.inventorySlots) {
|
||||
if (slot instanceof CraftingMatrixSlot || slot instanceof FakeCraftingMatrixSlot) {
|
||||
if (slot.getSlotIndex() == slotIndex) {
|
||||
final ListNBT tags = new ListNBT();
|
||||
final ListTag tags = new ListTag();
|
||||
final List<ItemStack> list = new ArrayList<>();
|
||||
final ItemStack displayed = ingredient.getDisplayedIngredient();
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
@@ -990,7 +990,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU {
|
||||
data.put("link", link);
|
||||
}
|
||||
|
||||
final ListNBT list = new ListNBT();
|
||||
final ListTag list = new ListTag();
|
||||
for (final Entry<ICraftingPatternDetails, TaskProgress> e : this.tasks.entrySet()) {
|
||||
final CompoundTag item = this.writeItem(AEItemStack.fromItemStack(e.getKey().getPattern()));
|
||||
item.putLong("craftingProgress", e.getValue().value);
|
||||
@@ -1015,8 +1015,8 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU {
|
||||
return out;
|
||||
}
|
||||
|
||||
private ListNBT writeList(final IItemList<IAEItemStack> myList) {
|
||||
final ListNBT out = new ListNBT();
|
||||
private ListTag writeList(final IItemList<IAEItemStack> myList) {
|
||||
final ListTag out = new ListTag();
|
||||
|
||||
for (final IAEItemStack ais : myList) {
|
||||
out.add(this.writeItem(ais));
|
||||
@@ -1054,7 +1054,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU {
|
||||
this.submitLink(this.myLastLink);
|
||||
}
|
||||
|
||||
final ListNBT list = data.getList("tasks", 10);
|
||||
final ListTag list = data.getList("tasks", 10);
|
||||
for (int x = 0; x < list.size(); x++) {
|
||||
final CompoundTag item = list.getCompound(x);
|
||||
final IAEItemStack pattern = AEItemStack.fromNBT(item);
|
||||
@@ -1095,7 +1095,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU {
|
||||
}
|
||||
}
|
||||
|
||||
private IItemList<IAEItemStack> readList(final ListNBT tag) {
|
||||
private IItemList<IAEItemStack> readList(final ListTag tag) {
|
||||
final IItemList<IAEItemStack> out = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)
|
||||
.createList();
|
||||
|
||||
|
||||
@@ -335,7 +335,7 @@ public abstract class AEBasePart implements IPart, IGridProxyable, IActionHost,
|
||||
final AppEngInternalAEInventory tmp = new AppEngInternalAEInventory(null, target.getSlots());
|
||||
tmp.readFromNBT(compound, "config");
|
||||
for (int x = 0; x < tmp.getSlots(); x++) {
|
||||
target.setStackInSlot(x, tmp.getStackInSlot(x));
|
||||
target.setStackInSlot(x, tmp.getInvStack(x));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class CableBusStorage {
|
||||
|
||||
if (this.sides != null && this.sides.length > x && part == null) {
|
||||
this.sides[x] = null;
|
||||
this.sides = this.shrink(this.sides, true);
|
||||
this.sides = this.decrement(this.sides, true);
|
||||
} else if (part != null) {
|
||||
this.sides = this.expand(this.sides, x, true);
|
||||
this.sides[x] = part;
|
||||
@@ -112,7 +112,7 @@ public class CableBusStorage {
|
||||
public void setFacade(final int x, @Nullable final IFacadePart facade) {
|
||||
if (this.facades != null && this.facades.length > x && facade == null) {
|
||||
this.facades[x] = null;
|
||||
this.facades = this.shrink(this.facades, false);
|
||||
this.facades = this.decrement(this.facades, false);
|
||||
} else {
|
||||
this.facades = this.expand(this.facades, x, false);
|
||||
this.facades[x] = facade;
|
||||
|
||||
@@ -213,7 +213,7 @@ public class FormationPlanePart extends AbstractFormationPlanePart<IAEItemStack>
|
||||
final ItemStack is = input.createItemStack();
|
||||
final Item i = is.getItem();
|
||||
|
||||
long maxStorage = Math.min(input.getStackSize(), is.getMaxStackSize());
|
||||
long maxStorage = Math.min(input.getStackSize(), is.getMaxCount());
|
||||
boolean worked = false;
|
||||
|
||||
final BlockEntity te = this.getHost().getTile();
|
||||
|
||||
@@ -231,8 +231,8 @@ public class ItemP2PTunnelPart extends P2PTunnelPart<ItemP2PTunnelPart> implemen
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit(int slot) {
|
||||
return this.getDestination().getSlotLimit(slot);
|
||||
public int getMaxAmount(int slot, ItemStack is) {
|
||||
return this.getDestination().getMaxAmount(slot, is);
|
||||
}
|
||||
|
||||
public float getPowerDrainPerTick() {
|
||||
|
||||
@@ -121,7 +121,7 @@ public class ConversionMonitorPart extends AbstractMonitorPart {
|
||||
}
|
||||
|
||||
if (this.getDisplayed() != null) {
|
||||
this.extractItem(player, this.getDisplayed().getDefinition().getMaxStackSize());
|
||||
this.extractItem(player, this.getDisplayed().getDefinition().getMaxCount());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -106,7 +106,7 @@ public class PatternTerminalPart extends AbstractTerminalPart {
|
||||
public void onChangeInventory(final FixedItemInv 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);
|
||||
final ItemStack is = this.pattern.getInvStack(1);
|
||||
if (!is.isEmpty() && is.getItem() instanceof ICraftingPatternItem) {
|
||||
final ICraftingPatternItem pattern = (ICraftingPatternItem) is.getItem();
|
||||
final ICraftingPatternDetails details = pattern.getPatternForItem(is,
|
||||
@@ -136,7 +136,7 @@ public class PatternTerminalPart extends AbstractTerminalPart {
|
||||
private void fixCraftingRecipes() {
|
||||
if (this.craftingMode) {
|
||||
for (int x = 0; x < this.crafting.getSlots(); x++) {
|
||||
final ItemStack is = this.crafting.getStackInSlot(x);
|
||||
final ItemStack is = this.crafting.getInvStack(x);
|
||||
if (!is.isEmpty()) {
|
||||
is.setCount(1);
|
||||
}
|
||||
|
||||
@@ -280,7 +280,7 @@ public class CraftingBlockEntity extends AENetworkBlockEntity implements IAEMult
|
||||
for (IAEItemStack ais : inv.getAvailableItems(
|
||||
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList())) {
|
||||
ais = ais.copy();
|
||||
ais.setStackSize(ais.getDefinition().getMaxStackSize());
|
||||
ais.setStackSize(ais.getDefinition().getMaxCount());
|
||||
while (true) {
|
||||
final IAEItemStack g = inv.extractItems(ais.copy(), Actionable.MODULATE,
|
||||
this.cluster.getActionSource());
|
||||
|
||||
@@ -160,7 +160,7 @@ public class MolecularAssemblerBlockEntity extends AENetworkInvBlockEntity
|
||||
}
|
||||
|
||||
private boolean canPush() {
|
||||
return !this.gridInv.getStackInSlot(9).isEmpty();
|
||||
return !this.gridInv.getInvStack(9).isEmpty();
|
||||
}
|
||||
|
||||
private boolean hasMats() {
|
||||
@@ -169,7 +169,7 @@ public class MolecularAssemblerBlockEntity extends AENetworkInvBlockEntity
|
||||
}
|
||||
|
||||
for (int x = 0; x < this.craftingInv.size(); x++) {
|
||||
this.craftingInv.setStack(x, this.gridInv.getStackInSlot(x));
|
||||
this.craftingInv.setStack(x, this.gridInv.getInvStack(x));
|
||||
}
|
||||
|
||||
return !this.myPlan.getOutput(this.craftingInv, this.getWorld()).isEmpty();
|
||||
@@ -247,7 +247,7 @@ public class MolecularAssemblerBlockEntity extends AENetworkInvBlockEntity
|
||||
return;
|
||||
}
|
||||
|
||||
final ItemStack is = this.patternInv.getStackInSlot(0);
|
||||
final ItemStack is = this.patternInv.getInvStack(0);
|
||||
|
||||
if (!is.isEmpty() && is.getItem() instanceof EncodedPatternItem) {
|
||||
if (!ItemStack.areItemsEqual(is, this.myPattern)) {
|
||||
@@ -332,7 +332,7 @@ public class MolecularAssemblerBlockEntity extends AENetworkInvBlockEntity
|
||||
super.getDrops(w, pos, drops);
|
||||
|
||||
for (int h = 0; h < this.upgrades.getSlots(); h++) {
|
||||
final ItemStack is = this.upgrades.getStackInSlot(h);
|
||||
final ItemStack is = this.upgrades.getInvStack(h);
|
||||
if (!is.isEmpty()) {
|
||||
drops.add(is);
|
||||
}
|
||||
@@ -348,11 +348,11 @@ public class MolecularAssemblerBlockEntity extends AENetworkInvBlockEntity
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(final IGridNode node, int ticksSinceLastCall) {
|
||||
if (!this.gridInv.getStackInSlot(9).isEmpty()) {
|
||||
this.pushOut(this.gridInv.getStackInSlot(9));
|
||||
if (!this.gridInv.getInvStack(9).isEmpty()) {
|
||||
this.pushOut(this.gridInv.getInvStack(9));
|
||||
|
||||
// did it eject?
|
||||
if (this.gridInv.getStackInSlot(9).isEmpty()) {
|
||||
if (this.gridInv.getInvStack(9).isEmpty()) {
|
||||
this.saveChanges();
|
||||
}
|
||||
|
||||
@@ -400,7 +400,7 @@ public class MolecularAssemblerBlockEntity extends AENetworkInvBlockEntity
|
||||
|
||||
if (this.progress >= 100) {
|
||||
for (int x = 0; x < this.craftingInv.size(); x++) {
|
||||
this.craftingInv.setStack(x, this.gridInv.getStackInSlot(x));
|
||||
this.craftingInv.setStack(x, this.gridInv.getInvStack(x));
|
||||
}
|
||||
|
||||
this.progress = 0;
|
||||
@@ -441,9 +441,9 @@ public class MolecularAssemblerBlockEntity extends AENetworkInvBlockEntity
|
||||
}
|
||||
|
||||
private void ejectHeldItems() {
|
||||
if (this.gridInv.getStackInSlot(9).isEmpty()) {
|
||||
if (this.gridInv.getInvStack(9).isEmpty()) {
|
||||
for (int x = 0; x < 9; x++) {
|
||||
final ItemStack is = this.gridInv.getStackInSlot(x);
|
||||
final ItemStack is = this.gridInv.getInvStack(x);
|
||||
if (!is.isEmpty()) {
|
||||
if (this.myPlan == null || !this.myPlan.isValidItemForSlot(x, is, this.world)) {
|
||||
this.gridInv.setStackInSlot(9, is);
|
||||
|
||||
@@ -81,10 +81,10 @@ public class GrinderBlockEntity extends AEBaseInvBlockEntity implements ICrankab
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.inv.getStackInSlot(6).isEmpty()) // Add if there isn't one...
|
||||
if (this.inv.getInvStack(6).isEmpty()) // Add if there isn't one...
|
||||
{
|
||||
for (int x = 0; x < 3; x++) {
|
||||
ItemStack item = this.inv.getStackInSlot(x);
|
||||
ItemStack item = this.inv.getInvStack(x);
|
||||
if (item.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
@@ -93,7 +93,7 @@ public class GrinderBlockEntity extends AEBaseInvBlockEntity implements ICrankab
|
||||
if (r != null) {
|
||||
final ItemStack ais = item.copy();
|
||||
ais.setCount(r.getIngredientCount());
|
||||
item.shrink(r.getIngredientCount());
|
||||
item.decrement(r.getIngredientCount());
|
||||
|
||||
if (item.getCount() <= 0) {
|
||||
item = ItemStack.EMPTY;
|
||||
@@ -117,7 +117,7 @@ public class GrinderBlockEntity extends AEBaseInvBlockEntity implements ICrankab
|
||||
|
||||
this.points++;
|
||||
|
||||
final ItemStack processing = this.inv.getStackInSlot(SLOT_PROCESSING);
|
||||
final ItemStack processing = this.inv.getInvStack(SLOT_PROCESSING);
|
||||
GrinderRecipe r = GrinderRecipes.findForInput(world, processing);
|
||||
if (r != null) {
|
||||
if (r.getTurns() > this.points) {
|
||||
|
||||
@@ -1,84 +1,42 @@
|
||||
|
||||
package appeng.tile.inventory;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
import alexiil.mc.lib.attributes.Simulation;
|
||||
import alexiil.mc.lib.attributes.item.impl.DelegatingFixedItemInv;
|
||||
import appeng.api.storage.cells.ICellInventory;
|
||||
import appeng.api.storage.cells.ICellInventoryHandler;
|
||||
import appeng.util.inv.IAEAppEngInventory;
|
||||
import appeng.util.inv.filter.IAEItemFilter;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class AppEngCellInventory implements IItemHandlerModifiable {
|
||||
private final AppEngInternalInventory inv;
|
||||
private final ICellInventoryHandler handlerForSlot[];
|
||||
public class AppEngCellInventory extends DelegatingFixedItemInv {
|
||||
private final ICellInventoryHandler<?>[] handlerForSlot;
|
||||
|
||||
public AppEngCellInventory(final IAEAppEngInventory host, final int slots) {
|
||||
this.inv = new AppEngInternalInventory(host, slots, 1);
|
||||
super(new AppEngInternalInventory(host, slots, 1));
|
||||
this.handlerForSlot = new ICellInventoryHandler[slots];
|
||||
}
|
||||
|
||||
public void setHandler(final int slot, final ICellInventoryHandler handler) {
|
||||
public void setHandler(final int slot, final ICellInventoryHandler<?> handler) {
|
||||
this.handlerForSlot[slot] = handler;
|
||||
}
|
||||
|
||||
public void setFilter(IAEItemFilter filter) {
|
||||
this.inv.setFilter(filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackInSlot(int slot, ItemStack stack) {
|
||||
public boolean setInvStack(int slot, ItemStack to, Simulation simulation) {
|
||||
this.persist(slot);
|
||||
this.inv.setStackInSlot(slot, stack);
|
||||
boolean result = super.setInvStack(slot, to, simulation);
|
||||
this.cleanup(slot);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots() {
|
||||
return this.inv.getSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
public ItemStack getInvStack(int slot) {
|
||||
this.persist(slot);
|
||||
return this.inv.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
|
||||
this.persist(slot);
|
||||
final ItemStack ret = this.inv.insertItem(slot, stack, simulate);
|
||||
this.cleanup(slot);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
this.persist(slot);
|
||||
final ItemStack ret = this.inv.extractItem(slot, amount, simulate);
|
||||
this.cleanup(slot);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit(int slot) {
|
||||
return this.inv.getSlotLimit(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(int slot, ItemStack stack) {
|
||||
return this.inv.isItemValid(slot, stack);
|
||||
}
|
||||
|
||||
public void persist() {
|
||||
for (int i = 0; i < this.getSlots(); ++i) {
|
||||
this.persist(i);
|
||||
}
|
||||
return super.getInvStack(slot);
|
||||
}
|
||||
|
||||
private void persist(int slot) {
|
||||
if (this.handlerForSlot[slot] != null) {
|
||||
final ICellInventory ci = this.handlerForSlot[slot].getCellInv();
|
||||
final ICellInventory<?> ci = this.handlerForSlot[slot].getCellInv();
|
||||
if (ci != null) {
|
||||
ci.persist();
|
||||
}
|
||||
@@ -87,9 +45,9 @@ public class AppEngCellInventory implements IItemHandlerModifiable {
|
||||
|
||||
private void cleanup(int slot) {
|
||||
if (this.handlerForSlot[slot] != null) {
|
||||
final ICellInventory ci = this.handlerForSlot[slot].getCellInv();
|
||||
final ICellInventory<?> ci = this.handlerForSlot[slot].getCellInv();
|
||||
|
||||
if (ci == null || ci.getItemStack() != this.inv.getStackInSlot(slot)) {
|
||||
if (ci == null || ci.getItemStack() != super.getInvStack(slot)) {
|
||||
this.handlerForSlot[slot] = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,15 @@ package appeng.tile.inventory;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import alexiil.mc.lib.attributes.ListenerRemovalToken;
|
||||
import alexiil.mc.lib.attributes.ListenerToken;
|
||||
import alexiil.mc.lib.attributes.Simulation;
|
||||
import alexiil.mc.lib.attributes.item.FixedItemInv;
|
||||
import alexiil.mc.lib.attributes.item.InvMarkDirtyListener;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
@@ -35,10 +39,9 @@ import appeng.util.Platform;
|
||||
import appeng.util.inv.IAEAppEngInventory;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import appeng.util.iterators.AEInvIterator;
|
||||
import appeng.util.iterators.InvIterator;
|
||||
|
||||
public class AppEngInternalAEInventory implements IItemHandlerModifiable, Iterable<ItemStack> {
|
||||
public class AppEngInternalAEInventory implements FixedItemInv, Iterable<ItemStack> {
|
||||
private final IAEAppEngInventory te;
|
||||
private final IAEItemStack[] inv;
|
||||
private final int size;
|
||||
@@ -103,105 +106,74 @@ public class AppEngInternalAEInventory implements IItemHandlerModifiable, Iterab
|
||||
}
|
||||
|
||||
protected int getStackLimit(int slot, @Nonnull ItemStack stack) {
|
||||
return Math.min(this.getSlotLimit(slot), stack.getMaxStackSize());
|
||||
return Math.min(this.getMaxAmount(slot, stack), stack.getMaxCount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots() {
|
||||
public ItemStack getInvStack(int slot) {
|
||||
if (this.inv[slot] == null) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
return this.inv[slot].createItemStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setInvStack(int slot, ItemStack to, Simulation simulation) {
|
||||
if (this.te == null || !Platform.isServer()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// FIXME: We need to implement the actual checks here, stacking /caninsert/canremove
|
||||
if (true) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
if (simulation == Simulation.SIMULATE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ItemStack oldStack = this.getInvStack(slot).copy();
|
||||
this.inv[slot] = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)
|
||||
.createStack(to);
|
||||
|
||||
ItemStack newStack = to.copy();
|
||||
InvOperation op = InvOperation.SET;
|
||||
|
||||
if (ItemStack.areItemsEqual(oldStack, newStack)) {
|
||||
if (newStack.getCount() > oldStack.getCount()) {
|
||||
newStack.decrement(oldStack.getCount());
|
||||
oldStack = ItemStack.EMPTY;
|
||||
op = InvOperation.INSERT;
|
||||
} else {
|
||||
oldStack.decrement(newStack.getCount());
|
||||
newStack = ItemStack.EMPTY;
|
||||
op = InvOperation.EXTRACT;
|
||||
}
|
||||
}
|
||||
this.fireOnChangeInventory(slot, op, oldStack, newStack);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotCount() {
|
||||
return this.size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(final int var1) {
|
||||
if (this.inv[var1] == null) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
return this.inv[var1].createItemStack();
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
|
||||
if (stack.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
ItemStack existing = this.getStackInSlot(slot);
|
||||
int limit = this.getStackLimit(slot, stack);
|
||||
|
||||
if (!existing.isEmpty()) {
|
||||
if (!ItemHandlerHelper.canItemStacksStack(stack, existing)) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
limit -= existing.getCount();
|
||||
}
|
||||
|
||||
if (limit <= 0) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
boolean reachedLimit = stack.getCount() > limit;
|
||||
|
||||
if (!simulate) {
|
||||
if (existing.isEmpty()) {
|
||||
this.inv[slot] = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)
|
||||
.createStack(reachedLimit ? Platform.copyStackWithSize(stack, limit) : stack);
|
||||
} else {
|
||||
existing.increment(reachedLimit ? limit : stack.getCount());
|
||||
}
|
||||
this.fireOnChangeInventory(slot, InvOperation.INSERT, ItemStack.EMPTY,
|
||||
reachedLimit ? Platform.copyStackWithSize(stack, limit) : stack);
|
||||
}
|
||||
return reachedLimit ? Platform.copyStackWithSize(stack, stack.getCount() - limit) : ItemStack.EMPTY;
|
||||
public int getChangeValue() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
if (this.inv[slot] != null) {
|
||||
final ItemStack split = this.getStackInSlot(slot);
|
||||
|
||||
if (amount >= split.getCount()) {
|
||||
if (!simulate) {
|
||||
this.inv[slot] = null;
|
||||
this.fireOnChangeInventory(slot, InvOperation.EXTRACT, split, ItemStack.EMPTY);
|
||||
}
|
||||
return split;
|
||||
} else {
|
||||
if (!simulate) {
|
||||
split.increment(-amount);
|
||||
this.fireOnChangeInventory(slot, InvOperation.EXTRACT,
|
||||
Platform.copyStackWithSize(split, amount), ItemStack.EMPTY);
|
||||
}
|
||||
return Platform.copyStackWithSize(split, amount);
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackInSlot(final int slot, final ItemStack newItemStack) {
|
||||
ItemStack oldStack = this.getStackInSlot(slot).copy();
|
||||
this.inv[slot] = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)
|
||||
.createStack(newItemStack);
|
||||
|
||||
if (this.te != null && Platform.isServer()) {
|
||||
ItemStack newStack = newItemStack.copy();
|
||||
InvOperation op = InvOperation.SET;
|
||||
|
||||
if (ItemStack.areItemsEqual(oldStack, newStack)) {
|
||||
if (newStack.getCount() > oldStack.getCount()) {
|
||||
newStack.shrink(oldStack.getCount());
|
||||
oldStack = ItemStack.EMPTY;
|
||||
op = InvOperation.INSERT;
|
||||
} else {
|
||||
oldStack.shrink(newStack.getCount());
|
||||
newStack = ItemStack.EMPTY;
|
||||
op = InvOperation.EXTRACT;
|
||||
}
|
||||
}
|
||||
this.fireOnChangeInventory(slot, op, oldStack, newStack);
|
||||
}
|
||||
public ListenerToken addListener(InvMarkDirtyListener listener, ListenerRemovalToken removalToken) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private void fireOnChangeInventory(int slot, InvOperation op, ItemStack removed, ItemStack inserted) {
|
||||
@@ -214,8 +186,8 @@ public class AppEngInternalAEInventory implements IItemHandlerModifiable, Iterab
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit(int slot) {
|
||||
return this.maxStack > 64 ? 64 : this.maxStack;
|
||||
public int getMaxAmount(int slot, ItemStack is) {
|
||||
return Math.min(this.maxStack, 64);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -223,12 +195,4 @@ public class AppEngInternalAEInventory implements IItemHandlerModifiable, Iterab
|
||||
return new InvIterator(this);
|
||||
}
|
||||
|
||||
public Iterator<IAEItemStack> getNewAEIterator() {
|
||||
return new AEInvIterator(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(int slot, ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,26 +18,28 @@
|
||||
|
||||
package appeng.tile.inventory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
import alexiil.mc.lib.attributes.Simulation;
|
||||
import alexiil.mc.lib.attributes.item.FixedItemInvView;
|
||||
import alexiil.mc.lib.attributes.item.filter.ConstantItemFilter;
|
||||
import alexiil.mc.lib.attributes.item.filter.ItemFilter;
|
||||
import alexiil.mc.lib.attributes.item.impl.FullFixedItemInv;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.IAEAppEngInventory;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import appeng.util.inv.filter.IAEItemFilter;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class AppEngInternalInventory extends ItemStackHandler implements Iterable<ItemStack> {
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
// FIXME: the filtering is not correctly implemented and need to be reworked
|
||||
public class AppEngInternalInventory extends FullFixedItemInv implements Iterable<ItemStack> {
|
||||
private boolean enableClientEvents = false;
|
||||
private IAEAppEngInventory te;
|
||||
private final int[] maxStack;
|
||||
private ItemStack previousStack = ItemStack.EMPTY;
|
||||
private IAEItemFilter filter;
|
||||
private boolean dirtyFlag = false;
|
||||
|
||||
@@ -48,6 +50,8 @@ public class AppEngInternalInventory extends ItemStackHandler implements Iterabl
|
||||
this.setFilter(filter);
|
||||
this.maxStack = new int[size];
|
||||
Arrays.fill(this.maxStack, maxStack);
|
||||
|
||||
setOwnerListener(this::onContentsChanged);
|
||||
}
|
||||
|
||||
public AppEngInternalInventory(final IAEAppEngInventory inventory, final int size, final int maxStack) {
|
||||
@@ -63,57 +67,24 @@ public class AppEngInternalInventory extends ItemStackHandler implements Iterabl
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit(int slot) {
|
||||
return this.maxStack[slot];
|
||||
public int getMaxAmount(int slot, ItemStack stack) {
|
||||
return Math.min(maxStack[slot], super.getMaxAmount(slot, stack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackInSlot(int slot, @Nonnull ItemStack stack) {
|
||||
this.previousStack = this.getStackInSlot(slot).copy();
|
||||
super.setStackInSlot(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
|
||||
if (this.filter != null && !this.filter.allowInsert(this, slot, stack)) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
if (!simulate) {
|
||||
this.previousStack = this.getStackInSlot(slot).copy();
|
||||
}
|
||||
return super.insertItem(slot, stack, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
if (this.filter != null && !this.filter.allowExtract(this, slot, amount)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if (!simulate) {
|
||||
this.previousStack = this.getStackInSlot(slot).copy();
|
||||
}
|
||||
return super.extractItem(slot, amount, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onContentsChanged(int slot) {
|
||||
protected void onContentsChanged(FixedItemInvView inv, int slot, ItemStack previous, ItemStack current) {
|
||||
if (this.getBlockEntity() != null && this.eventsEnabled() && !this.dirtyFlag) {
|
||||
this.dirtyFlag = true;
|
||||
ItemStack newStack = this.getStackInSlot(slot).copy();
|
||||
ItemStack oldStack = this.previousStack;
|
||||
ItemStack newStack = current.copy();
|
||||
ItemStack oldStack = previous;
|
||||
InvOperation op = InvOperation.SET;
|
||||
|
||||
if (newStack.isEmpty() || oldStack.isEmpty() || ItemStack.areItemsEqual(newStack, oldStack)) {
|
||||
if (newStack.getCount() > oldStack.getCount()) {
|
||||
newStack.shrink(oldStack.getCount());
|
||||
newStack.decrement(oldStack.getCount());
|
||||
oldStack = ItemStack.EMPTY;
|
||||
op = InvOperation.INSERT;
|
||||
} else {
|
||||
oldStack.shrink(newStack.getCount());
|
||||
oldStack.decrement(newStack.getCount());
|
||||
newStack = ItemStack.EMPTY;
|
||||
op = InvOperation.EXTRACT;
|
||||
}
|
||||
@@ -121,10 +92,8 @@ public class AppEngInternalInventory extends ItemStackHandler implements Iterabl
|
||||
|
||||
this.getBlockEntity().onChangeInventory(this, slot, op, oldStack, newStack);
|
||||
this.getBlockEntity().saveChanges();
|
||||
this.previousStack = ItemStack.EMPTY;
|
||||
this.dirtyFlag = false;
|
||||
}
|
||||
super.onContentsChanged(slot);
|
||||
}
|
||||
|
||||
protected boolean eventsEnabled() {
|
||||
@@ -136,7 +105,25 @@ public class AppEngInternalInventory extends ItemStackHandler implements Iterabl
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(int slot, ItemStack stack) {
|
||||
public ItemFilter getFilterForSlot(int slot) {
|
||||
if (this.maxStack[slot] == 0) {
|
||||
return ConstantItemFilter.NOTHING;
|
||||
}
|
||||
if (this.filter != null) {
|
||||
return stack -> {
|
||||
// FIXME: This is not correct...
|
||||
if (stack == ItemStack.EMPTY) {
|
||||
return filter.allowExtract(this, slot, this.getSlot(slot).get().getCount());
|
||||
} else {
|
||||
return filter.allowExtract(this, slot, this.getSlot(slot).get().getCount());
|
||||
}
|
||||
};
|
||||
}
|
||||
return ConstantItemFilter.ANYTHING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
if (this.maxStack[slot] == 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -147,7 +134,7 @@ public class AppEngInternalInventory extends ItemStackHandler implements Iterabl
|
||||
}
|
||||
|
||||
public void writeToNBT(final CompoundTag data, final String name) {
|
||||
data.put(name, this.serializeNBT());
|
||||
data.put(name, this.toTag());
|
||||
}
|
||||
|
||||
public void readFromNBT(final CompoundTag data, final String name) {
|
||||
@@ -158,12 +145,12 @@ public class AppEngInternalInventory extends ItemStackHandler implements Iterabl
|
||||
}
|
||||
|
||||
public void readFromNBT(final CompoundTag data) {
|
||||
this.deserializeNBT(data);
|
||||
this.fromTag(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemStack> iterator() {
|
||||
return Collections.unmodifiableList(super.stacks).iterator();
|
||||
return stackIterable().iterator();
|
||||
}
|
||||
|
||||
private boolean isEnableClientEvents() {
|
||||
|
||||
@@ -67,7 +67,7 @@ public class CellWorkbenchBlockEntity extends AEBaseBlockEntity
|
||||
return null;
|
||||
}
|
||||
|
||||
final ItemStack is = this.cell.getStackInSlot(0);
|
||||
final ItemStack is = this.cell.getInvStack(0);
|
||||
if (is.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
@@ -83,12 +83,12 @@ public class CellWorkbenchBlockEntity extends AEBaseBlockEntity
|
||||
}
|
||||
|
||||
public ICellWorkbenchItem getCell() {
|
||||
if (this.cell.getStackInSlot(0).isEmpty()) {
|
||||
if (this.cell.getInvStack(0).isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (this.cell.getStackInSlot(0).getItem() instanceof ICellWorkbenchItem) {
|
||||
return ((ICellWorkbenchItem) this.cell.getStackInSlot(0).getItem());
|
||||
if (this.cell.getInvStack(0).getItem() instanceof ICellWorkbenchItem) {
|
||||
return ((ICellWorkbenchItem) this.cell.getInvStack(0).getItem());
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -183,7 +183,7 @@ public class CellWorkbenchBlockEntity extends AEBaseBlockEntity
|
||||
return null;
|
||||
}
|
||||
|
||||
final ItemStack is = this.cell.getStackInSlot(0);
|
||||
final ItemStack is = this.cell.getInvStack(0);
|
||||
if (is.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
@@ -202,8 +202,8 @@ public class CellWorkbenchBlockEntity extends AEBaseBlockEntity
|
||||
public void getDrops(final World w, final BlockPos pos, final List<ItemStack> drops) {
|
||||
super.getDrops(w, pos, drops);
|
||||
|
||||
if (this.cell.getStackInSlot(0) != null) {
|
||||
drops.add(this.cell.getStackInSlot(0));
|
||||
if (this.cell.getInvStack(0) != null) {
|
||||
drops.add(this.cell.getInvStack(0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ public class ChargerBlockEntity extends AENetworkPowerBlockEntity implements ICr
|
||||
@Override
|
||||
protected void writeToStream(final PacketByteBuf data) throws IOException {
|
||||
super.writeToStream(data);
|
||||
final AEItemStack is = AEItemStack.fromItemStack(this.inv.getStackInSlot(0));
|
||||
final AEItemStack is = AEItemStack.fromItemStack(this.inv.getInvStack(0));
|
||||
if (is != null) {
|
||||
is.writeToPacket(data);
|
||||
}
|
||||
@@ -113,7 +113,7 @@ public class ChargerBlockEntity extends AENetworkPowerBlockEntity implements ICr
|
||||
public void applyTurn() {
|
||||
this.injectExternalPower(PowerUnits.AE, POWER_PER_CRANK_TURN, Actionable.MODULATE);
|
||||
|
||||
final ItemStack myItem = this.inv.getStackInSlot(0);
|
||||
final ItemStack myItem = this.inv.getInvStack(0);
|
||||
if (this.getInternalCurrentPower() > POWER_THRESHOLD) {
|
||||
final IMaterials materials = AEApi.instance().definitions().materials();
|
||||
|
||||
@@ -153,7 +153,7 @@ public class ChargerBlockEntity extends AENetworkPowerBlockEntity implements ICr
|
||||
return;
|
||||
}
|
||||
|
||||
final ItemStack myItem = this.inv.getStackInSlot(0);
|
||||
final ItemStack myItem = this.inv.getInvStack(0);
|
||||
if (myItem.isEmpty()) {
|
||||
ItemStack held = player.inventory.getCurrentItem();
|
||||
|
||||
@@ -181,7 +181,7 @@ public class ChargerBlockEntity extends AENetworkPowerBlockEntity implements ICr
|
||||
}
|
||||
|
||||
private boolean doWork() {
|
||||
final ItemStack myItem = this.inv.getStackInSlot(0);
|
||||
final ItemStack myItem = this.inv.getInvStack(0);
|
||||
boolean changed = false;
|
||||
|
||||
if (!myItem.isEmpty()) {
|
||||
|
||||
@@ -102,7 +102,7 @@ public class CondenserBlockEntity extends AEBaseInvBlockEntity implements IConfi
|
||||
}
|
||||
|
||||
public double getStorage() {
|
||||
final ItemStack is = this.storageSlot.getStackInSlot(0);
|
||||
final ItemStack is = this.storageSlot.getInvStack(0);
|
||||
if (!is.isEmpty()) {
|
||||
if (is.getItem() instanceof IStorageComponent) {
|
||||
final IStorageComponent sc = (IStorageComponent) is.getItem();
|
||||
@@ -247,7 +247,7 @@ public class CondenserBlockEntity extends AEBaseInvBlockEntity implements IConfi
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit(int slot) {
|
||||
public int getMaxAmount(int slot, ItemStack is) {
|
||||
return 64;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ public class InscriberBlockEntity extends AENetworkPowerBlockEntity
|
||||
super.getDrops(w, pos, drops);
|
||||
|
||||
for (int h = 0; h < this.upgrades.getSlots(); h++) {
|
||||
final ItemStack is = this.upgrades.getStackInSlot(h);
|
||||
final ItemStack is = this.upgrades.getInvStack(h);
|
||||
if (!is.isEmpty()) {
|
||||
drops.add(is);
|
||||
}
|
||||
@@ -249,9 +249,9 @@ public class InscriberBlockEntity extends AENetworkPowerBlockEntity
|
||||
@Nullable
|
||||
public InscriberRecipe getTask() {
|
||||
if (this.cachedTask == null && world != null) {
|
||||
ItemStack input = this.sideItemHandler.getStackInSlot(0);
|
||||
ItemStack plateA = this.topItemHandler.getStackInSlot(0);
|
||||
ItemStack plateB = this.bottomItemHandler.getStackInSlot(0);
|
||||
ItemStack input = this.sideItemHandler.getInvStack(0);
|
||||
ItemStack plateA = this.topItemHandler.getInvStack(0);
|
||||
ItemStack plateB = this.bottomItemHandler.getInvStack(0);
|
||||
if (input.isEmpty()) {
|
||||
return null; // No input to handle
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public class SecurityStationBlockEntity extends AENetworkBlockEntity implements
|
||||
@Override
|
||||
public void getDrops(final World w, final BlockPos pos, final List<ItemStack> drops) {
|
||||
if (!ItemHandlerUtil.isEmpty(this.getConfigSlot())) {
|
||||
drops.add(this.getConfigSlot().getStackInSlot(0));
|
||||
drops.add(this.getConfigSlot().getInvStack(0));
|
||||
}
|
||||
|
||||
for (final IAEItemStack ais : this.inventory.getStoredItems()) {
|
||||
|
||||
@@ -134,7 +134,7 @@ public class VibrationChamberBlockEntity extends AENetworkInvBlockEntity impleme
|
||||
}
|
||||
|
||||
private boolean canEatFuel() {
|
||||
final ItemStack is = this.inv.getStackInSlot(0);
|
||||
final ItemStack is = this.inv.getInvStack(0);
|
||||
if (!is.isEmpty()) {
|
||||
final int newBurnTime = ForgeHooks.getBurnTime(is);
|
||||
if (newBurnTime > 0 && is.getCount() > 0) {
|
||||
@@ -206,7 +206,7 @@ public class VibrationChamberBlockEntity extends AENetworkInvBlockEntity impleme
|
||||
}
|
||||
|
||||
private void eatFuel() {
|
||||
final ItemStack is = this.inv.getStackInSlot(0);
|
||||
final ItemStack is = this.inv.getInvStack(0);
|
||||
if (!is.isEmpty()) {
|
||||
final int newBurnTime = ForgeHooks.getBurnTime(is);
|
||||
if (newBurnTime > 0 && is.getCount() > 0) {
|
||||
@@ -214,7 +214,7 @@ public class VibrationChamberBlockEntity extends AENetworkInvBlockEntity impleme
|
||||
this.setMaxBurnTime(this.getBurnTime());
|
||||
|
||||
final Item fuelItem = is.getItem();
|
||||
is.shrink(1);
|
||||
is.decrement(1);
|
||||
|
||||
if (is.isEmpty()) {
|
||||
this.inv.setStackInSlot(0, fuelItem.getRecipeRemainder(is));
|
||||
|
||||
@@ -138,7 +138,7 @@ public class WirelessBlockEntity extends AENetworkInvBlockEntity implements IWir
|
||||
}
|
||||
|
||||
private int getBoosters() {
|
||||
final ItemStack boosters = this.inv.getStackInSlot(0);
|
||||
final ItemStack boosters = this.inv.getInvStack(0);
|
||||
return boosters == null ? 0 : boosters.getCount();
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ public class QuantumBridgeBlockEntity extends AENetworkInvBlockEntity implements
|
||||
super.writeToStream(data);
|
||||
int out = this.constructed;
|
||||
|
||||
if (!this.internalInventory.getStackInSlot(0).isEmpty() && this.constructed != -1) {
|
||||
if (!this.internalInventory.getInvStack(0).isEmpty() && this.constructed != -1) {
|
||||
out |= this.hasSingularity;
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ public class QuantumBridgeBlockEntity extends AENetworkInvBlockEntity implements
|
||||
}
|
||||
|
||||
public long getQEFrequency() {
|
||||
final ItemStack is = this.internalInventory.getStackInSlot(0);
|
||||
final ItemStack is = this.internalInventory.getInvStack(0);
|
||||
if (!is.isEmpty()) {
|
||||
final CompoundTag c = is.getTag();
|
||||
if (c != null) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user