From f5a2165d85f46e14d88b74eeb262ca1df4bdde63 Mon Sep 17 00:00:00 2001 From: P3pp3rF1y Date: Sun, 17 Nov 2024 01:05:22 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Fixed=20discBlockList=20t?= =?UTF-8?q?o=20be=20properly=20considered=20again=20as=20after=20its=20use?= =?UTF-8?q?=20was=20accidentally=20removed=20during=201.21=20port?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- .../common/EntityBackpackAdditionHandler.java | 28 +++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/gradle.properties b/gradle.properties index aeafb851..d71221ed 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ loader_version_range=[4,) mod_id=sophisticatedbackpacks mod_name=Sophisticated Backpacks mod_license=GNU General Public License v3.0 -mod_version=3.20.20 +mod_version=3.20.21 mod_group_id=sophisticatedbackpacks mod_authors=P3pp3rF1y, Ridanisaurus mod_description=Fancy and functional backpacks. diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/common/EntityBackpackAdditionHandler.java b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/common/EntityBackpackAdditionHandler.java index bde515f4..f2b78ea1 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/common/EntityBackpackAdditionHandler.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/common/EntityBackpackAdditionHandler.java @@ -6,7 +6,6 @@ import net.minecraft.core.registries.Registries; import net.minecraft.server.MinecraftServer; import net.minecraft.tags.EnchantmentTags; -import net.minecraft.tags.ItemTags; import net.minecraft.util.RandomSource; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectInstance; @@ -31,6 +30,7 @@ import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; +import net.neoforged.neoforge.common.Tags; import net.neoforged.neoforge.common.util.FakePlayer; import net.neoforged.neoforge.event.entity.living.LivingDropsEvent; import net.neoforged.neoforge.event.tick.EntityTickEvent; @@ -45,10 +45,7 @@ import net.p3pp3rf1y.sophisticatedcore.util.RandHelper; import net.p3pp3rf1y.sophisticatedcore.util.WeightedElement; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; public class EntityBackpackAdditionHandler { private static final int MAX_DIFFICULTY = 3; @@ -175,10 +172,29 @@ private static void addJukeboxUpgradeAndRandomDisc(IStorageWrapper w, RandomSour Iterator it = w.getUpgradeHandler().getTypeWrappers(JukeboxUpgradeItem.TYPE).iterator(); if (it.hasNext()) { JukeboxUpgradeItem.Wrapper wrapper = it.next(); - BuiltInRegistries.ITEM.getRandomElementOf(ItemTags.CREEPER_DROP_MUSIC_DISCS, rnd).ifPresent(disc -> wrapper.setDisc(new ItemStack(disc))); + wrapper.setDisc(new ItemStack(getMusicDiscs().get(rnd.nextInt(getMusicDiscs().size())))); } } + private static List musicDiscs = null; + + private static List getMusicDiscs() { + if (musicDiscs == null) { + BuiltInRegistries.ITEM.getTag(Tags.Items.MUSIC_DISCS).ifPresentOrElse(records -> { + Set blockedDiscs = new HashSet<>(Config.SERVER.entityBackpackAdditions.discBlockList.get()); + musicDiscs = new ArrayList<>(); + records.forEach(musicDisc -> { + //noinspection ConstantConditions - by this point the disc has registry name + if (!blockedDiscs.contains(musicDisc.getKey().location().toString())) { + musicDiscs.add(musicDisc.value()); + } + }); + }, () -> musicDiscs = Collections.emptyList()); + } + + return musicDiscs; + } + private static void raiseHealth(Monster monster, int minDifficulty) { if (Boolean.FALSE.equals(Config.SERVER.entityBackpackAdditions.buffHealth.get())) { return;