Skip to content

Commit 13a2b06

Browse files
committed
feat: update to 1.20.6
1 parent db526b1 commit 13a2b06

11 files changed

Lines changed: 87 additions & 52 deletions

File tree

build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ plugins {
1111
}
1212

1313
group = "me.machinemaker"
14-
version = "0.5.0"
14+
version = "0.6.0"
1515

1616
repositories {
1717
mavenCentral()
@@ -29,7 +29,7 @@ dependencies {
2929
}
3030

3131
java {
32-
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
32+
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
3333
}
3434

3535
checkstyle {
@@ -55,7 +55,7 @@ tasks {
5555
}
5656

5757
compileJava {
58-
options.release.set(17)
58+
options.release.set(21)
5959
options.encoding = Charsets.UTF_8.toString()
6060
}
6161

@@ -74,7 +74,7 @@ tasks {
7474
systemProperty("com.mojang.eula.agree", "true")
7575

7676
downloadPlugins {
77-
url("https://download.luckperms.net/1526/bukkit/loader/LuckPerms-Bukkit-5.4.113.jar")
77+
url("https://download.luckperms.net/1543/bukkit/loader/LuckPerms-Bukkit-5.4.130.jar")
7878
}
7979
}
8080

gradle/libs.versions.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[versions]
2-
minecraft = "1.20.4"
2+
minecraft = "1.20.6"
33
junit = "5.9.1"
4-
mirror = "0.1.2"
4+
mirror = "0.2.0"
55
reflectionRemapper = "0.1.0"
66

77
paperweight = "1.7.1"
88
runPaper = "2.3.0"
9-
shadow = "8.1.1"
9+
shadow = "8.1.7"
1010
spotless = "6.17.0"
1111

1212
[libraries]
@@ -18,5 +18,5 @@ reflectionRemapper = { module = "xyz.jpenilla:reflection-remapper", version.ref
1818
[plugins]
1919
paper-userdev = { id = "io.papermc.paperweight.userdev", version.ref = "paperweight" }
2020
paper-run = { id = "xyz.jpenilla.run-paper", version.ref = "runPaper" }
21-
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }
21+
shadow = { id = "io.github.goooler.shadow", version.ref = "shadow" }
2222
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }

src/main/java/me/machinemaker/treasuremapsplus/RegistryOverride.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
*/
2020
package me.machinemaker.treasuremapsplus;
2121

22-
import com.mojang.serialization.Lifecycle;
2322
import it.unimi.dsi.fastutil.objects.Reference2IntMap;
2423
import java.lang.invoke.MethodHandle;
2524
import java.lang.invoke.MethodHandles;
@@ -35,7 +34,6 @@ public record RegistryOverride<T>(ResourceKey<? extends Registry<T>> registryKey
3534

3635
private static final MethodHandle TO_ID_MAP;
3736
private static final MethodHandle BY_VALUE_MAP;
38-
private static final MethodHandle LIFECYCLES_MAP;
3937

4038
private static final MethodHandle SET_HOLDER_VALUE;
4139

@@ -45,7 +43,6 @@ public record RegistryOverride<T>(ResourceKey<? extends Registry<T>> registryKey
4543
final MethodHandles.Lookup mappedRegistryLookup = MethodHandles.privateLookupIn(MappedRegistry.class, MethodHandles.lookup());
4644
TO_ID_MAP = mappedRegistryLookup.findGetter(MappedRegistry.class, remapper.remapFieldName(MappedRegistry.class, "toId"), Reference2IntMap.class);
4745
BY_VALUE_MAP = mappedRegistryLookup.findGetter(MappedRegistry.class, remapper.remapFieldName(MappedRegistry.class, "byValue"), Map.class);
48-
LIFECYCLES_MAP = mappedRegistryLookup.findGetter(MappedRegistry.class, remapper.remapFieldName(MappedRegistry.class, "lifecycles"), Map.class);
4946

5047
final MethodHandles.Lookup referenceHolderLookup = MethodHandles.privateLookupIn(Holder.Reference.class, MethodHandles.lookup());
5148
SET_HOLDER_VALUE = referenceHolderLookup.findSetter(Holder.Reference.class, remapper.remapFieldName(Holder.Reference.class, "value"), Object.class);
@@ -63,7 +60,6 @@ public void override(final RegistryAccess access) {
6360
final int id = registry.getId(oldValue);
6461
swapToIdMap(registry, id, oldValue, this.value());
6562
swapByValueMap(registry, holder, oldValue, this.value());
66-
swapLifecyclesMap(registry, oldValue, this.value());
6763
swapInHolder(holder, this.value());
6864
}
6965

@@ -89,17 +85,6 @@ private static <T> void swapByValueMap(final Registry<T> registry, final Holder.
8985
}
9086
}
9187

92-
@SuppressWarnings("unchecked")
93-
private static <T> void swapLifecyclesMap(final Registry<T> registry, final T oldValue, final T newValue) {
94-
try {
95-
final Map<T, Lifecycle> map = (Map<T, Lifecycle>) LIFECYCLES_MAP.invoke(registry);
96-
map.remove(oldValue);
97-
map.put(newValue, Lifecycle.experimental());
98-
} catch (final Throwable e) {
99-
throw new RuntimeException("Could not get lifecycles map from " + registry, e);
100-
}
101-
}
102-
10388
private static <T> void swapInHolder(final Holder.Reference<T> holder, final T newValue) {
10489
try {
10590
SET_HOLDER_VALUE.invoke(holder, newValue);

src/main/java/me/machinemaker/treasuremapsplus/TreasureMapsPlus.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@
2222
import java.util.Collections;
2323
import java.util.List;
2424
import me.machinemaker.treasuremapsplus.listener.PlayerInteract;
25-
import me.machinemaker.treasuremapsplus.loot.ExplorationMapItemFunctionOverride;
26-
import me.machinemaker.treasuremapsplus.villager.VillagerTradeOverride;
25+
import me.machinemaker.treasuremapsplus.listener.ServerLoad;
2726
import net.kyori.adventure.text.Component;
2827
import net.kyori.adventure.text.format.TextDecoration;
2928
import net.kyori.adventure.text.minimessage.MiniMessage;
30-
import net.minecraft.server.MinecraftServer;
3129
import org.bukkit.NamespacedKey;
3230
import org.bukkit.plugin.java.JavaPlugin;
31+
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
3332

3433
public final class TreasureMapsPlus extends JavaPlugin {
3534

@@ -42,7 +41,7 @@ public final class TreasureMapsPlus extends JavaPlugin {
4241
private final boolean replaceMonuments;
4342
private final boolean replaceMansions;
4443

45-
private final ReplacementResult result;
44+
private @MonotonicNonNull ReplacementResult result;
4645

4746
public TreasureMapsPlus() throws Exception {
4847
this.saveDefaultConfig();
@@ -52,19 +51,12 @@ public TreasureMapsPlus() throws Exception {
5251
this.replaceChests = this.getConfig().getBoolean("replace.chests", false);
5352
this.replaceMonuments = this.getConfig().getBoolean("replace.villagers.monument", false);
5453
this.replaceMansions = this.getConfig().getBoolean("replace.villagers.mansion", false);
55-
final ExplorationMapItemFunctionOverride mapFunctionOverride = new ExplorationMapItemFunctionOverride(MinecraftServer.getServer().registryAccess(), this);
56-
mapFunctionOverride.override();
57-
DatapackOverride.deleteLeftoversAndReload(); // must reload resources override to count how many were changed
58-
final VillagerTradeOverride villagerTradeOverride = new VillagerTradeOverride(this);
59-
final int replacedTrades = villagerTradeOverride.override();
60-
this.result = new ReplacementResult(mapFunctionOverride.replaceCount(), replacedTrades);
6154
}
6255

6356
@Override
6457
public void onEnable() {
6558
this.getServer().getPluginManager().registerEvents(new PlayerInteract(), this);
66-
this.getSLF4JLogger().info("Found and replaced {} loot tables with a treasure map", this.result.lootTableCount);
67-
this.getSLF4JLogger().info("Found and replaced {} villager trades with a treasure map", this.result.tradeCount);
59+
this.getServer().getPluginManager().registerEvents(new ServerLoad(this), this);
6860

6961
}
7062

src/main/java/me/machinemaker/treasuremapsplus/Utils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import net.minecraft.server.MinecraftServer;
2828
import net.minecraft.server.level.ServerPlayer;
2929
import net.minecraft.world.level.storage.loot.functions.LootItemFunction;
30-
import net.minecraft.world.level.storage.loot.functions.SetNbtFunction;
30+
import net.minecraft.world.level.storage.loot.functions.SetCustomDataFunction;
3131
import org.bukkit.entity.Player;
3232
import org.bukkit.inventory.ItemStack;
3333

@@ -69,7 +69,7 @@ public static ItemStack getBukkitStackMirror(final net.minecraft.world.item.Item
6969

7070
@SuppressWarnings("deprecation")
7171
public static LootItemFunction.Builder createSetNbtFunction(final CompoundTag tag) {
72-
return SetNbtFunction.setTag(tag);
72+
return SetCustomDataFunction.setCustomData(tag);
7373
}
7474

7575
public static <T, E extends Throwable> T sneaky(final CheckedSupplier<T, E> supplier) {

src/main/java/me/machinemaker/treasuremapsplus/listener/PlayerInteract.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import me.machinemaker.treasuremapsplus.TreasureMapsPlus;
2525
import me.machinemaker.treasuremapsplus.Utils;
2626
import net.minecraft.core.registries.Registries;
27+
import net.minecraft.resources.ResourceKey;
2728
import net.minecraft.resources.ResourceLocation;
2829
import net.minecraft.server.level.ServerPlayer;
2930
import net.minecraft.tags.StructureTags;
@@ -33,6 +34,7 @@
3334
import net.minecraft.world.level.levelgen.structure.Structure;
3435
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
3536
import net.minecraft.world.level.storage.loot.LootParams;
37+
import net.minecraft.world.level.storage.loot.LootTable;
3638
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
3739
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
3840
import net.minecraft.world.phys.Vec3;
@@ -75,7 +77,7 @@ public void onEvent(final PlayerInteractEvent event) {
7577

7678
private static List<net.minecraft.world.item.ItemStack> rollLootTable(final ItemStack item, final ServerPlayer player) {
7779
boolean isChest = true;
78-
@Nullable ResourceLocation lootTable = null;
80+
@Nullable ResourceKey<LootTable> lootTable = null;
7981
final PersistentDataContainer pdc = item.getItemMeta().getPersistentDataContainer();
8082
final @Nullable String tagKey = pdc.get(TreasureMapsPlus.MAP_STRUCTURE_TAG_KEY, PersistentDataType.STRING);
8183
if (tagKey != null) {
@@ -95,7 +97,7 @@ private static List<net.minecraft.world.item.ItemStack> rollLootTable(final Item
9597

9698
final LootParams params = isChest ? createChestParams(player) : createEntityParams(player);
9799
final List<net.minecraft.world.item.ItemStack> items = new ArrayList<>();
98-
Utils.getServer().getLootData().getLootTable(lootTable).getRandomItems(params, items::add);
100+
Utils.getServer().reloadableRegistries().getLootTable(lootTable).getRandomItems(params, items::add);
99101
return items;
100102

101103
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* GNU General Public License v3
3+
*
4+
* TreasureMapsPlus, a plugin to alter treasure maps
5+
*
6+
* Copyright (C) 2024 Machine-Maker
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, version 3.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
package me.machinemaker.treasuremapsplus.listener;
21+
22+
import me.machinemaker.treasuremapsplus.DatapackOverride;
23+
import me.machinemaker.treasuremapsplus.TreasureMapsPlus;
24+
import me.machinemaker.treasuremapsplus.loot.ExplorationMapItemFunctionOverride;
25+
import me.machinemaker.treasuremapsplus.villager.VillagerTradeOverride;
26+
import net.minecraft.server.MinecraftServer;
27+
import org.bukkit.event.EventHandler;
28+
import org.bukkit.event.Listener;
29+
import org.bukkit.event.server.ServerLoadEvent;
30+
31+
public class ServerLoad implements Listener {
32+
33+
final TreasureMapsPlus plugin;
34+
35+
public ServerLoad(final TreasureMapsPlus plugin) {
36+
this.plugin = plugin;
37+
}
38+
39+
@EventHandler
40+
public void onEvent(final ServerLoadEvent event) {
41+
if (event.getType() == ServerLoadEvent.LoadType.STARTUP) {
42+
try {
43+
final ExplorationMapItemFunctionOverride mapFunctionOverride = new ExplorationMapItemFunctionOverride(MinecraftServer.getServer().registryAccess(), this.plugin);
44+
mapFunctionOverride.override();
45+
this.plugin.getSLF4JLogger().info("Reloading the server resources to apply treasure map changes...");
46+
DatapackOverride.deleteLeftoversAndReload();
47+
final VillagerTradeOverride villagerTradeOverride = new VillagerTradeOverride(this.plugin);
48+
final int replacedTrades = villagerTradeOverride.override();
49+
this.plugin.getSLF4JLogger().info("Found and replaced {} loot tables with a treasure map", mapFunctionOverride.replaceCount());
50+
this.plugin.getSLF4JLogger().info("Found and replaced {} villager trades with a treasure map", replacedTrades);
51+
} catch (final Exception ex) {
52+
throw new RuntimeException("Could not load this plugin", ex);
53+
}
54+
}
55+
}
56+
}

src/main/java/me/machinemaker/treasuremapsplus/loot/ExplorationMapItemFunctionOverride.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import com.google.common.collect.BiMap;
2323
import com.google.common.collect.HashBiMap;
24-
import com.mojang.serialization.Codec;
2524
import com.mojang.serialization.MapCodec;
2625
import io.papermc.paper.adventure.PaperAdventure;
2726
import java.util.List;
@@ -47,7 +46,7 @@
4746
public class ExplorationMapItemFunctionOverride {
4847

4948
@VisibleForTesting
50-
static final ResourceKey<LootItemFunctionType> EXPLORATION_FUNCTION_KEY = ResourceKey.create(Registries.LOOT_FUNCTION_TYPE, new ResourceLocation(ResourceLocation.DEFAULT_NAMESPACE, "exploration_map"));
49+
static final ResourceKey<LootItemFunctionType<?>> EXPLORATION_FUNCTION_KEY = ResourceKey.create(Registries.LOOT_FUNCTION_TYPE, new ResourceLocation(ResourceLocation.DEFAULT_NAMESPACE, "exploration_map"));
5150
private static final LootItemFunction.Builder SET_PDC_FUNCTION;
5251

5352
static {
@@ -61,7 +60,7 @@ public class ExplorationMapItemFunctionOverride {
6160

6261

6362
@VisibleForTesting
64-
final RegistryOverride<LootItemFunctionType> registryOverride;
63+
final RegistryOverride<LootItemFunctionType<?>> registryOverride;
6564
private final RegistryAccess access;
6665
private final List<Component> lore;
6766
private final boolean replaceChests;
@@ -72,17 +71,16 @@ public ExplorationMapItemFunctionOverride(final RegistryAccess registryAccess, f
7271
}
7372

7473
@VisibleForTesting
75-
@SuppressWarnings("unchecked")
7674
ExplorationMapItemFunctionOverride(final RegistryAccess registryAccess, final List<Component> lore, final boolean replaceChests) {
7775
this.access = registryAccess;
7876
this.lore = lore;
7977
this.replaceChests = replaceChests;
80-
final MapCodec.MapCodecCodec<ExplorationMapFunction> mapCodecCodec = (MapCodec.MapCodecCodec<ExplorationMapFunction>) LootItemFunctions.EXPLORATION_MAP.codec();
81-
final Codec<? extends LootItemFunction> replacementCodec = mapCodecCodec.codec().xmap(this::createSequenceFunction, this::retrieveExplorationFunction).codec();
78+
final MapCodec<ExplorationMapFunction> mapCodecCodec = LootItemFunctions.EXPLORATION_MAP.codec();
79+
final MapCodec<? extends LootItemFunction> replacementCodec = mapCodecCodec.xmap(this::createSequenceFunction, this::retrieveExplorationFunction);
8280
this.registryOverride = new RegistryOverride<>(
8381
Registries.LOOT_FUNCTION_TYPE,
8482
EXPLORATION_FUNCTION_KEY,
85-
new LootItemFunctionType(replacementCodec));
83+
new LootItemFunctionType<>(replacementCodec));
8684
}
8785

8886
public void override() {

src/main/java/me/machinemaker/treasuremapsplus/villager/VillagerTradeOverride.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Collection;
2626
import java.util.List;
2727
import java.util.Map;
28+
import java.util.Optional;
2829
import java.util.function.Function;
2930
import me.machinemaker.treasuremapsplus.TreasureMapsPlus;
3031
import me.machinemaker.treasuremapsplus.Utils;
@@ -36,6 +37,7 @@
3637
import net.minecraft.world.entity.npc.VillagerType;
3738
import net.minecraft.world.item.ItemStack;
3839
import net.minecraft.world.item.Items;
40+
import net.minecraft.world.item.trading.ItemCost;
3941
import net.minecraft.world.item.trading.MerchantOffer;
4042
import org.bukkit.persistence.PersistentDataType;
4143
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -133,7 +135,7 @@ private VillagerTrades.ItemListing createOverride(final VillagerTrades.ItemListi
133135
return this.replaceMonuments ? new OverrideListing(original, this::createStack) : original;
134136
} else if (name.endsWith("mansion")) {
135137
return this.replaceMansions ? new OverrideListing(original, this::createStack) : original;
136-
} else if (name.startsWith("filled_map.village_") || name.startsWith("filled_map.explorer_")) {
138+
} else if (name.startsWith("filled_map.village_") || name.startsWith("filled_map.explorer_") || name.endsWith(".trial_chambers")) {
137139
// skip these maps, no point in replacing them, it defeats their whole purpose
138140
return original;
139141
} else {
@@ -165,8 +167,8 @@ private record OverrideListing(VillagerTrades.ItemListing original, Function<Vil
165167
return null;
166168
}
167169
return new MerchantOffer(
168-
new ItemStack(Items.EMERALD, TREASURE_MAP_PROXY.emeraldCost(this.original)),
169-
new ItemStack(Items.COMPASS),
170+
new ItemCost(Items.EMERALD, TREASURE_MAP_PROXY.emeraldCost(this.original)),
171+
Optional.of(new ItemCost(Items.COMPASS)),
170172
this.mapStackCreator.apply(this.original),
171173
TREASURE_MAP_PROXY.maxUses(this.original),
172174
TREASURE_MAP_PROXY.villagerXp(this.original),

src/main/resources/paper-plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ name: TreasureMapsPlus
22
main: me.machinemaker.treasuremapsplus.TreasureMapsPlus
33
version: ${version}
44
author: Machine_Maker
5-
api-version: "1.20"
5+
api-version: "1.20.6"
66
load: STARTUP

0 commit comments

Comments
 (0)