Skip to content

Commit

Permalink
fix: 🐛 Fixed discBlockList to be properly considered again as after i…
Browse files Browse the repository at this point in the history
…ts use was accidentally removed during 1.21 port
  • Loading branch information
P3pp3rF1y committed Nov 17, 2024
1 parent 8d24dfd commit f5a2165
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -175,10 +172,29 @@ private static void addJukeboxUpgradeAndRandomDisc(IStorageWrapper w, RandomSour
Iterator<JukeboxUpgradeItem.Wrapper> 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<Item> musicDiscs = null;

private static List<Item> getMusicDiscs() {
if (musicDiscs == null) {
BuiltInRegistries.ITEM.getTag(Tags.Items.MUSIC_DISCS).ifPresentOrElse(records -> {
Set<String> 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;
Expand Down

0 comments on commit f5a2165

Please sign in to comment.