From 90576fa843b5033f5065c3277ee154e02e81fed4 Mon Sep 17 00:00:00 2001 From: modmuss Date: Mon, 30 Dec 2024 19:53:51 +0000 Subject: [PATCH] Update to 1.21.4: mod (#243) --- develop/items/first-item.md | 2 +- reference/gradle.properties | 2 +- .../docs/datagen/EnchantmentGenerator.java | 2 +- ...abricDocsReferenceAdvancementProvider.java | 7 +- .../FabricDocsReferenceRecipeProvider.java | 99 +++++++++++-------- .../rendering/DrawContextExampleScreen.java | 5 +- .../rendering/HudRenderingEntrypoint.java | 2 +- .../RenderingConceptsEntrypoint.java | 4 +- .../docs/sound/DynamicSoundManager.java | 2 +- .../recipe/crafting_table.json | 4 +- .../fabric-docs-reference/recipe/dirt.json | 4 +- .../fabric-docs-reference/recipe/loom.json | 8 +- .../recipe/oak_door.json | 4 +- .../recipe/wheat_from_smelting_bread.json | 4 +- .../recipe/wheat_from_smelting_cookie.json | 4 +- .../recipe/wheat_from_smelting_hay_block.json | 4 +- .../com/example/docs/block/ModBlocks.java | 17 +++- .../docs/block/entity/ModBlockEntities.java | 6 +- .../FabricDocsReferenceDamageTypes.java | 11 ++- .../com/example/docs/damage/TaterBlock.java | 10 +- .../com/example/docs/effect/TaterEffect.java | 5 +- .../docs/event/FabricDocsReferenceEvents.java | 7 +- .../java/com/example/docs/item/ModItems.java | 65 +++++++----- .../docs/item/armor/ModArmorMaterials.java | 59 ++++------- .../example/docs/item/custom/CounterItem.java | 9 +- .../docs/item/custom/LightningStick.java | 10 +- .../docs/item/tool/GuiditeMaterial.java | 70 +++---------- .../docs/mixin/event/SheepEntityMixin.java | 2 +- .../payload/EngineSoundInstancePacket.java | 2 +- .../potion/FabricDocsReferencePotions.java | 2 +- 30 files changed, 201 insertions(+), 231 deletions(-) diff --git a/develop/items/first-item.md b/develop/items/first-item.md index 84678c998..384f0ab03 100644 --- a/develop/items/first-item.md +++ b/develop/items/first-item.md @@ -121,7 +121,7 @@ For example, if you want to make your item compostable, you can use the `Compost @[code transcludeWith=:::_10](@/reference/latest/src/main/java/com/example/docs/item/ModItems.java) -Alternatively, if you want to make your item a fuel, you can use the `FuelRegistry` class: +Alternatively, if you want to make your item a fuel, you can use the `FuelRegistryEvents.BUILD` event: @[code transcludeWith=:::_11](@/reference/latest/src/main/java/com/example/docs/item/ModItems.java) diff --git a/reference/gradle.properties b/reference/gradle.properties index cafa20b46..ccc1363e3 100644 --- a/reference/gradle.properties +++ b/reference/gradle.properties @@ -1,4 +1,4 @@ org.gradle.jvmargs=-Xmx1G org.gradle.parallel=true -loader_version=0.16.8 \ No newline at end of file +loader_version=0.16.9 \ No newline at end of file diff --git a/reference/latest/src/client/java/com/example/docs/datagen/EnchantmentGenerator.java b/reference/latest/src/client/java/com/example/docs/datagen/EnchantmentGenerator.java index 8232ec86b..c81da067b 100644 --- a/reference/latest/src/client/java/com/example/docs/datagen/EnchantmentGenerator.java +++ b/reference/latest/src/client/java/com/example/docs/datagen/EnchantmentGenerator.java @@ -31,7 +31,7 @@ protected void configure(RegistryWrapper.WrapperLookup registries, Entries entri // Our new enchantment, "Thundering." register(entries, ModEnchantmentEffects.THUNDERING, Enchantment.builder( Enchantment.definition( - registries.getWrapperOrThrow(RegistryKeys.ITEM).getOrThrow(ItemTags.WEAPON_ENCHANTABLE), + registries.getOrThrow(RegistryKeys.ITEM).getOrThrow(ItemTags.WEAPON_ENCHANTABLE), // this is the "weight" or probability of our enchantment showing up in the table 10, // the maximum level of the enchantment diff --git a/reference/latest/src/client/java/com/example/docs/datagen/FabricDocsReferenceAdvancementProvider.java b/reference/latest/src/client/java/com/example/docs/datagen/FabricDocsReferenceAdvancementProvider.java index 784d4fabd..cb5e421bf 100644 --- a/reference/latest/src/client/java/com/example/docs/datagen/FabricDocsReferenceAdvancementProvider.java +++ b/reference/latest/src/client/java/com/example/docs/datagen/FabricDocsReferenceAdvancementProvider.java @@ -9,7 +9,9 @@ import net.minecraft.advancement.AdvancementFrame; import net.minecraft.advancement.criterion.ConsumeItemCriterion; import net.minecraft.advancement.criterion.InventoryChangedCriterion; +import net.minecraft.item.Item; import net.minecraft.item.Items; +import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.RegistryWrapper; import net.minecraft.text.Text; import net.minecraft.util.Identifier; @@ -49,6 +51,7 @@ public void generateAdvancement(RegistryWrapper.WrapperLookup wrapperLookup, Con .build(consumer, FabricDocsReference.MOD_ID + "/get_dirt"); // :::datagen-advancements:simple-advancement // :::datagen-advancements:second-advancement + final RegistryWrapper.Impl itemLookup = wrapperLookup.getOrThrow(RegistryKeys.ITEM); AdvancementEntry appleAndBeef = Advancement.Builder.create() .parent(getDirt) .display( @@ -61,8 +64,8 @@ public void generateAdvancement(RegistryWrapper.WrapperLookup wrapperLookup, Con true, false ) - .criterion("ate_apple", ConsumeItemCriterion.Conditions.item(Items.APPLE)) - .criterion("ate_cooked_beef", ConsumeItemCriterion.Conditions.item(Items.COOKED_BEEF)) + .criterion("ate_apple", ConsumeItemCriterion.Conditions.item(wrapperLookup.getOrThrow(RegistryKeys.ITEM), Items.APPLE)) + .criterion("ate_cooked_beef", ConsumeItemCriterion.Conditions.item(itemLookup, Items.COOKED_BEEF)) .build(consumer, FabricDocsReference.MOD_ID + "/apple_and_beef"); // :::datagen-advancements:second-advancement // :::datagen-advancements:custom-criteria-advancement diff --git a/reference/latest/src/client/java/com/example/docs/datagen/FabricDocsReferenceRecipeProvider.java b/reference/latest/src/client/java/com/example/docs/datagen/FabricDocsReferenceRecipeProvider.java index 72ab5493e..0e5256115 100644 --- a/reference/latest/src/client/java/com/example/docs/datagen/FabricDocsReferenceRecipeProvider.java +++ b/reference/latest/src/client/java/com/example/docs/datagen/FabricDocsReferenceRecipeProvider.java @@ -4,12 +4,13 @@ import java.util.List; import java.util.concurrent.CompletableFuture; -import net.minecraft.data.server.recipe.RecipeExporter; -import net.minecraft.data.server.recipe.ShapedRecipeJsonBuilder; -import net.minecraft.data.server.recipe.ShapelessRecipeJsonBuilder; +import net.minecraft.data.recipe.RecipeExporter; +import net.minecraft.data.recipe.RecipeGenerator; +import net.minecraft.item.Item; import net.minecraft.item.Items; import net.minecraft.recipe.Ingredient; import net.minecraft.recipe.book.RecipeCategory; +import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.RegistryWrapper; import net.minecraft.registry.tag.ItemTags; @@ -22,46 +23,58 @@ public FabricDocsReferenceRecipeProvider(FabricDataOutput output, CompletableFut } @Override - public void generate(RecipeExporter recipeExporter) { - // :::datagen-recipes:provider - // :::datagen-recipes:shapeless - ShapelessRecipeJsonBuilder.create(RecipeCategory.BUILDING_BLOCKS, Items.DIRT) // You can also specify an int to produce more than one - .input(Items.COARSE_DIRT) // You can also specify an int to require more than one, or a tag to accept multiple things - // Create an advancement that gives you the recipe - .criterion(FabricRecipeProvider.hasItem(Items.COARSE_DIRT), FabricRecipeProvider.conditionsFromItem(Items.COARSE_DIRT)) - .offerTo(recipeExporter); - // :::datagen-recipes:shapeless - // :::datagen-recipes:shaped - ShapedRecipeJsonBuilder.create(RecipeCategory.MISC, Items.CRAFTING_TABLE, 4) - .pattern("ll") - .pattern("ll") - .input('l', ItemTags.LOGS) // 'l' means "any log" - .group("multi_bench") // Put it in a group called "multi_bench" - groups are shown in one slot in the recipe book - .criterion(FabricRecipeProvider.hasItem(Items.CRAFTING_TABLE), FabricRecipeProvider.conditionsFromItem(Items.CRAFTING_TABLE)) - .offerTo(recipeExporter); - ShapedRecipeJsonBuilder.create(RecipeCategory.MISC, Items.LOOM, 4) - .pattern("ww") - .pattern("ll") - .input('w', ItemTags.WOOL) // 'w' means "any wool" - .input('l', ItemTags.LOGS) - .group("multi_bench") - .criterion(FabricRecipeProvider.hasItem(Items.LOOM), FabricRecipeProvider.conditionsFromItem(Items.LOOM)) - .offerTo(recipeExporter); - FabricRecipeProvider.createDoorRecipe(Items.OAK_DOOR, Ingredient.ofItems(Items.OAK_BUTTON)) // Using a helper method! - .criterion(FabricRecipeProvider.hasItem(Items.OAK_BUTTON), FabricRecipeProvider.conditionsFromItem(Items.OAK_BUTTON)) - .offerTo(recipeExporter); - // :::datagen-recipes:shaped - // :::datagen-recipes:other - FabricRecipeProvider.offerSmelting(recipeExporter, - List.of(Items.BREAD, Items.COOKIE, Items.HAY_BLOCK), // Inputs - RecipeCategory.FOOD, // Category - Items.WHEAT, // Output - 0.1f, // Experience - 300, // Cooking time - "food_to_wheat" // group - ); - // :::datagen-recipes:other - // :::datagen-recipes:provider + protected RecipeGenerator getRecipeGenerator(RegistryWrapper.WrapperLookup registryLookup, RecipeExporter exporter) { + return new RecipeGenerator(registryLookup, exporter) { + @Override + public void generate() { + RegistryWrapper.Impl itemLookup = registries.getOrThrow(RegistryKeys.ITEM); + // :::datagen-recipes:provider + // :::datagen-recipes:shapeless + + createShapeless(RecipeCategory.BUILDING_BLOCKS, Items.DIRT) // You can also specify an int to produce more than one + .input(Items.COARSE_DIRT) // You can also specify an int to require more than one, or a tag to accept multiple things + // Create an advancement that gives you the recipe + .criterion(hasItem(Items.COARSE_DIRT), conditionsFromItem(Items.COARSE_DIRT)) + .offerTo(exporter); + // :::datagen-recipes:shapeless + // :::datagen-recipes:shaped + createShaped(RecipeCategory.MISC, Items.CRAFTING_TABLE, 4) + .pattern("ll") + .pattern("ll") + .input('l', ItemTags.LOGS) // 'l' means "any log" + .group("multi_bench") // Put it in a group called "multi_bench" - groups are shown in one slot in the recipe book + .criterion(hasItem(Items.CRAFTING_TABLE), conditionsFromItem(Items.CRAFTING_TABLE)) + .offerTo(exporter); + createShaped(RecipeCategory.MISC, Items.LOOM, 4) + .pattern("ww") + .pattern("ll") + .input('w', ItemTags.WOOL) // 'w' means "any wool" + .input('l', ItemTags.LOGS) + .group("multi_bench") + .criterion(hasItem(Items.LOOM), conditionsFromItem(Items.LOOM)) + .offerTo(exporter); + createDoorRecipe(Items.OAK_DOOR, Ingredient.ofItems(Items.OAK_BUTTON)) // Using a helper method! + .criterion(hasItem(Items.OAK_BUTTON), conditionsFromItem(Items.OAK_BUTTON)) + .offerTo(exporter); + // :::datagen-recipes:shaped + // :::datagen-recipes:other + offerSmelting( + List.of(Items.BREAD, Items.COOKIE, Items.HAY_BLOCK), // Inputs + RecipeCategory.FOOD, // Category + Items.WHEAT, // Output + 0.1f, // Experience + 300, // Cooking time + "food_to_wheat" // group + ); + // :::datagen-recipes:other + // :::datagen-recipes:provider + } + }; + } + + @Override + public String getName() { + return "FabricDocsReferenceRecipeProvider"; } } // :::datagen-recipes:provider diff --git a/reference/latest/src/client/java/com/example/docs/rendering/DrawContextExampleScreen.java b/reference/latest/src/client/java/com/example/docs/rendering/DrawContextExampleScreen.java index 2f79aa2f7..f3412a136 100644 --- a/reference/latest/src/client/java/com/example/docs/rendering/DrawContextExampleScreen.java +++ b/reference/latest/src/client/java/com/example/docs/rendering/DrawContextExampleScreen.java @@ -2,6 +2,7 @@ import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.render.RenderLayer; import net.minecraft.text.Text; import net.minecraft.util.Identifier; @@ -57,14 +58,14 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { // :::5 Identifier texture = Identifier.of("minecraft", "textures/block/deepslate.png"); // texture, x, y, u, v, width, height, textureWidth, textureHeight - context.drawTexture(texture, 90, 90, 0, 0, 16, 16, 16, 16); + context.drawTexture(RenderLayer::getGuiTextured, texture, 90, 90, 0, 0, 16, 16, 16, 16); // :::5 // :::6 Identifier texture2 = Identifier.of("fabric-docs-reference", "textures/gui/test-uv-drawing.png"); int u = 10, v = 13, regionWidth = 14, regionHeight = 14; // texture, x, y, width, height, u, v, regionWidth, regionHeight, textureWidth, textureHeight - context.drawTexture(texture2, 90, 190, 14, 14, u, v, regionWidth, regionHeight, 256, 256); + context.drawTexture(RenderLayer::getGuiTextured, texture2, 90, 190, 14, 14, u, v, regionWidth, regionHeight, 256, 256); // :::6 // :::7 diff --git a/reference/latest/src/client/java/com/example/docs/rendering/HudRenderingEntrypoint.java b/reference/latest/src/client/java/com/example/docs/rendering/HudRenderingEntrypoint.java index d226f49fe..81f675956 100644 --- a/reference/latest/src/client/java/com/example/docs/rendering/HudRenderingEntrypoint.java +++ b/reference/latest/src/client/java/com/example/docs/rendering/HudRenderingEntrypoint.java @@ -20,7 +20,7 @@ public void onInitializeClient() { // "lerp" simply means "linear interpolation", which is a fancy way of saying "blend". float lerpedAmount = MathHelper.abs(MathHelper.sin(totalTickDelta / 50F)); - int lerpedColor = ColorHelper.Argb.lerp(lerpedAmount, color, targetColor); + int lerpedColor = ColorHelper.lerp(lerpedAmount, color, targetColor); // Draw a square with the lerped color. // x1, x2, y1, y2, z, color diff --git a/reference/latest/src/client/java/com/example/docs/rendering/RenderingConceptsEntrypoint.java b/reference/latest/src/client/java/com/example/docs/rendering/RenderingConceptsEntrypoint.java index 311ea2434..d1acc0de4 100644 --- a/reference/latest/src/client/java/com/example/docs/rendering/RenderingConceptsEntrypoint.java +++ b/reference/latest/src/client/java/com/example/docs/rendering/RenderingConceptsEntrypoint.java @@ -3,9 +3,9 @@ import com.mojang.blaze3d.systems.RenderSystem; import org.joml.Matrix4f; +import net.minecraft.client.gl.ShaderProgramKeys; import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.BufferRenderer; -import net.minecraft.client.render.GameRenderer; import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.VertexFormat; import net.minecraft.client.render.VertexFormats; @@ -73,7 +73,7 @@ public void onInitializeClient() { buffer.vertex(transformationMatrix, 20, 60, 5).color(0xFF414141); // We'll get to this bit in the next section. - RenderSystem.setShader(GameRenderer::getPositionColorProgram); + RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); // Draw the buffer onto the screen. diff --git a/reference/latest/src/client/java/com/example/docs/sound/DynamicSoundManager.java b/reference/latest/src/client/java/com/example/docs/sound/DynamicSoundManager.java index a8650d34b..a1fc96e14 100644 --- a/reference/latest/src/client/java/com/example/docs/sound/DynamicSoundManager.java +++ b/reference/latest/src/client/java/com/example/docs/sound/DynamicSoundManager.java @@ -56,7 +56,7 @@ public void stop(T soundInstance) { public Optional getPlayingSoundInstance(SoundEvent soundEvent) { for (var activeSound : this.activeSounds) { // SoundInstances use their SoundEvent's id by default - if (activeSound.getId().equals(soundEvent.getId())) { + if (activeSound.getId().equals(soundEvent.id())) { return Optional.of(activeSound); } } diff --git a/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/crafting_table.json b/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/crafting_table.json index a7712f67d..ccd5680a3 100644 --- a/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/crafting_table.json +++ b/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/crafting_table.json @@ -3,9 +3,7 @@ "category": "misc", "group": "multi_bench", "key": { - "l": { - "tag": "minecraft:logs" - } + "l": "#minecraft:logs" }, "pattern": [ "ll", diff --git a/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/dirt.json b/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/dirt.json index e864fc682..93967858f 100644 --- a/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/dirt.json +++ b/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/dirt.json @@ -2,9 +2,7 @@ "type": "minecraft:crafting_shapeless", "category": "building", "ingredients": [ - { - "item": "minecraft:coarse_dirt" - } + "minecraft:coarse_dirt" ], "result": { "count": 1, diff --git a/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/loom.json b/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/loom.json index 013eac197..49c84c1db 100644 --- a/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/loom.json +++ b/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/loom.json @@ -3,12 +3,8 @@ "category": "misc", "group": "multi_bench", "key": { - "l": { - "tag": "minecraft:logs" - }, - "w": { - "tag": "minecraft:wool" - } + "l": "#minecraft:logs", + "w": "#minecraft:wool" }, "pattern": [ "ww", diff --git a/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/oak_door.json b/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/oak_door.json index 477fcc1d4..fdc8c074d 100644 --- a/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/oak_door.json +++ b/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/oak_door.json @@ -2,9 +2,7 @@ "type": "minecraft:crafting_shaped", "category": "redstone", "key": { - "#": { - "item": "minecraft:oak_button" - } + "#": "minecraft:oak_button" }, "pattern": [ "##", diff --git a/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/wheat_from_smelting_bread.json b/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/wheat_from_smelting_bread.json index 17017b6aa..9a8d13cfe 100644 --- a/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/wheat_from_smelting_bread.json +++ b/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/wheat_from_smelting_bread.json @@ -4,9 +4,7 @@ "cookingtime": 300, "experience": 0.1, "group": "food_to_wheat", - "ingredient": { - "item": "minecraft:bread" - }, + "ingredient": "minecraft:bread", "result": { "id": "minecraft:wheat" } diff --git a/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/wheat_from_smelting_cookie.json b/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/wheat_from_smelting_cookie.json index e87077791..d93f9361c 100644 --- a/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/wheat_from_smelting_cookie.json +++ b/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/wheat_from_smelting_cookie.json @@ -4,9 +4,7 @@ "cookingtime": 300, "experience": 0.1, "group": "food_to_wheat", - "ingredient": { - "item": "minecraft:cookie" - }, + "ingredient": "minecraft:cookie", "result": { "id": "minecraft:wheat" } diff --git a/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/wheat_from_smelting_hay_block.json b/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/wheat_from_smelting_hay_block.json index 2936c5d63..842ebd4c4 100644 --- a/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/wheat_from_smelting_hay_block.json +++ b/reference/latest/src/main/generated/data/fabric-docs-reference/recipe/wheat_from_smelting_hay_block.json @@ -4,9 +4,7 @@ "cookingtime": 300, "experience": 0.1, "group": "food_to_wheat", - "ingredient": { - "item": "minecraft:hay_block" - }, + "ingredient": "minecraft:hay_block", "result": { "id": "minecraft:wheat" } diff --git a/reference/latest/src/main/java/com/example/docs/block/ModBlocks.java b/reference/latest/src/main/java/com/example/docs/block/ModBlocks.java index de1c61733..fec962e3c 100644 --- a/reference/latest/src/main/java/com/example/docs/block/ModBlocks.java +++ b/reference/latest/src/main/java/com/example/docs/block/ModBlocks.java @@ -7,6 +7,8 @@ import net.minecraft.item.Item; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; import net.minecraft.sound.BlockSoundGroup; import net.minecraft.util.Identifier; @@ -23,36 +25,43 @@ public class ModBlocks { // :::1 // :::2 + public static final RegistryKey CONDENSED_DIRT_KEY = RegistryKey.of(RegistryKeys.BLOCK, Identifier.of(FabricDocsReference.MOD_ID, "condensed_dirt")); public static final Block CONDENSED_DIRT = register( - new Block(AbstractBlock.Settings.create().sounds(BlockSoundGroup.GRASS)), + new Block(AbstractBlock.Settings.create().registryKey(CONDENSED_DIRT_KEY).sounds(BlockSoundGroup.GRASS)), "condensed_dirt", true ); // :::2 // :::3 + public static final RegistryKey CONDENSED_OAK_LOG_KEY = RegistryKey.of(RegistryKeys.BLOCK, Identifier.of(FabricDocsReference.MOD_ID, "condensed_oak_log")); public static final Block CONDENSED_OAK_LOG = register( new PillarBlock( AbstractBlock.Settings.create() + .registryKey(CONDENSED_OAK_LOG_KEY) .sounds(BlockSoundGroup.WOOD) ), "condensed_oak_log", true ); // :::3 // :::4 + public static final RegistryKey PRISMARINE_LAMP_KEY = RegistryKey.of(RegistryKeys.BLOCK, Identifier.of(FabricDocsReference.MOD_ID, "prismarine_lamp")); public static final Block PRISMARINE_LAMP = register( new PrismarineLampBlock( AbstractBlock.Settings.create() + .registryKey(PRISMARINE_LAMP_KEY) .sounds(BlockSoundGroup.LANTERN) .luminance(PrismarineLampBlock::getLuminance) ), "prismarine_lamp", true ); // :::4 + public static final RegistryKey ENGINE_BLOCK_KEY = RegistryKey.of(RegistryKeys.BLOCK, Identifier.of(FabricDocsReference.MOD_ID, "engine")); public static final Block ENGINE_BLOCK = register( - new EngineBlock(AbstractBlock.Settings.create()), "engine", true + new EngineBlock(AbstractBlock.Settings.create().registryKey(ENGINE_BLOCK_KEY)), "engine", true ); // :::5 + public static final RegistryKey COUNTER_BLOCK_KEY = RegistryKey.of(RegistryKeys.BLOCK, Identifier.of(FabricDocsReference.MOD_ID, "counter_block")); public static final Block COUNTER_BLOCK = register( - new CounterBlock(AbstractBlock.Settings.create()), "counter_block", true + new CounterBlock(AbstractBlock.Settings.create().registryKey(COUNTER_BLOCK_KEY)), "counter_block", true ); // :::5 @@ -64,7 +73,7 @@ public static Block register(Block block, String name, boolean shouldRegisterIte // Sometimes, you may not want to register an item for the block. // Eg: if it's a technical block like `minecraft:air` or `minecraft:end_gateway` if (shouldRegisterItem) { - BlockItem blockItem = new BlockItem(block, new Item.Settings()); + BlockItem blockItem = new BlockItem(block, new Item.Settings().registryKey(RegistryKey.of(RegistryKeys.ITEM, id))); Registry.register(Registries.ITEM, id, blockItem); } diff --git a/reference/latest/src/main/java/com/example/docs/block/entity/ModBlockEntities.java b/reference/latest/src/main/java/com/example/docs/block/entity/ModBlockEntities.java index 8d38b4289..775e32996 100644 --- a/reference/latest/src/main/java/com/example/docs/block/entity/ModBlockEntities.java +++ b/reference/latest/src/main/java/com/example/docs/block/entity/ModBlockEntities.java @@ -7,6 +7,8 @@ import net.minecraft.registry.Registry; import net.minecraft.util.Identifier; +import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; + import com.example.docs.FabricDocsReference; import com.example.docs.block.ModBlocks; import com.example.docs.block.entity.custom.CounterBlockEntity; @@ -21,10 +23,10 @@ public class ModBlockEntities { register("counter", CounterBlockEntity::new, ModBlocks.COUNTER_BLOCK); private static BlockEntityType register(String name, - BlockEntityType.BlockEntityFactory entityFactory, + FabricBlockEntityTypeBuilder.Factory entityFactory, Block... blocks) { Identifier id = Identifier.of(FabricDocsReference.MOD_ID, name); - return Registry.register(Registries.BLOCK_ENTITY_TYPE, id, BlockEntityType.Builder.create(entityFactory, blocks).build()); + return Registry.register(Registries.BLOCK_ENTITY_TYPE, id, FabricBlockEntityTypeBuilder.create(entityFactory, blocks).build()); } // :::1 diff --git a/reference/latest/src/main/java/com/example/docs/damage/FabricDocsReferenceDamageTypes.java b/reference/latest/src/main/java/com/example/docs/damage/FabricDocsReferenceDamageTypes.java index b8c8d714b..4c3ddf48b 100644 --- a/reference/latest/src/main/java/com/example/docs/damage/FabricDocsReferenceDamageTypes.java +++ b/reference/latest/src/main/java/com/example/docs/damage/FabricDocsReferenceDamageTypes.java @@ -13,15 +13,18 @@ import net.fabricmc.api.ModInitializer; +import com.example.docs.FabricDocsReference; + public class FabricDocsReferenceDamageTypes implements ModInitializer { - public static final Block TATER_BLOCK = new TaterBlock(AbstractBlock.Settings.create()); + public static final RegistryKey TATER_BLOCK_KEY = RegistryKey.of(RegistryKeys.BLOCK, Identifier.of(FabricDocsReference.MOD_ID, "tater")); + public static final Block TATER_BLOCK = new TaterBlock(AbstractBlock.Settings.create().registryKey(TATER_BLOCK_KEY)); // :::1 - public static final RegistryKey TATER_DAMAGE = RegistryKey.of(RegistryKeys.DAMAGE_TYPE, Identifier.of("fabric-docs-reference", "tater")); + public static final RegistryKey TATER_DAMAGE = RegistryKey.of(RegistryKeys.DAMAGE_TYPE, Identifier.of(FabricDocsReference.MOD_ID, "tater")); // :::1 @Override public void onInitialize() { - Registry.register(Registries.BLOCK, Identifier.of("fabric-docs-reference", "tater"), TATER_BLOCK); - Registry.register(Registries.ITEM, Identifier.of("fabric-docs-reference", "tater"), new BlockItem(TATER_BLOCK, new Item.Settings())); + Registry.register(Registries.BLOCK, Identifier.of(FabricDocsReference.MOD_ID, "tater"), TATER_BLOCK); + Registry.register(Registries.ITEM, Identifier.of(FabricDocsReference.MOD_ID, "tater"), new BlockItem(TATER_BLOCK, new Item.Settings().registryKey(RegistryKey.of(RegistryKeys.ITEM, TATER_BLOCK_KEY.getValue())))); } } diff --git a/reference/latest/src/main/java/com/example/docs/damage/TaterBlock.java b/reference/latest/src/main/java/com/example/docs/damage/TaterBlock.java index 87e217764..728df7667 100644 --- a/reference/latest/src/main/java/com/example/docs/damage/TaterBlock.java +++ b/reference/latest/src/main/java/com/example/docs/damage/TaterBlock.java @@ -6,6 +6,7 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.entity.damage.DamageSource; import net.minecraft.registry.RegistryKeys; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -17,12 +18,13 @@ public TaterBlock(Settings settings) { @Override public void onSteppedOn(World world, BlockPos pos, BlockState state, Entity entity) { - if (entity instanceof LivingEntity) { + if (entity instanceof LivingEntity && world instanceof ServerWorld serverWorld) { DamageSource damageSource = new DamageSource( world.getRegistryManager() - .get(RegistryKeys.DAMAGE_TYPE) - .entryOf(FabricDocsReferenceDamageTypes.TATER_DAMAGE)); - entity.damage(damageSource, 5.0f); + .getOrThrow(RegistryKeys.DAMAGE_TYPE) + .getEntry(FabricDocsReferenceDamageTypes.TATER_DAMAGE.getValue()).get() + ); + entity.damage(serverWorld, damageSource, 5.0f); } } } diff --git a/reference/latest/src/main/java/com/example/docs/effect/TaterEffect.java b/reference/latest/src/main/java/com/example/docs/effect/TaterEffect.java index eb0a705b5..b26d11d46 100644 --- a/reference/latest/src/main/java/com/example/docs/effect/TaterEffect.java +++ b/reference/latest/src/main/java/com/example/docs/effect/TaterEffect.java @@ -4,6 +4,7 @@ import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffectCategory; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.server.world.ServerWorld; // :::1 public class TaterEffect extends StatusEffect { @@ -22,12 +23,12 @@ public boolean canApplyUpdateEffect(int duration, int amplifier) { // Called when the effect is applied. @Override - public boolean applyUpdateEffect(LivingEntity entity, int amplifier) { + public boolean applyUpdateEffect(ServerWorld world, LivingEntity entity, int amplifier) { if (entity instanceof PlayerEntity) { ((PlayerEntity) entity).addExperience(1 << amplifier); // Higher amplifier gives you experience faster } - return super.applyUpdateEffect(entity, amplifier); + return super.applyUpdateEffect(world, entity, amplifier); } } // :::1 diff --git a/reference/latest/src/main/java/com/example/docs/event/FabricDocsReferenceEvents.java b/reference/latest/src/main/java/com/example/docs/event/FabricDocsReferenceEvents.java index 150d6b616..b3304609b 100644 --- a/reference/latest/src/main/java/com/example/docs/event/FabricDocsReferenceEvents.java +++ b/reference/latest/src/main/java/com/example/docs/event/FabricDocsReferenceEvents.java @@ -9,6 +9,7 @@ import net.minecraft.loot.LootTable; import net.minecraft.loot.entry.ItemEntry; import net.minecraft.registry.RegistryKey; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.ActionResult; import net.fabricmc.api.ModInitializer; @@ -17,7 +18,7 @@ // Class to contain all mod events. public class FabricDocsReferenceEvents implements ModInitializer { - private static final RegistryKey COAL_ORE_LOOT_TABLE_ID = Blocks.COAL_ORE.getLootTableKey(); + private static final RegistryKey COAL_ORE_LOOT_TABLE_ID = Blocks.COAL_ORE.getLootTableKey().get(); @Override public void onInitialize() { @@ -26,8 +27,8 @@ public void onInitialize() { BlockState state = world.getBlockState(pos); // Manual spectator check is necessary because AttackBlockCallbacks fire before the spectator check - if (!player.isSpectator() && player.getMainHandStack().isEmpty() && state.isToolRequired()) { - player.damage(world.getDamageSources().generic(), 1.0F); + if (!player.isSpectator() && player.getMainHandStack().isEmpty() && state.isToolRequired() && world instanceof ServerWorld serverWorld) { + player.damage(serverWorld, world.getDamageSources().generic(), 1.0F); } return ActionResult.PASS; diff --git a/reference/latest/src/main/java/com/example/docs/item/ModItems.java b/reference/latest/src/main/java/com/example/docs/item/ModItems.java index 928f1578e..81a738a7b 100644 --- a/reference/latest/src/main/java/com/example/docs/item/ModItems.java +++ b/reference/latest/src/main/java/com/example/docs/item/ModItems.java @@ -1,5 +1,7 @@ package com.example.docs.item; +import net.minecraft.component.type.ConsumableComponent; +import net.minecraft.component.type.ConsumableComponents; import net.minecraft.component.type.FoodComponent; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; @@ -9,16 +11,19 @@ import net.minecraft.item.ItemGroups; import net.minecraft.item.ItemStack; import net.minecraft.item.SwordItem; +import net.minecraft.item.consume.ApplyEffectsConsumeEffect; +import net.minecraft.item.equipment.EquipmentType; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup; import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; import net.fabricmc.fabric.api.registry.CompostingChanceRegistry; -import net.fabricmc.fabric.api.registry.FuelRegistry; +import net.fabricmc.fabric.api.registry.FuelRegistryEvents; import com.example.docs.FabricDocsReference; import com.example.docs.component.ModComponents; @@ -32,20 +37,32 @@ public class ModItems { // :::1 // :::6 - public static final Item GUIDITE_HELMET = register(new ArmorItem(ModArmorMaterials.GUIDITE, ArmorItem.Type.HELMET, new Item.Settings().maxDamage(ArmorItem.Type.HELMET.getMaxDamage(ModArmorMaterials.GUIDITE_DURABILITY_MULTIPLIER))), "guidite_helmet"); - public static final Item GUIDITE_CHESTPLATE = register(new ArmorItem(ModArmorMaterials.GUIDITE, ArmorItem.Type.CHESTPLATE, new Item.Settings().maxDamage(ArmorItem.Type.CHESTPLATE.getMaxDamage(ModArmorMaterials.GUIDITE_DURABILITY_MULTIPLIER))), "guidite_chestplate"); - public static final Item GUIDITE_LEGGINGS = register(new ArmorItem(ModArmorMaterials.GUIDITE, ArmorItem.Type.LEGGINGS, new Item.Settings().maxDamage(ArmorItem.Type.LEGGINGS.getMaxDamage(ModArmorMaterials.GUIDITE_DURABILITY_MULTIPLIER))), "guidite_leggings"); - public static final Item GUIDITE_BOOTS = register(new ArmorItem(ModArmorMaterials.GUIDITE, ArmorItem.Type.BOOTS, new Item.Settings().maxDamage(ArmorItem.Type.BOOTS.getMaxDamage(ModArmorMaterials.GUIDITE_DURABILITY_MULTIPLIER))), "guidite_boots"); + public static final RegistryKey GUIDITE_HELMET_KEY = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(FabricDocsReference.MOD_ID, "guidite_helmet")); + public static final Item GUIDITE_HELMET = register(new ArmorItem(ModArmorMaterials.GUIDITE, EquipmentType.HELMET, new Item.Settings().registryKey(GUIDITE_HELMET_KEY).maxDamage(EquipmentType.HELMET.getMaxDamage(ModArmorMaterials.GUIDITE_DURABILITY_MULTIPLIER))), GUIDITE_HELMET_KEY); + + public static final RegistryKey GUIDITE_CHESTPLATE_KEY = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(FabricDocsReference.MOD_ID, "guidite_chestplate")); + public static final Item GUIDITE_CHESTPLATE = register(new ArmorItem(ModArmorMaterials.GUIDITE, EquipmentType.CHESTPLATE, new Item.Settings().registryKey(GUIDITE_CHESTPLATE_KEY).maxDamage(EquipmentType.CHESTPLATE.getMaxDamage(ModArmorMaterials.GUIDITE_DURABILITY_MULTIPLIER))), GUIDITE_CHESTPLATE_KEY); + + public static final RegistryKey GUIDITE_LEGGINGS_KEY = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(FabricDocsReference.MOD_ID, "guidite_leggings")); + public static final Item GUIDITE_LEGGINGS = register(new ArmorItem(ModArmorMaterials.GUIDITE, EquipmentType.LEGGINGS, new Item.Settings().registryKey(GUIDITE_LEGGINGS_KEY).maxDamage(EquipmentType.LEGGINGS.getMaxDamage(ModArmorMaterials.GUIDITE_DURABILITY_MULTIPLIER))), GUIDITE_LEGGINGS_KEY); + + public static final RegistryKey GUIDITE_BOOTS_KEY = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(FabricDocsReference.MOD_ID, "guidite_boots")); + public static final Item GUIDITE_BOOTS = register(new ArmorItem(ModArmorMaterials.GUIDITE, EquipmentType.BOOTS, new Item.Settings().registryKey(GUIDITE_BOOTS_KEY).maxDamage(EquipmentType.BOOTS.getMaxDamage(ModArmorMaterials.GUIDITE_DURABILITY_MULTIPLIER))), GUIDITE_BOOTS_KEY); // :::6 - public static final Item LIGHTNING_STICK = register(new LightningStick(new Item.Settings()), "lightning_stick"); + public static final RegistryKey LIGHTNING_STICK_KEY = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(FabricDocsReference.MOD_ID, "lightning_stick")); + public static final Item LIGHTNING_STICK = register(new LightningStick(new Item.Settings().registryKey(LIGHTNING_STICK_KEY)), LIGHTNING_STICK_KEY); // :::7 - public static final Item GUIDITE_SWORD = register(new SwordItem(GuiditeMaterial.INSTANCE, new Item.Settings()), "guidite_sword"); + public static final RegistryKey GUIDITE_SWORD_KEY = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(FabricDocsReference.MOD_ID, "guidite_sword")); + public static final Item GUIDITE_SWORD = register(new SwordItem(GuiditeMaterial.INSTANCE, 1f, 1f, new Item.Settings().registryKey(GUIDITE_SWORD_KEY)), GUIDITE_SWORD_KEY); // :::7 // :::_13 + public static final RegistryKey COUNTER_KEY = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(FabricDocsReference.MOD_ID, "counter")); public static final Item COUNTER = register(new CounterItem( - // Initialize the click count component with a default value of 0 - new Item.Settings().component(ModComponents.CLICK_COUNT_COMPONENT, 0) - ), "counter"); + new Item.Settings() + .registryKey(COUNTER_KEY) + // Initialize the click count component with a default value of 0 + .component(ModComponents.CLICK_COUNT_COMPONENT, 0) + ), COUNTER_KEY); // :::_13 // :::9 public static final RegistryKey CUSTOM_ITEM_GROUP_KEY = RegistryKey.of(Registries.ITEM_GROUP.getKey(), Identifier.of(FabricDocsReference.MOD_ID, "item_group")); @@ -55,35 +72,35 @@ public class ModItems { .build(); // :::9 // :::5 + public static final ConsumableComponent POISON_FOOD_CONSUMABLE_COMPONENT = ConsumableComponents.food() + // The duration is in ticks, 20 ticks = 1 second + .consumeEffect(new ApplyEffectsConsumeEffect(new StatusEffectInstance(StatusEffects.POISON, 6 * 20, 1), 1.0f)) + .build(); public static final FoodComponent POISON_FOOD_COMPONENT = new FoodComponent.Builder() .alwaysEdible() - .snack() - // The duration is in ticks, 20 ticks = 1 second - .statusEffect(new StatusEffectInstance(StatusEffects.POISON, 6 * 20, 1), 1.0f) .build(); // :::5 // :::poisonous_apple + public static final RegistryKey POISONOUS_APPLE_KEY = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(FabricDocsReference.MOD_ID, "poisonous_apple")); public static final Item POISONOUS_APPLE = register( - new Item(new Item.Settings().food(POISON_FOOD_COMPONENT)), - "poisonous_apple" + new Item(new Item.Settings().registryKey(POISONOUS_APPLE_KEY).food(POISON_FOOD_COMPONENT, POISON_FOOD_CONSUMABLE_COMPONENT)), + POISONOUS_APPLE_KEY ); // :::poisonous_apple // :::2 + public static final RegistryKey SUSPICIOUS_SUBSTANCE_KEY = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(FabricDocsReference.MOD_ID, "suspicious_substance")); public static final Item SUSPICIOUS_SUBSTANCE = register( - new Item(new Item.Settings()), - "suspicious_substance" + new Item(new Item.Settings().registryKey(SUSPICIOUS_SUBSTANCE_KEY)), + SUSPICIOUS_SUBSTANCE_KEY ); // :::2 // :::1 - public static Item register(Item item, String id) { - // Create the identifier for the item. - Identifier itemID = Identifier.of(FabricDocsReference.MOD_ID, id); - + public static Item register(Item item, RegistryKey registryKey) { // Register the item. - Item registeredItem = Registry.register(Registries.ITEM, itemID, item); + Item registeredItem = Registry.register(Registries.ITEM, registryKey.getValue(), item); // Return the registered item! return registeredItem; @@ -141,7 +158,9 @@ public static void initialize() { // Add the suspicious substance to the registry of fuels, with a burn time of 30 seconds. // Remember, Minecraft deals with logical based-time using ticks. // 20 ticks = 1 second. - FuelRegistry.INSTANCE.add(ModItems.SUSPICIOUS_SUBSTANCE, 30 * 20); + FuelRegistryEvents.BUILD.register((builder, context) -> { + builder.add(ModItems.SUSPICIOUS_SUBSTANCE, 30 * 20); + }); // :::_11 // :::3 } diff --git a/reference/latest/src/main/java/com/example/docs/item/armor/ModArmorMaterials.java b/reference/latest/src/main/java/com/example/docs/item/armor/ModArmorMaterials.java index 0a79d0bab..077a0885d 100644 --- a/reference/latest/src/main/java/com/example/docs/item/armor/ModArmorMaterials.java +++ b/reference/latest/src/main/java/com/example/docs/item/armor/ModArmorMaterials.java @@ -1,66 +1,41 @@ package com.example.docs.item.armor; -import java.util.List; import java.util.Map; -import java.util.function.Supplier; -import net.minecraft.item.ArmorItem; -import net.minecraft.item.ArmorMaterial; -import net.minecraft.recipe.Ingredient; -import net.minecraft.registry.Registries; -import net.minecraft.registry.Registry; -import net.minecraft.registry.entry.RegistryEntry; -import net.minecraft.sound.SoundEvent; +import net.minecraft.item.equipment.ArmorMaterial; +import net.minecraft.item.equipment.EquipmentAssetKeys; +import net.minecraft.item.equipment.EquipmentType; +import net.minecraft.registry.tag.ItemTags; import net.minecraft.sound.SoundEvents; -import net.minecraft.util.Identifier; - -import com.example.docs.FabricDocsReference; -import com.example.docs.item.ModItems; public class ModArmorMaterials { // :::3 public static final int GUIDITE_DURABILITY_MULTIPLIER = 15; // :::3 // :::2 - public static final RegistryEntry GUIDITE = registerMaterial("guidite", + public static final ArmorMaterial GUIDITE = new ArmorMaterial( + // Durability of the armor material. + 15, // Defense (protection) point values for each armor piece. Map.of( - ArmorItem.Type.HELMET, 3, - ArmorItem.Type.CHESTPLATE, 8, - ArmorItem.Type.LEGGINGS, 6, - ArmorItem.Type.BOOTS, 3 + EquipmentType.HELMET, 3, + EquipmentType.CHESTPLATE, 8, + EquipmentType.LEGGINGS, 6, + EquipmentType.BOOTS, 3 ), // Enchantability. For reference, leather has 15, iron has 9, and diamond has 10. 5, // The sound played when the armor is equipped. SoundEvents.ITEM_ARMOR_EQUIP_IRON, - // The ingredient(s) used to repair the armor. - () -> Ingredient.ofItems(ModItems.SUSPICIOUS_SUBSTANCE), + // Toughness 0.0F, + // Knockback resistance 0.0F, - // Guidite is NOT dyeable, so we will pass false. - false); + // The ingredient(s) used to repair the armor. + ItemTags.REPAIRS_DIAMOND_ARMOR, // TODO make a tag for this ModItems.SUSPICIOUS_SUBSTANCE + EquipmentAssetKeys.TURTLE_SCUTE // TODO make a custom key for this + ); // :::2 - // :::1 - public static RegistryEntry registerMaterial(String id, Map defensePoints, int enchantability, RegistryEntry equipSound, Supplier repairIngredientSupplier, float toughness, float knockbackResistance, boolean dyeable) { - // Get the supported layers for the armor material - List layers = List.of( - // The ID of the texture layer, the suffix, and whether the layer is dyeable. - // We can just pass the armor material ID as the texture layer ID. - // We have no need for a suffix, so we'll pass an empty string. - // We'll pass the dyeable boolean we received as the dyeable parameter. - new ArmorMaterial.Layer(Identifier.of(FabricDocsReference.MOD_ID, id), "", dyeable) - ); - - ArmorMaterial material = new ArmorMaterial(defensePoints, enchantability, equipSound, repairIngredientSupplier, layers, toughness, knockbackResistance); - // Register the material within the ArmorMaterials registry. - material = Registry.register(Registries.ARMOR_MATERIAL, Identifier.of(FabricDocsReference.MOD_ID, id), material); - - // The majority of the time, you'll want the RegistryEntry of the material - especially for the ArmorItem constructor. - return RegistryEntry.of(material); - } - - // :::1 public static void initialize() { } } diff --git a/reference/latest/src/main/java/com/example/docs/item/custom/CounterItem.java b/reference/latest/src/main/java/com/example/docs/item/custom/CounterItem.java index 4bf333922..7a0cfe0bf 100644 --- a/reference/latest/src/main/java/com/example/docs/item/custom/CounterItem.java +++ b/reference/latest/src/main/java/com/example/docs/item/custom/CounterItem.java @@ -7,9 +7,9 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.tooltip.TooltipType; import net.minecraft.text.Text; +import net.minecraft.util.ActionResult; import net.minecraft.util.Formatting; import net.minecraft.util.Hand; -import net.minecraft.util.TypedActionResult; import net.minecraft.world.World; import com.example.docs.component.ModComponents; @@ -24,20 +24,19 @@ public CounterItem(Settings settings) { @Override //::2 - public TypedActionResult use(World world, PlayerEntity user, Hand hand) { + public ActionResult use(World world, PlayerEntity user, Hand hand) { ItemStack stack = user.getStackInHand(hand); // Don't do anything on the client if (world.isClient()) { - return TypedActionResult.success(stack); + return ActionResult.SUCCESS; } // Read the current count and increase it by one int count = stack.getOrDefault(ModComponents.CLICK_COUNT_COMPONENT, 0); stack.set(ModComponents.CLICK_COUNT_COMPONENT, ++count); - // Return the original stack - return TypedActionResult.success(stack); + return ActionResult.SUCCESS; } //::2 diff --git a/reference/latest/src/main/java/com/example/docs/item/custom/LightningStick.java b/reference/latest/src/main/java/com/example/docs/item/custom/LightningStick.java index c7477af01..0b5d7645a 100644 --- a/reference/latest/src/main/java/com/example/docs/item/custom/LightningStick.java +++ b/reference/latest/src/main/java/com/example/docs/item/custom/LightningStick.java @@ -9,9 +9,9 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.tooltip.TooltipType; import net.minecraft.text.Text; +import net.minecraft.util.ActionResult; import net.minecraft.util.Formatting; import net.minecraft.util.Hand; -import net.minecraft.util.TypedActionResult; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -24,11 +24,11 @@ public LightningStick(Settings settings) { // :::1 // :::2 @Override - public TypedActionResult use(World world, PlayerEntity user, Hand hand) { + public ActionResult use(World world, PlayerEntity user, Hand hand) { // Ensure we don't spawn the lightning only on the client. // This is to prevent desync. if (world.isClient) { - return TypedActionResult.pass(user.getStackInHand(hand)); + return ActionResult.PASS; } BlockPos frontOfPlayer = user.getBlockPos().offset(user.getHorizontalFacing(), 10); @@ -38,9 +38,7 @@ public TypedActionResult use(World world, PlayerEntity user, Hand han lightningBolt.setPosition(frontOfPlayer.toCenterPos()); world.spawnEntity(lightningBolt); - // Nothing has changed to the item stack, - // so we just return it how it was. - return TypedActionResult.success(user.getStackInHand(hand)); + return ActionResult.SUCCESS; } // :::2 diff --git a/reference/latest/src/main/java/com/example/docs/item/tool/GuiditeMaterial.java b/reference/latest/src/main/java/com/example/docs/item/tool/GuiditeMaterial.java index bd148a901..78e673c31 100644 --- a/reference/latest/src/main/java/com/example/docs/item/tool/GuiditeMaterial.java +++ b/reference/latest/src/main/java/com/example/docs/item/tool/GuiditeMaterial.java @@ -1,65 +1,25 @@ package com.example.docs.item.tool; -import net.minecraft.block.Block; -import net.minecraft.item.Items; import net.minecraft.item.ToolMaterial; -import net.minecraft.recipe.Ingredient; import net.minecraft.registry.tag.BlockTags; -import net.minecraft.registry.tag.TagKey; - -import com.example.docs.item.ModItems; +import net.minecraft.registry.tag.ItemTags; // :::1 -public class GuiditeMaterial implements ToolMaterial { - // Your IDE should override the interface's methods for you, or at least shout at you to do so. +public class GuiditeMaterial { // :::1 - // :::8 - public static final GuiditeMaterial INSTANCE = new GuiditeMaterial(); - // :::8 - - // :::2 - @Override - public int getDurability() { - return 455; - } - - // :::2 - // :::3 - @Override - public float getMiningSpeedMultiplier() { - return 5.0F; - } - - // :::3 - // :::4 - @Override - public float getAttackDamage() { - return 1.5F; - } - - // :::4 - // :::5 - @Override - public TagKey getInverseTag() { - return BlockTags.INCORRECT_FOR_IRON_TOOL; - } - - // :::5 - // :::6 - @Override - public int getEnchantability() { - return 22; - } - - // :::6 - // :::7 - @Override - public Ingredient getRepairIngredient() { - return Ingredient.ofItems(ModItems.SUSPICIOUS_SUBSTANCE, Items.POTATO); - } - - // :::7 - + public static final ToolMaterial INSTANCE = new ToolMaterial( + BlockTags.INCORRECT_FOR_WOODEN_TOOL, + // Durability + 455, + // Mining speed multiplier + 5.0F, + // Attack damage bonus + 1.5F, + // Enchantability + 22, + // Repair tag + ItemTags.REPAIRS_DIAMOND_ARMOR // TODO make a tag for this ModItems.SUSPICIOUS_SUBSTANCE + ); // :::1 } // :::1 diff --git a/reference/latest/src/main/java/com/example/docs/mixin/event/SheepEntityMixin.java b/reference/latest/src/main/java/com/example/docs/mixin/event/SheepEntityMixin.java index 60fa33213..1b19da5f5 100644 --- a/reference/latest/src/main/java/com/example/docs/mixin/event/SheepEntityMixin.java +++ b/reference/latest/src/main/java/com/example/docs/mixin/event/SheepEntityMixin.java @@ -15,7 +15,7 @@ // ::: @Mixin(SheepEntity.class) public class SheepEntityMixin { - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/SheepEntity;sheared(Lnet/minecraft/sound/SoundCategory;)V"), method = "interactMob", cancellable = true) + @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/SheepEntity;sheared(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/sound/SoundCategory;Lnet/minecraft/item/ItemStack;)V"), method = "interactMob", cancellable = true) private void onShear(final PlayerEntity player, final Hand hand, final CallbackInfoReturnable info) { ActionResult result = SheepShearCallback.EVENT.invoker().interact(player, (SheepEntity) (Object) this); diff --git a/reference/latest/src/main/java/com/example/docs/networking/payload/EngineSoundInstancePacket.java b/reference/latest/src/main/java/com/example/docs/networking/payload/EngineSoundInstancePacket.java index 25b3084ff..dc63c4d9f 100644 --- a/reference/latest/src/main/java/com/example/docs/networking/payload/EngineSoundInstancePacket.java +++ b/reference/latest/src/main/java/com/example/docs/networking/payload/EngineSoundInstancePacket.java @@ -18,7 +18,7 @@ public Id getId() { } public static final PacketCodec CODEC = PacketCodec.tuple( - PacketCodecs.BOOL, EngineSoundInstancePacket::shouldStart, + PacketCodecs.BOOLEAN, EngineSoundInstancePacket::shouldStart, BlockPos.PACKET_CODEC, EngineSoundInstancePacket::blockEntityPos, EngineSoundInstancePacket::new ); diff --git a/reference/latest/src/main/java/com/example/docs/potion/FabricDocsReferencePotions.java b/reference/latest/src/main/java/com/example/docs/potion/FabricDocsReferencePotions.java index 3431e8596..a666a39c9 100644 --- a/reference/latest/src/main/java/com/example/docs/potion/FabricDocsReferencePotions.java +++ b/reference/latest/src/main/java/com/example/docs/potion/FabricDocsReferencePotions.java @@ -19,7 +19,7 @@ public class FabricDocsReferencePotions implements ModInitializer { Registry.register( Registries.POTION, Identifier.of("fabric-docs-reference", "tater"), - new Potion( + new Potion("tater", new StatusEffectInstance( FabricDocsReferenceEffects.TATER, 3600,