Skip to content

Commit

Permalink
1.21 deprecations (#1091)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt authored Jun 12, 2024
1 parent f9eb6d9 commit 52526da
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 68 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jetbrains_annotations_version=24.0.1
slf4j_api_version=2.0.7
apache_maven_artifact_version=3.8.5
jarjar_version=0.4.1
fancy_mod_loader_version=3.0.45
fancy_mod_loader_version=4.0.1
mojang_logging_version=1.1.1
log4j_version=2.22.1
guava_version=31.1.2-jre
Expand Down
6 changes: 4 additions & 2 deletions patches/net/minecraft/world/entity/animal/Parrot.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@
return getImitatedSound(list.get(p_218240_.nextInt(list.size())));
} else {
return SoundEvents.PARROT_AMBIENT;
@@ -329,6 +_,8 @@
@@ -329,7 +_,9 @@
}

private static SoundEvent getImitatedSound(EntityType<?> p_29409_) {
- return MOB_SOUND_MAP.getOrDefault(p_29409_, SoundEvents.PARROT_AMBIENT);
+ var imitation = p_29409_.builtInRegistryHolder().getData(net.neoforged.neoforge.registries.datamaps.builtin.NeoForgeDataMaps.PARROT_IMITATIONS);
+ if (imitation != null) return imitation.sound();
return MOB_SOUND_MAP.getOrDefault(p_29409_, SoundEvents.PARROT_AMBIENT);
+ return SoundEvents.PARROT_AMBIENT;
}

@Override
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
return l;
}
}
@@ -214,13 +_,18 @@
@@ -214,11 +_,15 @@
}

public void tick() {
Expand All @@ -25,10 +25,7 @@
+ slot++;
}
}
+ armor.forEach(e -> e.onArmorTick(player.level(), player));
}

public boolean add(ItemStack p_36055_) {
@@ -268,6 +_,8 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Adding item to inventory");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
public static final int MIN_LEVEL = 0;
public static final int MAX_LEVEL = 7;
public static final IntegerProperty LEVEL = BlockStateProperties.LEVEL_COMPOSTER;
+ /** @deprecated Neo: Use the {@link net.neoforged.neoforge.registries.datamaps.builtin.NeoForgeDataMaps#COMPOSTABLES compostable} data map instead, as this field will be ignored starting with 1.20.5. */
+ /** @deprecated Neo: Use the {@link net.neoforged.neoforge.registries.datamaps.builtin.NeoForgeDataMaps#COMPOSTABLES compostable} data map instead */
+ @Deprecated
public static final Object2FloatMap<ItemLike> COMPOSTABLES = new Object2FloatOpenHashMap<>();
private static final int AABB_SIDE_THICKNESS = 2;
Expand Down Expand Up @@ -70,6 +70,6 @@
+ public static float getValue(ItemStack item) {
+ var value = item.getItemHolder().getData(net.neoforged.neoforge.registries.datamaps.builtin.NeoForgeDataMaps.COMPOSTABLES);
+ if (value != null) return value.chance();
+ return COMPOSTABLES.getFloat(item.getItem());
+ return -1f;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
static int getGameEventFrequency(ResourceKey<GameEvent> p_316800_) {
- return VIBRATION_FREQUENCY_FOR_EVENT.applyAsInt(p_316800_);
+ var holder = net.minecraft.core.registries.BuiltInRegistries.GAME_EVENT.getHolder(p_316800_);
+ return holder.isPresent() ? getGameEventFrequency(holder.get()) : VIBRATION_FREQUENCY_FOR_EVENT.applyAsInt(p_316800_);
+ return holder.map(VibrationSystem::getGameEventFrequency).orElse(0);
}

static ResourceKey<GameEvent> getResonanceEventByFrequency(int p_282105_) {
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,6 @@ default boolean doesSneakBypassUse(ItemStack stack, net.minecraft.world.level.Le
return false;
}

/**
* Called to tick armor in the armor slot. Override to do something
*
* @deprecated Use {@link Item#inventoryTick(ItemStack, Level, Entity, int, boolean)} by checking that the slot argument is an armor slot. Armor slots are 36, 37, 38 and 39.
*/
@Deprecated(forRemoval = true, since = "1.20.4")
default void onArmorTick(ItemStack stack, Level level, Player player) {}

/**
* Determines if the specific ItemStack can be placed in the specified armor
* slot, for the entity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,6 @@ default float getXpRepairRatio() {
return self().getItem().getXpRepairRatio(self());
}

/**
* Called to tick armor in the armor slot. Override to do something
*
* @deprecated Use {@link Item#inventoryTick(ItemStack, Level, Entity, int, boolean)} by checking that the slot argument is an armor slot. Armor slots are 36, 37, 38 and 39.
*/
@Deprecated(forRemoval = true, since = "1.20.4")
default void onArmorTick(Level level, Player player) {
self().getItem().onArmorTick(self(), level, player);
}

/**
* Called every tick when this item is equipped {@linkplain Mob#isBodyArmorItem(ItemStack) as an armor item} by a horse {@linkplain Mob#canWearBodyArmor()} that can wear armor}.
* <p>
Expand Down
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 52526da

Please sign in to comment.