ForgePatch/src/main/java/net/minecraftforge/items/ItemStackHandler.java

227 lines
5.9 KiB
Java
Raw Normal View History

/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library 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 version 2.1
* of the License.
*
* This library 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 this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
package net.minecraftforge.items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
2016-11-13 22:09:54 +00:00
import net.minecraft.util.NonNullList;
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.INBTSerializable;
2016-11-13 22:09:54 +00:00
import javax.annotation.Nonnull;
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
public class ItemStackHandler implements IItemHandler, IItemHandlerModifiable, INBTSerializable<NBTTagCompound>
{
2016-11-13 22:09:54 +00:00
protected NonNullList<ItemStack> stacks;
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
public ItemStackHandler()
{
this(1);
}
public ItemStackHandler(int size)
{
stacks = NonNullList.withSize(size, ItemStack.EMPTY);
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
}
2016-11-13 22:09:54 +00:00
public ItemStackHandler(NonNullList<ItemStack> stacks)
{
this.stacks = stacks;
}
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
public void setSize(int size)
{
stacks = NonNullList.withSize(size, ItemStack.EMPTY);
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
}
@Override
2016-11-13 22:09:54 +00:00
public void setStackInSlot(int slot, @Nonnull ItemStack stack)
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
{
validateSlotIndex(slot);
2016-11-13 22:09:54 +00:00
this.stacks.set(slot, stack);
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
onContentsChanged(slot);
}
@Override
public int getSlots()
{
2016-11-13 22:09:54 +00:00
return stacks.size();
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
}
@Override
2016-11-13 22:09:54 +00:00
@Nonnull
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
public ItemStack getStackInSlot(int slot)
{
validateSlotIndex(slot);
2016-11-13 22:09:54 +00:00
return this.stacks.get(slot);
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
}
@Override
2016-11-13 22:09:54 +00:00
@Nonnull
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate)
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
{
if (stack.isEmpty())
return ItemStack.EMPTY;
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
validateSlotIndex(slot);
2016-11-13 22:09:54 +00:00
ItemStack existing = this.stacks.get(slot);
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
int limit = getStackLimit(slot, stack);
if (!existing.isEmpty())
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
{
if (!ItemHandlerHelper.canItemStacksStack(stack, existing))
return stack;
limit -= existing.getCount();
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
}
if (limit <= 0)
return stack;
boolean reachedLimit = stack.getCount() > limit;
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
if (!simulate)
{
if (existing.isEmpty())
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
{
2016-11-13 22:09:54 +00:00
this.stacks.set(slot, reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack);
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
}
else
{
existing.grow(reachedLimit ? limit : stack.getCount());
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
}
onContentsChanged(slot);
}
return reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, stack.getCount()- limit) : ItemStack.EMPTY;
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
}
2017-06-18 01:24:17 +00:00
@Override
2016-11-13 22:09:54 +00:00
@Nonnull
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
public ItemStack extractItem(int slot, int amount, boolean simulate)
{
if (amount == 0)
return ItemStack.EMPTY;
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
validateSlotIndex(slot);
2016-11-13 22:09:54 +00:00
ItemStack existing = this.stacks.get(slot);
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
if (existing.isEmpty())
return ItemStack.EMPTY;
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
int toExtract = Math.min(amount, existing.getMaxStackSize());
if (existing.getCount() <= toExtract)
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
{
if (!simulate)
{
this.stacks.set(slot, ItemStack.EMPTY);
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
onContentsChanged(slot);
}
return existing;
}
else
{
if (!simulate)
{
this.stacks.set(slot, ItemHandlerHelper.copyStackWithSize(existing, existing.getCount() - toExtract));
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
onContentsChanged(slot);
}
return ItemHandlerHelper.copyStackWithSize(existing, toExtract);
}
}
@Override
public int getSlotLimit(int slot)
{
return 64;
}
protected int getStackLimit(int slot, @Nonnull ItemStack stack)
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
{
return Math.min(getSlotLimit(slot), stack.getMaxStackSize());
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
}
@Override
public boolean isItemValid(int slot, @Nonnull ItemStack stack)
{
return true;
}
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
@Override
public NBTTagCompound serializeNBT()
{
NBTTagList nbtTagList = new NBTTagList();
2016-11-13 22:09:54 +00:00
for (int i = 0; i < stacks.size(); i++)
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
{
if (!stacks.get(i).isEmpty())
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
{
NBTTagCompound itemTag = new NBTTagCompound();
itemTag.setInt("Slot", i);
stacks.get(i).write(itemTag);
2018-08-27 17:10:07 +00:00
nbtTagList.add(itemTag);
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
}
}
NBTTagCompound nbt = new NBTTagCompound();
nbt.setTag("Items", nbtTagList);
nbt.setInt("Size", stacks.size());
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
return nbt;
}
@Override
public void deserializeNBT(NBTTagCompound nbt)
{
setSize(nbt.contains("Size", Constants.NBT.TAG_INT) ? nbt.getInt("Size") : stacks.size());
NBTTagList tagList = nbt.getList("Items", Constants.NBT.TAG_COMPOUND);
2018-08-27 17:10:07 +00:00
for (int i = 0; i < tagList.size(); i++)
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
{
NBTTagCompound itemTags = tagList.getCompound(i);
int slot = itemTags.getInt("Slot");
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
2016-11-13 22:09:54 +00:00
if (slot >= 0 && slot < stacks.size())
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
{
stacks.set(slot, ItemStack.read(itemTags));
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
}
}
onLoad();
}
protected void validateSlotIndex(int slot)
{
2016-11-13 22:09:54 +00:00
if (slot < 0 || slot >= stacks.size())
throw new RuntimeException("Slot " + slot + " not in valid range - [0," + stacks.size() + ")");
Add IItemHandler capability Add the actual patches that I forgot. Add simple implementations of IStorage and the factory methods. Add ItemStackHandler. A simple IItemHandler implementaton. return nulls, not throw nulls. Move the vanilla wrappers to a separate class for now. Minor clean ups of VanillaWrapper code. Inline static methods. Add comments. Minor cleanup of code. Remove redundant size field and add a validate slot index method. Minor formatting issues. Break early If stacksize to insert is 0. Remove setByte() methods. Throw exception if IItemHandler can't be modifyed in NBT loading. Replace event handler with patches Add capability to mine cart inventory entities. Change formatting and registration of capability. Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them. Reduce patch sizes Lazy initialization of the item handler for vanilla tiles. Minor formatting changes. Create a single vanilla chest item handler that will merge with adjacent chests when detected. Added hooks to reset the cached adjacent value when a block update is detected and when a chunk loads. Revert "Make InventoryPlayer implements IItemHandler because why not. Also added a field to allow mods that add additional player inventory space to publicly expose them." This reverts commit 306d4a37fd0e8c8a0754411c013b750dfe8e2c87. Fix furnace derp Replace double chest code with a simpler method. Vanilla wrappers implement IItemHandlerModifiable (since they are modifiable) Minor code cleanups Add an onContentsChanged() and onLoad() callback methods.to the default implementation. Add slot as a parameter in the callback method. Change IItemHandlerModifiable.setStackInSlot() to void, and added a note about not being intended for cross-mod use. Improve ItemStackHandler handling of errored NBT. Make the stacks array protected. Fix a lot of derps in SlotItemHandler. Fix derp in ItemStackHandler Clarify comments on IItemHandler ItemStackHandler no longer caches the stack array in local variable. Clean up the Chests code to make intentions clearer Vanilla hoppers have their cooldown activated when an item is inserted. Made this behavior part of an item handler (rather than the insertion code) Fix mistake in ItemStackHandler More documentation of potential edge cases in getStackInSlot() Make limit checking more resiliant.
2016-01-17 16:41:34 +00:00
}
protected void onLoad()
{
}
protected void onContentsChanged(int slot)
{
}
}