From f28b6714d42da6a3bba169bb7465f534f3c6cdcb Mon Sep 17 00:00:00 2001 From: Flanks255 <32142731+Flanks255@users.noreply.github.com> Date: Sat, 27 Jul 2024 15:43:46 -0500 Subject: [PATCH] Some more things... --- .../actuallyadditions/mod/items/ItemFilter.java | 6 ++---- .../mod/misc/apiimpl/MethodHandler.java | 14 ++++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemFilter.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemFilter.java index d54443f1b..ca2ba0313 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemFilter.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemFilter.java @@ -13,7 +13,6 @@ package de.ellpeck.actuallyadditions.mod.items; import de.ellpeck.actuallyadditions.mod.inventory.ContainerFilter; import de.ellpeck.actuallyadditions.mod.items.base.ItemBase; import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA; -import de.ellpeck.actuallyadditions.mod.util.StackUtil; import net.minecraft.network.chat.Component; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResultHolder; @@ -36,7 +35,6 @@ public class ItemFilter extends ItemBase { public InteractionResultHolder use(Level world, Player player, InteractionHand hand) { if (!world.isClientSide && hand == InteractionHand.MAIN_HAND) { player.openMenu(new SimpleMenuProvider((windowId, inv, playerEnt) -> new ContainerFilter(windowId, inv), Component.translatable("container.actuallyadditions.filter"))); - // player.openGui(ActuallyAdditions.INSTANCE, GuiHandler.GuiTypes.FILTER.ordinal(), world, (int) player.posX, (int) player.posY, (int) player.posZ); } return InteractionResultHolder.pass(player.getItemInHand(hand)); } @@ -47,10 +45,10 @@ public class ItemFilter extends ItemBase { super.appendHoverText(stack, pContext, tooltip, flagIn); ItemStackHandlerAA inv = new ItemStackHandlerAA(ContainerFilter.SLOT_AMOUNT); - DrillItem.loadSlotsFromNBT(inv, stack, pContext.registries()); + DrillItem.loadSlotsFromNBT(inv, stack); for (int i = 0; i < inv.getSlots(); i++) { ItemStack slot = inv.getStackInSlot(i); - if (StackUtil.isValid(slot)) { + if (!slot.isEmpty()) { tooltip.add(slot.getItem().getName(slot)); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/MethodHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/MethodHandler.java index ffe043e18..5ca4c5981 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/MethodHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/MethodHandler.java @@ -22,7 +22,9 @@ import de.ellpeck.actuallyadditions.mod.tile.TileEntityAtomicReconstructor; import de.ellpeck.actuallyadditions.mod.util.StackUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.Holder; import net.minecraft.core.Vec3i; +import net.minecraft.core.component.DataComponents; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; @@ -33,6 +35,7 @@ import net.minecraft.world.effect.MobEffects; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.component.CustomData; import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; @@ -107,7 +110,6 @@ public class MethodHandler implements IMethodHandler { @Override public void addEffectProperties(ItemStack stack, MobEffectInstance effect, boolean addDur, boolean addAmp) { MobEffectInstance[] effects = this.getEffectsFromStack(stack); - stack.setTag(new CompoundTag()); for (int i = 0; i < effects.length; i++) { if (effects[i].getEffect() == effect.getEffect()) { effects[i] = new MobEffectInstance(effects[i].getEffect(), effects[i].getDuration() + (addDur @@ -124,11 +126,11 @@ public class MethodHandler implements IMethodHandler { @Override public void addEffectToStack(ItemStack stack, MobEffectInstance effect) { - CompoundTag tag = stack.getOrCreateTag(); + CompoundTag tag = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY).copyTag(); //TODO move effects to a component int prevCounter = tag.getInt("Counter"); CompoundTag compound = new CompoundTag(); - compound.putString("ID", BuiltInRegistries.MOB_EFFECT.getKey(effect.getEffect()).toString()); + compound.putString("ID", BuiltInRegistries.MOB_EFFECT.getKey(effect.getEffect().value()).toString()); compound.putInt("Duration", effect.getDuration()); compound.putInt("Amplifier", effect.getAmplifier()); @@ -136,19 +138,19 @@ public class MethodHandler implements IMethodHandler { tag.put(counter + "", compound); tag.putInt("Counter", counter); - stack.setTag(tag); + stack.set(DataComponents.CUSTOM_DATA, CustomData.of(tag)); } @Override public MobEffectInstance[] getEffectsFromStack(ItemStack stack) { ArrayList effects = new ArrayList<>(); - CompoundTag tag = stack.getOrCreateTag(); + CompoundTag tag = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY).copyTag(); //TODO move effects to a component int counter = tag.getInt("Counter"); while (counter > 0) { CompoundTag compound = tag.getCompound(counter + ""); String id = compound.getString("ID"); ResourceLocation effectID = id.isEmpty() ? ResourceLocation.tryParse("speed") : ResourceLocation.tryParse(id); - MobEffect effect = BuiltInRegistries.MOB_EFFECT.get(effectID); + Holder effect = BuiltInRegistries.MOB_EFFECT.getHolder(effectID).orElse(null); if (effect == null) { ActuallyAdditions.LOGGER.error("Unable to find effect with ID: {}, defaulting to speed", effectID); effect = MobEffects.MOVEMENT_SPEED;