From 123a24274ed9eade88d75b43067e0ea86a3b27f1 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Tue, 27 Sep 2022 18:45:33 +0100 Subject: [PATCH] port to 1.19.2 --- build.gradle | 4 +- gradle.properties | 10 +-- .../net/zestyblaze/nomadbooks/NomadBooks.java | 73 ++++++++++--------- .../nomadbooks/item/NomadBookItem.java | 37 +++++----- .../nomadbooks/mixin/LocalPlayerMixin.java | 5 +- .../nomadbooks/mixin/ServerPlayerMixin.java | 10 +-- src/main/resources/fabric.mod.json | 2 +- 7 files changed, 71 insertions(+), 70 deletions(-) diff --git a/build.gradle b/build.gradle index 19f18a6..e3b2c6c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '0.11-SNAPSHOT' + id 'fabric-loom' version '0.12.+' id 'maven-publish' } @@ -25,7 +25,7 @@ dependencies { //Parchment mappings loom.layered() { officialMojangMappings() - parchment("org.parchmentmc.data:parchment-1.18.2:2022.05.02@zip") + parchment("org.parchmentmc.data:parchment-1.19.2:2022.09.18@zip") } } diff --git a/gradle.properties b/gradle.properties index c7cb6b7..aa7a8cf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ org.gradle.jvmargs=-Xmx1G - minecraft_version=1.18.2 - loader_version=0.14.5 - mod_version = 1.0.1 + minecraft_version = 1.19.2 + loader_version = 0.14.9 + mod_version = 1.1.1-1.19.2 maven_group = net.zestyblaze - archives_base_name = nomadbooks-1.18 - fabric_version=0.51.1+1.18.2 + archives_base_name = nomadbooks + fabric_version = 0.61.0+1.19.2 diff --git a/src/main/java/net/zestyblaze/nomadbooks/NomadBooks.java b/src/main/java/net/zestyblaze/nomadbooks/NomadBooks.java index 878eb86..07a2446 100644 --- a/src/main/java/net/zestyblaze/nomadbooks/NomadBooks.java +++ b/src/main/java/net/zestyblaze/nomadbooks/NomadBooks.java @@ -2,8 +2,7 @@ import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.item.v1.FabricItemSettings; -import net.fabricmc.fabric.api.loot.v1.FabricLootPoolBuilder; -import net.fabricmc.fabric.api.loot.v1.event.LootTableLoadingCallback; +import net.fabricmc.fabric.api.loot.v2.LootTableEvents; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.minecraft.Util; import net.minecraft.core.Registry; @@ -17,6 +16,8 @@ import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.MaterialColor; +import net.minecraft.world.level.storage.loot.LootPool; +import net.minecraft.world.level.storage.loot.LootPool.Builder; import net.minecraft.world.level.storage.loot.entries.LootItem; import net.minecraft.world.level.storage.loot.functions.SetNbtFunction; import net.minecraft.world.level.storage.loot.providers.number.ConstantValue; @@ -71,67 +72,67 @@ public void onInitialize() { CREATIVE_NOMAD_BOOK = registerItem(new NomadBookItem(new FabricItemSettings().maxCount(1).group(CreativeModeTab.TAB_MISC).rarity(Rarity.RARE).fireproof()), "creative_nomad_book"); UniformGenerator lootTableRange = UniformGenerator.between(0, 1); - LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, supplier, setter) -> { + LootTableEvents.MODIFY.register((resourceManager, lootManager, id, supplier, setter) -> { if (DUNGEON_CHEST_LOOT_TABLE_ID.equals(id)) { - FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder() - .rolls(lootTableRange) - .withEntry(LootItem.lootTableItem(GRASS_PAGE).build()); + LootPool.Builder poolBuilder = LootPool.lootPool() + .setRolls(lootTableRange) + .add(LootItem.lootTableItem(GRASS_PAGE)); - supplier.withPool(poolBuilder.build()); + supplier.withPool(poolBuilder); } if (MINESHAFT_CHEST_LOOT_TABLE_ID.equals(id)) { - FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder() - .rolls(lootTableRange) - .withEntry(LootItem.lootTableItem(GRASS_PAGE).build()); + LootPool.Builder poolBuilder = LootPool.lootPool() + .setRolls(lootTableRange) + .add(LootItem.lootTableItem(GRASS_PAGE)); - supplier.withPool(poolBuilder.build()); + supplier.withPool(poolBuilder); } if (TEMPLE_CHEST_LOOT_TABLE_ID.equals(id)) { - FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder() - .rolls(lootTableRange) - .withEntry(LootItem.lootTableItem(GRASS_PAGE).build()); + LootPool.Builder poolBuilder = LootPool.lootPool() + .setRolls(lootTableRange) + .add(LootItem.lootTableItem(GRASS_PAGE)); - supplier.withPool(poolBuilder.build()); + supplier.withPool(poolBuilder); } if (TREASURE_CHEST_LOOT_TABLE_ID.equals(id)) { - FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder() - .rolls(lootTableRange) - .withEntry(LootItem.lootTableItem(GRASS_PAGE).build()); + LootPool.Builder poolBuilder = LootPool.lootPool() + .setRolls(lootTableRange) + .add(LootItem.lootTableItem(GRASS_PAGE)); - supplier.withPool(poolBuilder.build()); + supplier.withPool(poolBuilder); } if (OUTPOST_CHEST_LOOT_TABLE_ID.equals(id)) { - FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder() - .rolls(lootTableRange) - .withEntry(LootItem.lootTableItem(GRASS_PAGE).build()); + LootPool.Builder poolBuilder = LootPool.lootPool() + .setRolls(lootTableRange) + .add(LootItem.lootTableItem(GRASS_PAGE)); - supplier.withPool(poolBuilder.build()); + supplier.withPool(poolBuilder); } if (CARTOGRAPHER_CHEST_LOOT_TABLE_ID.equals(id)) { - FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder() - .rolls(lootTableRange) - .withEntry(LootItem.lootTableItem(GRASS_PAGE).build()); + LootPool.Builder poolBuilder = LootPool.lootPool() + .setRolls(lootTableRange) + .add(LootItem.lootTableItem(GRASS_PAGE)); - supplier.withPool(poolBuilder.build()); + supplier.withPool(poolBuilder); } if (STRONGHOLD_LIBRARY_CHEST_LOOT_TABLE_ID.equals(id)) { - FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder() - .rolls(UniformGenerator.between(0, 3)) - .withEntry(LootItem.lootTableItem(GRASS_PAGE).build()); + LootPool.Builder poolBuilder = LootPool.lootPool() + .setRolls(UniformGenerator.between(0, 3)) + .add(LootItem.lootTableItem(GRASS_PAGE)); - supplier.withPool(poolBuilder.build()); + supplier.withPool(poolBuilder); } if (BONUS_CHEST_LOOT_TABLE_ID.equals(id)) { - FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder() - .rolls(ConstantValue.exactly(1)) - .withEntry(LootItem.lootTableItem(NOMAD_BOOK).build()) - .withFunction(SetNbtFunction.setTag(Util.make(new CompoundTag(), (compoundTag) -> compoundTag.put(MODID, Util.make(new CompoundTag(), child -> { + LootPool.Builder poolBuilder = LootPool.lootPool() + .setRolls(ConstantValue.exactly(1)) + .add(LootItem.lootTableItem(NOMAD_BOOK)) + .apply(SetNbtFunction.setTag(Util.make(new CompoundTag(), (compoundTag) -> compoundTag.put(MODID, Util.make(new CompoundTag(), child -> { child.putInt("Height", 1); child.putInt("Width", 3); child.putString("Structure", NomadBookItem.defaultStructurePath); })))).build()); - supplier.withPool(poolBuilder.build()); + supplier.withPool(poolBuilder); } }); diff --git a/src/main/java/net/zestyblaze/nomadbooks/item/NomadBookItem.java b/src/main/java/net/zestyblaze/nomadbooks/item/NomadBookItem.java index 06a3bb8..a1bf5eb 100644 --- a/src/main/java/net/zestyblaze/nomadbooks/item/NomadBookItem.java +++ b/src/main/java/net/zestyblaze/nomadbooks/item/NomadBookItem.java @@ -9,7 +9,6 @@ import net.minecraft.nbt.*; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Style; -import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; @@ -26,9 +25,9 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager; import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager; import net.minecraft.world.level.material.Material; import net.zestyblaze.nomadbooks.NomadBooks; import net.zestyblaze.nomadbooks.block.NomadMushroomBlock; @@ -79,7 +78,7 @@ public InteractionResult useOn(UseOnContext context) { BlockPos p = pos.offset(new BlockPos(x, y, z)); BlockState bs = context.getLevel().getBlockState(p); if (!(isBlockReplaceable(bs) || isBlockUnderwaterReplaceable(bs) && tags.getList("Upgrades", NbtType.STRING).contains(StringTag.valueOf("aquatic_membrane")))) { - Objects.requireNonNull(context.getPlayer()).displayClientMessage(new TranslatableComponent("error.nomadbooks.no_space"), true); + Objects.requireNonNull(context.getPlayer()).displayClientMessage(Component.translatable("error.nomadbooks.no_space"), true); return InteractionResult.FAIL; } } @@ -114,7 +113,7 @@ public InteractionResult useOn(UseOnContext context) { BlockPos p = pos.offset(new BlockPos(x, -1, z)); BlockState bs = context.getLevel().getBlockState(p); if (isBlockReplaceable(bs)) { - Objects.requireNonNull(context.getPlayer()).displayClientMessage(new TranslatableComponent("error.nomadbooks.invalid_surface"), true); + Objects.requireNonNull(context.getPlayer()).displayClientMessage(Component.translatable("error.nomadbooks.invalid_surface"), true); return InteractionResult.FAIL; } } @@ -189,10 +188,10 @@ public InteractionResultHolder use(@NotNull Level world, Player user, if (user.isShiftKeyDown()) { // switch boundaries display on or off if (tags.getBoolean("DisplayBoundaries")) { - user.displayClientMessage(new TranslatableComponent("info.nomadbooks.display_boundaries_off"), true); + user.displayClientMessage(Component.translatable("info.nomadbooks.display_boundaries_off"), true); tags.putBoolean("DisplayBoundaries", false); } else { - user.displayClientMessage(new TranslatableComponent("info.nomadbooks.display_boundaries_on"), true); + user.displayClientMessage(Component.translatable("info.nomadbooks.display_boundaries_on"), true); tags.putBoolean("DisplayBoundaries", true); } @@ -215,12 +214,12 @@ public InteractionResultHolder use(@NotNull Level world, Player user, } world.playSound(null, pos.getX() + width / 2 + 0.5, pos.getY(), pos.getZ() + width / 2 + 0.5, SoundEvents.ENDERMAN_TELEPORT, SoundSource.PLAYERS, 1f, 1f); } else { - user.displayClientMessage(new TranslatableComponent("error.nomadbooks.camp_too_far"), true); + user.displayClientMessage(Component.translatable("error.nomadbooks.camp_too_far"), true); } return InteractionResultHolder.success(itemStack); } } else { - user.displayClientMessage(new TranslatableComponent("error.nomadbooks.different_dimension"), true); + user.displayClientMessage(Component.translatable("error.nomadbooks.different_dimension"), true); return InteractionResultHolder.success(itemStack); } @@ -232,7 +231,7 @@ public InteractionResultHolder use(@NotNull Level world, Player user, if (!world.isClientSide) { ServerLevel serverLevel = (ServerLevel) world; - StructureManager structureManager = serverLevel.getStructureManager(); + StructureTemplateManager structureTemplateManager = serverLevel.getStructureManager(); // free beds so they don't redeploy as occupied for (int x = 0; x < width; x++) { @@ -251,14 +250,14 @@ public InteractionResultHolder use(@NotNull Level world, Player user, // save structure StructureTemplate structure; try { - structure = structureManager.getOrCreate(new ResourceLocation(structurePath)); + structure = structureTemplateManager.getOrCreate(new ResourceLocation(structurePath)); } catch (ResourceLocationException var8) { return InteractionResultHolder.success(itemStack); } structure.fillFromWorld(world, pos.offset(new BlockPos(0, 0, 0)), new BlockPos(width, height, width), true, Blocks.STRUCTURE_VOID); structure.setAuthor(user.getScoreboardName()); - structureManager.save(new ResourceLocation(structurePath)); + structureTemplateManager.save(new ResourceLocation(structurePath)); // clear block entities for (int x = 0; x < width; x++) { @@ -362,14 +361,14 @@ public void appendHoverText(ItemStack stack, Level world, List toolti // height, width and upgrades int height = tags.getInt("Height"); int width = tags.getInt("Width"); - tooltip.add(new TranslatableComponent("item.nomadbooks.nomad_book.tooltip.height", height).setStyle(Style.EMPTY.withColor(ChatFormatting.GRAY))); - tooltip.add(new TranslatableComponent("item.nomadbooks.nomad_book.tooltip.width", width).setStyle(Style.EMPTY.withColor(ChatFormatting.GRAY))); + tooltip.add(Component.translatable("item.nomadbooks.nomad_book.tooltip.height", height).setStyle(Style.EMPTY.withColor(ChatFormatting.GRAY))); + tooltip.add(Component.translatable("item.nomadbooks.nomad_book.tooltip.width", width).setStyle(Style.EMPTY.withColor(ChatFormatting.GRAY))); ListTag upgrades = tags.getList("Upgrades", NbtType.STRING); - upgrades.forEach(tag -> tooltip.add(new TranslatableComponent("upgrade.nomadbooks."+tag.getAsString()).setStyle(Style.EMPTY.withColor(ChatFormatting.DARK_AQUA)))); + upgrades.forEach(tag -> tooltip.add(Component.translatable("upgrade.nomadbooks."+tag.getAsString()).setStyle(Style.EMPTY.withColor(ChatFormatting.DARK_AQUA)))); // if inked, show progress if (tags.getBoolean("Inked")) { - tooltip.add(new TranslatableComponent("item.nomadbooks.nomad_book.tooltip.itinerant_ink", tags.getInt("InkProgress"), tags.getInt("InkGoal")).setStyle(Style.EMPTY.withColor(ChatFormatting.BLUE))); + tooltip.add(Component.translatable("item.nomadbooks.nomad_book.tooltip.itinerant_ink", tags.getInt("InkProgress"), tags.getInt("InkGoal")).setStyle(Style.EMPTY.withColor(ChatFormatting.BLUE))); } // camp coordinates if deployed if (stack.getOrCreateTag().getFloat(NomadBooks.MODID+":deployed") == 1.0f) { @@ -379,16 +378,16 @@ public void appendHoverText(ItemStack stack, Level world, List toolti Optional> dimension = Level.RESOURCE_KEY_CODEC.parse(NbtOps.INSTANCE, tags.get("Dimension")).result(); if (dimension.isPresent() && dimension.get() == world.dimension()) { - tooltip.add(new TranslatableComponent("item.nomadbooks.nomad_book.tooltip.position", pos.getX()+", "+pos.getY()+", "+pos.getZ()).setStyle(Style.EMPTY.withColor(ChatFormatting.DARK_GRAY))); + tooltip.add(Component.translatable("item.nomadbooks.nomad_book.tooltip.position", pos.getX()+", "+pos.getY()+", "+pos.getZ()).setStyle(Style.EMPTY.withColor(ChatFormatting.DARK_GRAY))); } else { - tooltip.add(new TranslatableComponent("item.nomadbooks.nomad_book.tooltip.position", pos.getX()+", "+pos.getY()+", "+pos.getZ()).setStyle(Style.EMPTY.withColor(ChatFormatting.DARK_GRAY).applyFormats(ChatFormatting.OBFUSCATED))); + tooltip.add(Component.translatable("item.nomadbooks.nomad_book.tooltip.position", pos.getX()+", "+pos.getY()+", "+pos.getZ()).setStyle(Style.EMPTY.withColor(ChatFormatting.DARK_GRAY).applyFormats(ChatFormatting.OBFUSCATED))); } -// tooltip.add(new TranslatableComponent("item.nomadbooks.nomad_book.tooltip.dimension", dimension).setStyle(Style.EMPTY.withColor(ChatFormatting.DARK_GRAY))); +// tooltip.add(Component.translatable("item.nomadbooks.nomad_book.tooltip.dimension", dimension).setStyle(Style.EMPTY.withColor(ChatFormatting.DARK_GRAY))); } // displaying boundaries if (stack.getItem() instanceof NomadBookItem) { if (tags.getBoolean("DisplayBoundaries")) { - tooltip.add(new TranslatableComponent("item.nomadbooks.nomad_book.tooltip.boundaries_display").setStyle(Style.EMPTY.withColor(ChatFormatting.GREEN).withItalic(true))); + tooltip.add(Component.translatable("item.nomadbooks.nomad_book.tooltip.boundaries_display").setStyle(Style.EMPTY.withColor(ChatFormatting.GREEN).withItalic(true))); } } } diff --git a/src/main/java/net/zestyblaze/nomadbooks/mixin/LocalPlayerMixin.java b/src/main/java/net/zestyblaze/nomadbooks/mixin/LocalPlayerMixin.java index 944ceb3..ae63e18 100644 --- a/src/main/java/net/zestyblaze/nomadbooks/mixin/LocalPlayerMixin.java +++ b/src/main/java/net/zestyblaze/nomadbooks/mixin/LocalPlayerMixin.java @@ -9,6 +9,7 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtUtils; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.entity.player.ProfilePublicKey; import net.zestyblaze.nomadbooks.NomadBooks; import net.zestyblaze.nomadbooks.client.NomadBooksClient; import net.zestyblaze.nomadbooks.item.NomadBookItem; @@ -20,8 +21,8 @@ @Mixin(LocalPlayer.class) public abstract class LocalPlayerMixin extends AbstractClientPlayer { - public LocalPlayerMixin(ClientLevel clientLevel, GameProfile gameProfile) { - super(clientLevel, gameProfile); + public LocalPlayerMixin(ClientLevel clientLevel, GameProfile gameProfile, ProfilePublicKey profilePublicKey) { + super(clientLevel, gameProfile, profilePublicKey); } @Inject(method = "tick", at = @At("HEAD")) diff --git a/src/main/java/net/zestyblaze/nomadbooks/mixin/ServerPlayerMixin.java b/src/main/java/net/zestyblaze/nomadbooks/mixin/ServerPlayerMixin.java index 635c2de..edd096e 100644 --- a/src/main/java/net/zestyblaze/nomadbooks/mixin/ServerPlayerMixin.java +++ b/src/main/java/net/zestyblaze/nomadbooks/mixin/ServerPlayerMixin.java @@ -10,12 +10,12 @@ import net.minecraft.nbt.StringTag; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Style; -import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.player.ProfilePublicKey; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.zestyblaze.nomadbooks.NomadBooks; @@ -33,11 +33,11 @@ public abstract class ServerPlayerMixin extends Player { @Shadow public abstract void displayClientMessage(@NotNull Component chatComponent, boolean actionBar); - public ServerPlayerMixin(Level level, BlockPos blockPos, float f, GameProfile gameProfile) { - super(level, blockPos, f, gameProfile); + public ServerPlayerMixin(Level level, BlockPos blockPos, float f, GameProfile gameProfile, ProfilePublicKey profilePublicKey) { + super(level, blockPos, f, gameProfile, profilePublicKey); } - @Inject(method = "doTick", at = @At(value = "FIELD", target = "Lnet/minecraft/advancements/CriteriaTriggers;LOCATION:Lnet/minecraft/advancements/critereon/LocationTrigger;")) + @Inject(method = "doTick", at = @At(value = "FIELD", target = "Lnet/minecraft/advancements/CriteriaTriggers;LOCATION:Lnet/minecraft/advancements/critereon/PlayerTrigger;")) private void enterBiome(CallbackInfo info) { for(int i = 0; i < this.getInventory().getContainerSize(); ++i) { ItemStack itemStack = this.getInventory().getItem(i); @@ -69,7 +69,7 @@ private void enterBiome(CallbackInfo info) { tags.put("CampPos", NbtUtils.writeBlockPos(pos)); // show a chat message to the player this.playNotifySound(SoundEvents.PLAYER_LEVELUP, SoundSource.PLAYERS, 0.1f, 0.75f); - this.displayClientMessage(new TranslatableComponent("info.nomadbooks.itinerant_ink_done", tags.getInt("Width")).setStyle(Style.EMPTY.withColor(ChatFormatting.BLUE)), false); + this.displayClientMessage(Component.translatable("info.nomadbooks.itinerant_ink_done", tags.getInt("Width")).setStyle(Style.EMPTY.withColor(ChatFormatting.BLUE)), false); } else { visitedBiomes.add(biome); tags.put("VisitedBiomes", visitedBiomes); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 3250c95..1b34d17 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -34,7 +34,7 @@ "depends": { "fabricloader": ">=0.12.12", "fabric": "*", - "minecraft": "1.18.x", + "minecraft": "1.19.2", "java": ">=17" } }