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

@@ -16,19 +16,15 @@ import net.minecraftforge.items.wrapper.PlayerMainInvWrapper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ItemHandlerHelper
{
public class ItemHandlerHelper {
@NotNull
public static ItemStack insertItem(IItemHandler dest, @NotNull ItemStack stack, boolean simulate)
{
public static ItemStack insertItem(IItemHandler dest, @NotNull ItemStack stack, boolean simulate) {
if (dest == null || stack.isEmpty())
return stack;
for (int i = 0; i < dest.getSlots(); i++)
{
for (int i = 0; i < dest.getSlots(); i++) {
stack = dest.insertItem(i, stack, simulate);
if (stack.isEmpty())
{
if (stack.isEmpty()) {
return ItemStack.EMPTY;
}
}
@@ -36,42 +32,12 @@ public class ItemHandlerHelper
return stack;
}
public static boolean canItemStacksStack(@NotNull ItemStack a, @NotNull ItemStack b)
{
if (a.isEmpty() || !ItemStack.isSameItem(a, b) || a.hasTag() != b.hasTag())
return false;
return (!a.hasTag() || a.getTag().equals(b.getTag())) && a.areCapsCompatible(b);
}
/**
* A relaxed version of canItemStacksStack that stacks itemstacks with different metadata if they don't have subtypes.
* This usually only applies when players pick up items.
*/
public static boolean canItemStacksStackRelaxed(@NotNull ItemStack a, @NotNull ItemStack b)
{
if (a.isEmpty() || b.isEmpty() || a.getItem() != b.getItem())
return false;
if (!a.isStackable())
return false;
// Metadata value only matters when the item has subtypes
// Vanilla stacks non-subtype items with different metadata together
// TODO Item subtypes, is this still necessary?
/* e.g. a stick with metadata 0 and a stick with metadata 1 stack
if (a.getHasSubtypes() && a.getMetadata() != b.getMetadata())
return false;
*/
if (a.hasTag() != b.hasTag())
return false;
return (!a.hasTag() || a.getTag().equals(b.getTag())) && a.areCapsCompatible(b);
public static boolean canItemStacksStack(@NotNull ItemStack a, @NotNull ItemStack b) {
return ItemStack.isSameItemSameComponents(a, b);
}
@NotNull
public static ItemStack copyStackWithSize(@NotNull ItemStack itemStack, int size)
{
public static ItemStack copyStackWithSize(@NotNull ItemStack itemStack, int size) {
if (size == 0)
return ItemStack.EMPTY;
ItemStack copy = itemStack.copy();
@@ -85,45 +51,36 @@ public class ItemHandlerHelper
* Note: This function stacks items without subtypes with different metadata together.
*/
@NotNull
public static ItemStack insertItemStacked(IItemHandler inventory, @NotNull ItemStack stack, boolean simulate)
{
public static ItemStack insertItemStacked(IItemHandler inventory, @NotNull ItemStack stack, boolean simulate) {
if (inventory == null || stack.isEmpty())
return stack;
// not stackable -> just insert into a new slot
if (!stack.isStackable())
{
if (!stack.isStackable()) {
return insertItem(inventory, stack, simulate);
}
int sizeInventory = inventory.getSlots();
// go through the inventory and try to fill up already existing items
for (int i = 0; i < sizeInventory; i++)
{
for (int i = 0; i < sizeInventory; i++) {
ItemStack slot = inventory.getStackInSlot(i);
if (canItemStacksStackRelaxed(slot, stack))
{
if (canItemStacksStack(slot, stack)) {
stack = inventory.insertItem(i, stack, simulate);
if (stack.isEmpty())
{
if (stack.isEmpty()) {
break;
}
}
}
// insert remainder into empty slots
if (!stack.isEmpty())
{
if (!stack.isEmpty()) {
// find empty slot
for (int i = 0; i < sizeInventory; i++)
{
if (inventory.getStackInSlot(i).isEmpty())
{
for (int i = 0; i < sizeInventory; i++) {
if (inventory.getStackInSlot(i).isEmpty()) {
stack = inventory.insertItem(i, stack, simulate);
if (stack.isEmpty())
{
if (stack.isEmpty()) {
break;
}
}
@@ -145,8 +102,7 @@ public class ItemHandlerHelper
* @param player The player to give the item to
* @param stack The itemstack to insert
*/
public static void giveItemToPlayer(Player player, @NotNull ItemStack stack, int preferredSlot)
{
public static void giveItemToPlayer(Player player, @NotNull ItemStack stack, int preferredSlot) {
if (stack.isEmpty()) return;
IItemHandler inventory = new PlayerMainInvWrapper(player.getInventory());
@@ -155,26 +111,23 @@ public class ItemHandlerHelper
// try adding it into the inventory
ItemStack remainder = stack;
// insert into preferred slot first
if (preferredSlot >= 0 && preferredSlot < inventory.getSlots())
{
if (preferredSlot >= 0 && preferredSlot < inventory.getSlots()) {
remainder = inventory.insertItem(preferredSlot, stack, false);
}
// then into the inventory in general
if (!remainder.isEmpty())
{
if (!remainder.isEmpty()) {
remainder = insertItemStacked(inventory, remainder, false);
}
// play sound if something got picked up
if (remainder.isEmpty() || remainder.getCount() != stack.getCount())
{
if (remainder.isEmpty() || remainder.getCount() != stack.getCount()) {
level.playSound(null, player.getX(), player.getY() + 0.5, player.getZ(),
SoundEvents.ITEM_PICKUP, SoundSource.PLAYERS, 0.2F, ((level.random.nextFloat() - level.random.nextFloat()) * 0.7F + 1.0F) * 2.0F);
}
// drop remaining itemstack into the level
if (!remainder.isEmpty() && !level.isClientSide)
{
if (!remainder.isEmpty() && !level.isClientSide) {
ItemEntity entityitem = new ItemEntity(level, player.getX(), player.getY() + 0.5, player.getZ(), remainder);
entityitem.setPickUpDelay(40);
entityitem.setDeltaMovement(entityitem.getDeltaMovement().multiply(0, 1, 0));
@@ -189,23 +142,17 @@ public class ItemHandlerHelper
* @param inv The inventory handler to test.
* @return A redstone value in the range [0,15] representing how "full" this inventory is.
*/
public static int calcRedstoneFromInventory(@Nullable IItemHandler inv)
{
if (inv == null)
{
public static int calcRedstoneFromInventory(@Nullable IItemHandler inv) {
if (inv == null) {
return 0;
}
else
{
} else {
int itemsFound = 0;
float proportion = 0.0F;
for (int j = 0; j < inv.getSlots(); ++j)
{
for (int j = 0; j < inv.getSlots(); ++j) {
ItemStack itemstack = inv.getStackInSlot(j);
if (!itemstack.isEmpty())
{
if (!itemstack.isEmpty()) {
proportion += (float)itemstack.getCount() / (float)Math.min(inv.getSlotLimit(j), itemstack.getMaxStackSize());
++itemsFound;
}