Skip to content

Commit

Permalink
Remove ItemHandlerHelper deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt committed Jun 11, 2024
1 parent 57bca00 commit 6170679
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 40 deletions.
8 changes: 4 additions & 4 deletions src/main/java/net/neoforged/neoforge/fluids/FluidUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static boolean interactWithFluidHandler(Player player, InteractionHand ha
* @return a {@link FluidActionResult} holding the filled container if successful.
*/
public static FluidActionResult tryFillContainer(ItemStack container, IFluidHandler fluidSource, int maxAmount, @Nullable Player player, boolean doFill) {
ItemStack containerCopy = ItemHandlerHelper.copyStackWithSize(container, 1); // do not modify the input
ItemStack containerCopy = container.copyWithCount(1); // do not modify the input
return getFluidHandler(containerCopy)
.map(containerFluidHandler -> {
FluidStack simulatedTransfer = tryFluidTransfer(containerFluidHandler, fluidSource, maxAmount, false);
Expand Down Expand Up @@ -152,7 +152,7 @@ public static FluidActionResult tryFillContainer(ItemStack container, IFluidHand
* NOTE If the container is consumable, the empty container will be null on success.
*/
public static FluidActionResult tryEmptyContainer(ItemStack container, IFluidHandler fluidDestination, int maxAmount, @Nullable Player player, boolean doDrain) {
ItemStack containerCopy = ItemHandlerHelper.copyStackWithSize(container, 1); // do not modify the input
ItemStack containerCopy = container.copyWithCount(1); // do not modify the input
return getFluidHandler(containerCopy)
.map(containerFluidHandler -> {
FluidStack transfer = tryFluidTransfer(fluidDestination, containerFluidHandler, maxAmount, doDrain);
Expand Down Expand Up @@ -374,7 +374,7 @@ public static Optional<IFluidHandlerItem> getFluidHandler(ItemStack itemStack) {
*/
public static Optional<FluidStack> getFluidContained(ItemStack container) {
if (!container.isEmpty()) {
container = ItemHandlerHelper.copyStackWithSize(container, 1);
container = container.copyWithCount(1);
Optional<FluidStack> fluidContained = getFluidHandler(container)
.map(handler -> handler.drain(Integer.MAX_VALUE, IFluidHandler.FluidAction.SIMULATE));
if (fluidContained.isPresent() && !fluidContained.get().isEmpty()) {
Expand Down Expand Up @@ -435,7 +435,7 @@ public static FluidActionResult tryPickUpFluid(ItemStack emptyContainer, @Nullab
* @return the container's ItemStack with the remaining amount of fluid if the placement was successful, null otherwise
*/
public static FluidActionResult tryPlaceFluid(@Nullable Player player, Level level, InteractionHand hand, BlockPos pos, ItemStack container, FluidStack resource) {
ItemStack containerCopy = ItemHandlerHelper.copyStackWithSize(container, 1); // do not modify the input
ItemStack containerCopy = container.copyWithCount(1); // do not modify the input
return getFluidHandler(containerCopy)
.filter(handler -> tryPlaceFluid(player, level, hand, pos, handler, resource))
.map(IFluidHandlerItem::getContainer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,6 @@ public static ItemStack insertItem(IItemHandler dest, ItemStack stack, boolean s
return stack;
}

/**
* @deprecated Use {@link ItemStack#isSameItemSameComponents(ItemStack, ItemStack)}
*/
@Deprecated(forRemoval = true, since = "1.20.5")
public static boolean canItemStacksStack(ItemStack a, ItemStack b) {
return ItemStack.isSameItemSameComponents(a, b);
}

/**
* @deprecated Use {@link ItemStack#copyWithCount(int)}
*/
@Deprecated(forRemoval = true, since = "1.20.5")
public static ItemStack copyStackWithSize(ItemStack stack, int count) {
return stack.copyWithCount(count);
}

/**
* Inserts the ItemStack into the inventory, filling up already present stacks first.
* This is equivalent to the behaviour of a player picking up an item.
Expand All @@ -65,7 +49,7 @@ public static ItemStack insertItemStacked(IItemHandler inventory, ItemStack stac
// go through the inventory and try to fill up already existing items
for (int i = 0; i < sizeInventory; i++) {
ItemStack slot = inventory.getStackInSlot(i);
if (canItemStacksStack(slot, stack)) {
if (ItemStack.isSameItemSameComponents(slot, stack)) {
stack = inventory.insertItem(i, stack, simulate);

if (stack.isEmpty()) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/neoforged/neoforge/items/ItemStackHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
int limit = getStackLimit(slot, stack);

if (!existing.isEmpty()) {
if (!ItemHandlerHelper.canItemStacksStack(stack, existing))
if (!ItemStack.isSameItemSameComponents(stack, existing))
return stack;

limit -= existing.getCount();
Expand All @@ -79,14 +79,14 @@ public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {

if (!simulate) {
if (existing.isEmpty()) {
this.stacks.set(slot, reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack);
this.stacks.set(slot, reachedLimit ? stack.copyWithCount(limit) : stack);
} else {
existing.grow(reachedLimit ? limit : stack.getCount());
}
onContentsChanged(slot);
}

return reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - limit) : ItemStack.EMPTY;
return reachedLimit ? stack.copyWithCount(stack.getCount() - limit) : ItemStack.EMPTY;
}

@Override
Expand All @@ -113,11 +113,11 @@ public ItemStack extractItem(int slot, int amount, boolean simulate) {
}
} else {
if (!simulate) {
this.stacks.set(slot, ItemHandlerHelper.copyStackWithSize(existing, existing.getCount() - toExtract));
this.stacks.set(slot, existing.copyWithCount(existing.getCount() - toExtract));
onContentsChanged(slot);
}

return ItemHandlerHelper.copyStackWithSize(existing, toExtract);
return existing.copyWithCount(toExtract);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static Boolean extractHook(Level level, Hopper dest) {
if (!extractItem.isEmpty()) {
for (int j = 0; j < dest.getContainerSize(); j++) {
ItemStack destStack = dest.getItem(j);
if (dest.canPlaceItem(j, extractItem) && (destStack.isEmpty() || destStack.getCount() < destStack.getMaxStackSize() && destStack.getCount() < dest.getMaxStackSize() && ItemHandlerHelper.canItemStacksStack(extractItem, destStack))) {
if (dest.canPlaceItem(j, extractItem) && (destStack.isEmpty() || destStack.getCount() < destStack.getMaxStackSize() && destStack.getCount() < dest.getMaxStackSize() && ItemStack.isSameItemSameComponents(extractItem, destStack))) {
extractItem = handler.extractItem(i, 1, false);
if (destStack.isEmpty())
dest.setItem(j, extractItem);
Expand Down Expand Up @@ -142,7 +142,7 @@ private static ItemStack insertStack(BlockEntity source, Object destination, IIt
destInventory.insertItem(slot, stack, false);
stack = ItemStack.EMPTY;
insertedItem = true;
} else if (ItemHandlerHelper.canItemStacksStack(itemstack, stack)) {
} else if (ItemStack.isSameItemSameComponents(itemstack, stack)) {
int originalSize = stack.getCount();
stack = destInventory.insertItem(slot, stack, false);
insertedItem = originalSize < stack.getCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.items.IItemHandler;
import net.neoforged.neoforge.items.IItemHandlerModifiable;
import net.neoforged.neoforge.items.ItemHandlerHelper;

/**
* Exposes the armor or hands inventory of an {@link LivingEntity} as an {@link IItemHandler} using {@link LivingEntity#getItemBySlot(EquipmentSlot)} and
Expand Down Expand Up @@ -71,7 +70,7 @@ public ItemStack insertItem(final int slot, final ItemStack stack, final boolean
int limit = getStackLimit(slot, stack);

if (!existing.isEmpty()) {
if (!ItemHandlerHelper.canItemStacksStack(stack, existing))
if (!ItemStack.isSameItemSameComponents(stack, existing))
return stack;

limit -= existing.getCount();
Expand All @@ -84,13 +83,13 @@ public ItemStack insertItem(final int slot, final ItemStack stack, final boolean

if (!simulate) {
if (existing.isEmpty()) {
entity.setItemSlot(equipmentSlot, reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack);
entity.setItemSlot(equipmentSlot, reachedLimit ? stack.copyWithCount(limit) : stack);
} else {
existing.grow(reachedLimit ? limit : stack.getCount());
}
}

return reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - limit) : ItemStack.EMPTY;
return reachedLimit ? stack.copyWithCount(stack.getCount() - limit) : ItemStack.EMPTY;
}

@Override
Expand All @@ -115,10 +114,10 @@ public ItemStack extractItem(final int slot, final int amount, final boolean sim
return existing;
} else {
if (!simulate) {
entity.setItemSlot(equipmentSlot, ItemHandlerHelper.copyStackWithSize(existing, existing.getCount() - toExtract));
entity.setItemSlot(equipmentSlot, existing.copyWithCount(existing.getCount() - toExtract));
}

return ItemHandlerHelper.copyStackWithSize(existing, toExtract);
return existing.copyWithCount(toExtract);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import net.minecraft.world.Container;
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.items.IItemHandlerModifiable;
import net.neoforged.neoforge.items.ItemHandlerHelper;

public class InvWrapper implements IItemHandlerModifiable {
private final Container inv;
Expand Down Expand Up @@ -56,7 +55,7 @@ public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
if (stackInSlot.getCount() >= Math.min(stackInSlot.getMaxStackSize(), getSlotLimit(slot)))
return stack;

if (!ItemHandlerHelper.canItemStacksStack(stack, stackInSlot))
if (!ItemStack.isSameItemSameComponents(stack, stackInSlot))
return stack;

if (!getInv().canPlaceItem(slot, stack))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
import net.minecraft.world.level.block.entity.BrewingStandBlockEntity;
import net.neoforged.neoforge.items.IItemHandlerModifiable;
import net.neoforged.neoforge.items.ItemHandlerHelper;
import org.jetbrains.annotations.Nullable;

public class SidedInvWrapper implements IItemHandlerModifiable {
Expand Down Expand Up @@ -101,7 +100,7 @@ public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
if (stackInSlot.getCount() >= Math.min(stackInSlot.getMaxStackSize(), getSlotLimit(slot)))
return stack;

if (!ItemHandlerHelper.canItemStacksStack(stack, stackInSlot))
if (!ItemStack.isSameItemSameComponents(stack, stackInSlot))
return stack;

if (!inv.canPlaceItemThroughFace(slot1, stack, side) || !inv.canPlaceItem(slot1, stack))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
import net.neoforged.neoforge.common.loot.IGlobalLootModifier;
import net.neoforged.neoforge.common.loot.LootModifier;
import net.neoforged.neoforge.common.loot.LootTableIdCondition;
import net.neoforged.neoforge.items.ItemHandlerHelper;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;
import net.neoforged.neoforge.registries.NeoForgeRegistries;
Expand Down Expand Up @@ -114,7 +113,7 @@ private static ItemStack smelt(ItemStack stack, LootContext context) {
return context.getLevel().getRecipeManager().getRecipeFor(RecipeType.SMELTING, new SingleRecipeInput(stack), context.getLevel())
.map(smeltingRecipe -> smeltingRecipe.value().getResultItem(context.getLevel().registryAccess()))
.filter(itemStack -> !itemStack.isEmpty())
.map(itemStack -> ItemHandlerHelper.copyStackWithSize(itemStack, stack.getCount() * itemStack.getCount()))
.map(itemStack -> itemStack.copyWithCount(stack.getCount() * itemStack.getCount()))
.orElse(stack);
}

Expand Down

0 comments on commit 6170679

Please sign in to comment.