Class ItemStorage
java.lang.Object
com.hammy275.immersivemc.common.immersive.storage.dual.impl.ItemStorage
- All Implemented Interfaces:
NetworkStorage,WorldStorage
- Direct Known Subclasses:
AnvilStorage,ApothSalvagingTableStorage,BeaconStorage,CraftingTableStorage,ETableWorldStorage,GrindstoneStorage,SmithingTableStorage
Functions both as WorldStorage for saving server side and as a NetworkStorage for sending items
to the client. Note that only the items array is sent to the client, no other fields are!
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanWhether this storage has changed since the last sync to the client.protected List<ItemStorage.PlayerItemCounts>[]Item counts from each player for each slot.protected net.minecraft.world.item.ItemStack[]A list of items.final intThe index of the last item in the items array that is an input item. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSlotsToEnd(int slotsToAdd) Add slotsToAdd number of slots.voidcopyFromOld(ItemStorage oldStorage) voiddecode(net.minecraft.network.RegistryFriendlyByteBuf buffer) Decode the buffer into this object.voidencode(net.minecraft.network.RegistryFriendlyByteBuf buffer) Encode this storage into a buffer.net.minecraft.world.item.ItemStackgetItem(int slot) net.minecraft.world.item.ItemStack[]Get item array directly.intvoidincrementCountForPlayer(net.minecraft.world.entity.player.Player player, int amount, int slot) Increments the return item count for the provided player.booleanvoidload(net.minecraft.nbt.CompoundTag nbt, net.minecraft.core.HolderLookup.Provider provider, int lastVanillaDataVersion) Load from the NBT tag into this object.voidmoveSlot(int oldSlot, int newSlot) Moves the slot at position oldSlot to position newSlot.voidplaceItem(net.minecraft.world.entity.player.Player player, net.minecraft.world.InteractionHand hand, int slot, ItemSwapAmount amount) Attempts to merge contents of hand into the given slot, returning any leftovers or a new handStack.voidplaceItem(net.minecraft.world.entity.player.Player player, net.minecraft.world.InteractionHand hand, int slot, ItemSwapAmount amount, int forcedMaxImmersiveStackSize) Attempts to merge contents of hand into the given slot, returning any leftovers or a new handStack.voidreturnItems(net.minecraft.world.entity.player.Player player) Return items to player when leaving radiusnet.minecraft.nbt.CompoundTagsave(net.minecraft.nbt.CompoundTag nbt, net.minecraft.core.HolderLookup.Provider provider) Save this object into the NBT tag.voidsetDirty(net.minecraft.server.level.ServerLevel level) voidsetItem(int slot, net.minecraft.world.item.ItemStack stack) Directly set stack into slot.voidsetItem(int slot, net.minecraft.world.item.ItemStack stack, net.minecraft.world.entity.player.Player player) Directly set stack into slot with player credit for item counting.voidvoidshrinkCountsOnly(int slot, int amount) Shrink a slot, but only for the itemCounts, not the actual stored items!voidshrinkSlot(int slot, int amount) Shrink slot, adjusting the leftovers along the way.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.hammy275.immersivemc.server.storage.world.WorldStorage
getHandler
-
Field Details
-
items
protected net.minecraft.world.item.ItemStack[] itemsA list of items. Usually contains inputs and outputs. -
itemCounts
Item counts from each player for each slot. Used for item returns. -
isDirtyForClientSync
protected boolean isDirtyForClientSyncWhether this storage has changed since the last sync to the client. -
maxInputIndex
public final int maxInputIndexThe index of the last item in the items array that is an input item.
-
-
Constructor Details
-
ItemStorage
public ItemStorage(int numItems, int maxInputIndex)
-
-
Method Details
-
isDirtyForClientSync
public boolean isDirtyForClientSync() -
setDirty
public void setDirty(net.minecraft.server.level.ServerLevel level) -
setNoLongerDirtyForClientSync
public void setNoLongerDirtyForClientSync() -
setItem
public void setItem(int slot, net.minecraft.world.item.ItemStack stack) Directly set stack into slot.- Parameters:
slot- Slot to place intostack- Stack to place
-
setItem
public void setItem(int slot, net.minecraft.world.item.ItemStack stack, net.minecraft.world.entity.player.Player player) Directly set stack into slot with player credit for item counting.- Parameters:
slot- Slot to place intostack- Stack to placeplayer- Player to credit for placement
-
shrinkSlot
public void shrinkSlot(int slot, int amount) Shrink slot, adjusting the leftovers along the way.- Parameters:
slot- Slot to shrink fromamount- Amount to shrink by
-
shrinkCountsOnly
public void shrinkCountsOnly(int slot, int amount) Shrink a slot, but only for the itemCounts, not the actual stored items!- Parameters:
slot- Slot to shrink fromamount- Amount to shrink by
-
placeItem
public void placeItem(net.minecraft.world.entity.player.Player player, net.minecraft.world.InteractionHand hand, int slot, ItemSwapAmount amount) Attempts to merge contents of hand into the given slot, returning any leftovers or a new handStack.- Parameters:
player- Player to get items fromhand- Hand to get item fromslot- Slot to merge intoamount- Amount of items to swap
-
placeItem
public void placeItem(net.minecraft.world.entity.player.Player player, net.minecraft.world.InteractionHand hand, int slot, ItemSwapAmount amount, int forcedMaxImmersiveStackSize) Attempts to merge contents of hand into the given slot, returning any leftovers or a new handStack.- Parameters:
player- Player to get items fromhand- Hand to get item fromslot- Slot to merge intoamount- Amount of items to swapforcedMaxImmersiveStackSize- A forced maximum stack size for the slot in the Immersive, or -1 to use the item's stack size.
-
incrementCountForPlayer
public void incrementCountForPlayer(net.minecraft.world.entity.player.Player player, int amount, int slot) Increments the return item count for the provided player.- Parameters:
player- Player to increment for.amount- Amount to increment.slot- Slot to increment in.
-
getItem
public net.minecraft.world.item.ItemStack getItem(int slot) -
getNumItems
public int getNumItems() -
getItemsRaw
public net.minecraft.world.item.ItemStack[] getItemsRaw()Get item array directly. Only use for immersives that don't utilize the queue.- Returns:
- Items array.
-
copyFromOld
-
returnItems
public void returnItems(net.minecraft.world.entity.player.Player player) Return items to player when leaving radius- Parameters:
player- Player to return items to
-
load
public void load(net.minecraft.nbt.CompoundTag nbt, net.minecraft.core.HolderLookup.Provider provider, int lastVanillaDataVersion) Description copied from interface:WorldStorageLoad from the NBT tag into this object.- Specified by:
loadin interfaceWorldStorage- Parameters:
nbt- NBT tag to load from.provider- Provider for registry access.lastVanillaDataVersion- The last vanilla data version this storage was loaded in.
-
save
public net.minecraft.nbt.CompoundTag save(net.minecraft.nbt.CompoundTag nbt, net.minecraft.core.HolderLookup.Provider provider) Description copied from interface:WorldStorageSave this object into the NBT tag.- Specified by:
savein interfaceWorldStorage- Parameters:
nbt- NBT tag to save to.provider- Provider for registry access.- Returns:
- The same NBT tag as provided to this method.
-
moveSlot
public void moveSlot(int oldSlot, int newSlot) Moves the slot at position oldSlot to position newSlot. Only be used for version conversion, such as the addition of smithing templates in 1.20. The old slot will be made into air and have its item counts wiped.- Parameters:
oldSlot- Old slot numbernewSlot- New slot number
-
addSlotsToEnd
public void addSlotsToEnd(int slotsToAdd) Add slotsToAdd number of slots. Really should only be used for version conversion.- Parameters:
slotsToAdd- Number of slots to add. Will be added at the end of arrays.
-
encode
public void encode(net.minecraft.network.RegistryFriendlyByteBuf buffer) Description copied from interface:NetworkStorageEncode this storage into a buffer.- Specified by:
encodein interfaceNetworkStorage- Parameters:
buffer- Buffer to encode storage into.
-
decode
public void decode(net.minecraft.network.RegistryFriendlyByteBuf buffer) Description copied from interface:NetworkStorageDecode the buffer into this object.- Specified by:
decodein interfaceNetworkStorage- Parameters:
buffer- Buffer to decode from.
-