1.20.6 Initial Update

New Decompiler
Runtime Official mappings
ItemStacks arnt Capability providers anymore, use Vanilla's system.

Co-authored-by: RealMangoRage <[email protected]>
Co-authored-by: Paint_Ninja <[email protected]>
This commit is contained in:
committed 2024-04-30 11:42:52 -07:00
1 parent e1fa61080a
commit 7b782e5b05
1114 files changed
+24245 -28536

No files matched your search

@@ -3,10 +3,12 @@
* SPDX-License-Identifier: LGPL-2.1-only
*/
/*
package net.minecraftforge.items.wrapper;
import net.minecraft.core.Direction;
import net.minecraft.core.NonNullList;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.ContainerHelper;
@@ -14,6 +16,7 @@ import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.component.CustomData;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
@@ -30,12 +33,10 @@ import java.util.Objects;
import java.util.Set;
@ApiStatus.Internal
public class ShulkerItemStackInvWrapper implements IItemHandlerModifiable, ICapabilityProvider
{
public class ShulkerItemStackInvWrapper implements IItemHandlerModifiable, ICapabilityProvider {
@ApiStatus.Internal
@Nullable
public static ICapabilityProvider createDefaultProvider(ItemStack itemStack)
{
public static ICapabilityProvider createDefaultProvider(ItemStack itemStack) {
var item = itemStack.getItem();
if (item == Items.SHULKER_BOX ||
item == Items.BLACK_SHULKER_BOX ||
@@ -62,32 +63,28 @@ public class ShulkerItemStackInvWrapper implements IItemHandlerModifiable, ICapa
private final ItemStack stack;
private final LazyOptional<IItemHandler> holder = LazyOptional.of(() -> this);
private CompoundTag cachedTag;
private CustomData cachedData;
private NonNullList<ItemStack> itemStacksCache;
private ShulkerItemStackInvWrapper(ItemStack stack)
{
private ShulkerItemStackInvWrapper(ItemStack stack) {
this.stack = stack;
}
@Override
public int getSlots()
{
public int getSlots() {
return 27;
}
@Override
@NotNull
public ItemStack getStackInSlot(int slot)
{
public ItemStack getStackInSlot(int slot) {
validateSlotIndex(slot);
return getItemList().get(slot);
}
@Override
@NotNull
public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate)
{
public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) {
if (stack.isEmpty())
return ItemStack.EMPTY;
@@ -102,8 +99,7 @@ public class ShulkerItemStackInvWrapper implements IItemHandlerModifiable, ICapa
int limit = Math.min(getSlotLimit(slot), stack.getMaxStackSize());
if (!existing.isEmpty())
{
if (!existing.isEmpty()) {
if (!ItemHandlerHelper.canItemStacksStack(stack, existing))
return stack;
@@ -115,14 +111,10 @@ public class ShulkerItemStackInvWrapper implements IItemHandlerModifiable, ICapa
boolean reachedLimit = stack.getCount() > limit;
if (!simulate)
{
if (existing.isEmpty())
{
if (!simulate) {
if (existing.isEmpty()) {
itemStacks.set(slot, reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack);
}
else
{
} else {
existing.grow(reachedLimit ? limit : stack.getCount());
}
setItemList(itemStacks);
@@ -133,8 +125,7 @@ public class ShulkerItemStackInvWrapper implements IItemHandlerModifiable, ICapa
@Override
@NotNull
public ItemStack extractItem(int slot, int amount, boolean simulate)
{
public ItemStack extractItem(int slot, int amount, boolean simulate) {
NonNullList<ItemStack> itemStacks = getItemList();
if (amount == 0)
return ItemStack.EMPTY;
@@ -148,23 +139,16 @@ public class ShulkerItemStackInvWrapper implements IItemHandlerModifiable, ICapa
int toExtract = Math.min(amount, existing.getMaxStackSize());
if (existing.getCount() <= toExtract)
{
if (!simulate)
{
if (existing.getCount() <= toExtract) {
if (!simulate) {
itemStacks.set(slot, ItemStack.EMPTY);
setItemList(itemStacks);
return existing;
}
else
{
} else {
return existing.copy();
}
}
else
{
if (!simulate)
{
} else {
if (!simulate) {
itemStacks.set(slot, ItemHandlerHelper.copyStackWithSize(existing, existing.getCount() - toExtract));
setItemList(itemStacks);
}
@@ -173,27 +157,23 @@ public class ShulkerItemStackInvWrapper implements IItemHandlerModifiable, ICapa
}
}
private void validateSlotIndex(int slot)
{
private void validateSlotIndex(int slot) {
if (slot < 0 || slot >= getSlots())
throw new RuntimeException("Slot " + slot + " not in valid range - [0," + getSlots() + ")");
}
@Override
public int getSlotLimit(int slot)
{
public int getSlotLimit(int slot) {
return 64;
}
@Override
public boolean isItemValid(int slot, @NotNull ItemStack stack)
{
public boolean isItemValid(int slot, @NotNull ItemStack stack) {
return stack.getItem().canFitInsideContainerItems();
}
@Override
public void setStackInSlot(int slot, @NotNull ItemStack stack)
{
public void setStackInSlot(int slot, @NotNull ItemStack stack) {
validateSlotIndex(slot);
if (!isItemValid(slot, stack)) throw new RuntimeException("Invalid stack " + stack + " for slot " + slot + ")");
NonNullList<ItemStack> itemStacks = getItemList();
@@ -201,37 +181,34 @@ public class ShulkerItemStackInvWrapper implements IItemHandlerModifiable, ICapa
setItemList(itemStacks);
}
private NonNullList<ItemStack> getItemList()
{
CompoundTag rootTag = BlockItem.getBlockEntityData(this.stack);
if (cachedTag == null || !cachedTag.equals(rootTag))
private NonNullList<ItemStack> getItemList() {
var rootTag = this.stack.get(DataComponents.BLOCK_ENTITY_DATA);
if (cachedData == null || !cachedData.equals(rootTag))
itemStacksCache = refreshItemList(rootTag);
return itemStacksCache;
}
private NonNullList<ItemStack> refreshItemList(CompoundTag rootTag)
{
NonNullList<ItemStack> itemStacks = NonNullList.withSize(getSlots(), ItemStack.EMPTY);
if (rootTag != null && rootTag.contains("Items", CompoundTag.TAG_LIST))
{
private NonNullList<ItemStack> refreshItemList(CustomData data) {
var itemStacks = NonNullList.withSize(getSlots(), ItemStack.EMPTY);
var rootTag = data.copyTag();
if (rootTag != null && rootTag.contains("Items", CompoundTag.TAG_LIST)) {
ContainerHelper.loadAllItems(rootTag, itemStacks);
}
cachedTag = rootTag;
cachedData = data;
return itemStacks;
}
private void setItemList(NonNullList<ItemStack> itemStacks)
{
CompoundTag existing = BlockItem.getBlockEntityData(this.stack);
private void setItemList(NonNullList<ItemStack> itemStacks) {
var exisiting = this.stack.get(DataComponents.BLOCK_ENTITY_DATA);
CompoundTag rootTag = ContainerHelper.saveAllItems(existing == null ? new CompoundTag() : existing, itemStacks);
BlockItem.setBlockEntityData(this.stack, BlockEntityType.SHULKER_BOX, rootTag);
cachedTag = rootTag;
cachedData = rootTag;
}
@Override
@NotNull
public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side)
{
public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) {
return ForgeCapabilities.ITEM_HANDLER.orEmpty(cap, this.holder);
}
}
*/