From ba00a7da1969bf10bf5adf45e81aa1e15864ed4b Mon Sep 17 00:00:00 2001 From: IntelliFish123 Date: Sun, 17 Nov 2024 11:50:58 +0200 Subject: [PATCH] migrate to mojmaps --- build.gradle | 2 +- remappedSrc/ro/fishmc/FishMC.java | 191 ++++++++++++++++++ remappedSrc/ro/fishmc/ModItems.java | 28 +++ remappedSrc/ro/fishmc/mixin/ExampleMixin.java | 15 ++ src/main/java/ro/fishmc/FishMC.java | 130 ++++++------ src/main/java/ro/fishmc/ModItems.java | 18 +- 6 files changed, 309 insertions(+), 75 deletions(-) create mode 100644 remappedSrc/ro/fishmc/FishMC.java create mode 100644 remappedSrc/ro/fishmc/ModItems.java create mode 100644 remappedSrc/ro/fishmc/mixin/ExampleMixin.java diff --git a/build.gradle b/build.gradle index 1caf098..13f4f59 100644 --- a/build.gradle +++ b/build.gradle @@ -39,7 +39,7 @@ loom { dependencies { // To change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" + mappings loom.officialMojangMappings() modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" diff --git a/remappedSrc/ro/fishmc/FishMC.java b/remappedSrc/ro/fishmc/FishMC.java new file mode 100644 index 0000000..c1f99ed --- /dev/null +++ b/remappedSrc/ro/fishmc/FishMC.java @@ -0,0 +1,191 @@ +package ro.fishmc; + +import net.fabric_extras.ranged_weapon.api.CustomBow; +import net.fabric_extras.ranged_weapon.api.RangedConfig; +import net.fabricmc.api.ModInitializer; + +import net.fabricmc.fabric.api.registry.FabricBrewingRecipeRegistryBuilder; +import net.minecraft.core.Holder; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.effect.MobEffects; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.alchemy.Potion; +import net.minecraft.world.item.alchemy.Potions; +import net.minecraft.world.item.crafting.Ingredient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class FishMC implements ModInitializer { + // This logger is used to write text to the console and the log file. + // It is considered best practice to use your mod id as the logger's name. + // That way, it's clear which mod wrote info, warnings, and errors. + public static final String MOD_ID = "fishmc"; + public static final Logger LOGGER = LoggerFactory.getLogger("fishmc"); + public static final Potion DECAY = + Registry.register( + BuiltInRegistries.POTION, + ResourceLocation.fromNamespaceAndPath("fishmc", "decay"), + new Potion( + new MobEffectInstance( + MobEffects.WITHER, + 3600, + 1))); + public static final Potion BLINDNESS = + Registry.register( + BuiltInRegistries.POTION, + ResourceLocation.fromNamespaceAndPath("fishmc", "blindness"), + new Potion( + new MobEffectInstance( + MobEffects.BLINDNESS, + 3600, + 0))); + public static final Potion GLOWING = + Registry.register( + BuiltInRegistries.POTION, + ResourceLocation.fromNamespaceAndPath("fishmc", "glowing"), + new Potion( + new MobEffectInstance( + MobEffects.GLOWING, + 800, + 0))); + public static final Potion LEVITATION = + Registry.register( + BuiltInRegistries.POTION, + ResourceLocation.fromNamespaceAndPath("fishmc", "levitation"), + new Potion( + new MobEffectInstance( + MobEffects.LEVITATION, + 3600, + 0))); + public static final Potion STUNNED = + Registry.register( + BuiltInRegistries.POTION, + ResourceLocation.fromNamespaceAndPath("fishmc", "stunned"),new Potion(new MobEffectInstance[]{new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 400, 200), new MobEffectInstance(MobEffects.WEAKNESS, 400, 200), new MobEffectInstance(MobEffects.DIG_SLOWDOWN, 400, 200)})); + public static final Potion SHULKERCRAFT = + Registry.register( + BuiltInRegistries.POTION, + ResourceLocation.fromNamespaceAndPath("fishmc", "shulkercraft"),new Potion(new MobEffectInstance[]{new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 200, 200), new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 200, 2)})); + public static final Potion CRAFTABLE_DECAY = + Registry.register( + BuiltInRegistries.POTION, + ResourceLocation.fromNamespaceAndPath("fishmc", "craftable_decay"), + new Potion( + new MobEffectInstance( + MobEffects.WITHER, + 400, + 1))); + public static final Potion CRAFTABLE_BLINDNESS = + Registry.register( + BuiltInRegistries.POTION, + ResourceLocation.fromNamespaceAndPath("fishmc", "craftable_blindness"), + new Potion( + new MobEffectInstance( + MobEffects.BLINDNESS, + 400, + 0))); + public static final Potion CRAFTABLE_GLOWING = + Registry.register( + BuiltInRegistries.POTION, + ResourceLocation.fromNamespaceAndPath("fishmc", "craftable_glowing"), + new Potion( + new MobEffectInstance( + MobEffects.GLOWING, + 400, + 0))); + public static final Potion CRAFTABLE_LEVITATION = + Registry.register( + BuiltInRegistries.POTION, + ResourceLocation.fromNamespaceAndPath("fishmc", "craftable_levitation"), + new Potion( + new MobEffectInstance( + MobEffects.LEVITATION, + 400, + 0))); + public static final Potion CRAFTABLE_STUNNED = + Registry.register( + BuiltInRegistries.POTION, + ResourceLocation.fromNamespaceAndPath("fishmc", "craftable_stunned"),new Potion(new MobEffectInstance[]{new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 400, 200), new MobEffectInstance(MobEffects.WEAKNESS, 400, 200), new MobEffectInstance(MobEffects.DIG_SLOWDOWN, 400, 200)})); + @Override + public void onInitialize() { + // This code runs as soon as Minecraft is in a mod-load-ready state. + // However, some things (like resources) may still be uninitialized. + // Proceed with mild caution. + LOGGER.info("Welcome to FishMC!"); + var bow = new CustomBow( + new Item.Properties().durability(150), + new RangedConfig(3, -0.7F, 5), + () -> Ingredient.of(Items.OAK_WOOD) + ); + Registry.register( + BuiltInRegistries.ITEM, + ResourceLocation.fromNamespaceAndPath(FishMC.MOD_ID, "shortbow"), + bow + ); + ModItems.initialize(); + //Registry.registerPotionRecipe(Potions.WATER, Items.POTATO, DECAY); + FabricBrewingRecipeRegistryBuilder.BUILD.register(builder -> { + builder.addMix( + // Input potion. + Potions.AWKWARD, + // Ingredient + Items.WITHER_ROSE, + // Output potion. + Holder.direct(CRAFTABLE_DECAY) + ); + }); + FabricBrewingRecipeRegistryBuilder.BUILD.register(builder -> { + builder.addMix( + // Input potion. + Potions.AWKWARD, + // Ingredient + Items.FERMENTED_SPIDER_EYE, + // Output potion. + Holder.direct(CRAFTABLE_BLINDNESS) + ); + }); + FabricBrewingRecipeRegistryBuilder.BUILD.register(builder -> { + builder.addMix( + // Input potion. + Potions.AWKWARD, + // Ingredient + Items.GLOW_BERRIES, + // Output potion. + Holder.direct(CRAFTABLE_GLOWING) + ); + }); + FabricBrewingRecipeRegistryBuilder.BUILD.register(builder -> { + builder.addMix( + // Input potion. + Potions.AWKWARD, + // Ingredient + Items.SHULKER_SHELL, + // Output potion. + Holder.direct(CRAFTABLE_LEVITATION) + ); + }); + FabricBrewingRecipeRegistryBuilder.BUILD.register(builder -> { + builder.addMix( + // Input potion. + Potions.AWKWARD, + // Ingredient + Items.OMINOUS_BOTTLE, + // Output potion. + Holder.direct(CRAFTABLE_STUNNED) + ); + }); + FabricBrewingRecipeRegistryBuilder.BUILD.register(builder -> { + builder.addMix( + // Input potion. + Potions.AWKWARD, + // Ingredient + Items.SHULKER_BOX, + // Output potion. + Holder.direct(SHULKERCRAFT) + ); + }); + } +} diff --git a/remappedSrc/ro/fishmc/ModItems.java b/remappedSrc/ro/fishmc/ModItems.java new file mode 100644 index 0000000..6d7f5e4 --- /dev/null +++ b/remappedSrc/ro/fishmc/ModItems.java @@ -0,0 +1,28 @@ +package ro.fishmc; + +import eu.raspberrymods.fishlib.ObsidianTool; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.SwordItem; + +public class ModItems { + public static Item register(Item item, String id) { + // Create the identifier for the item. + ResourceLocation itemID = ResourceLocation.fromNamespaceAndPath(FishMC.MOD_ID, id); + + // Register the item. + Item registeredItem = Registry.register(BuiltInRegistries.ITEM, itemID, item); + + // Return the registered item! + return registeredItem; + } + + public static final Item OBSIDIAN_CLAYMORE = register(new SwordItem(ObsidianTool.INSTANCE, new Item.Properties().stacksTo(1).fireResistant().attributes( + SwordItem.createAttributes( + ObsidianTool.INSTANCE, + 12, -0.5f))), "obsidian_claymore"); + public static void initialize() { + } +} diff --git a/remappedSrc/ro/fishmc/mixin/ExampleMixin.java b/remappedSrc/ro/fishmc/mixin/ExampleMixin.java new file mode 100644 index 0000000..cb926ec --- /dev/null +++ b/remappedSrc/ro/fishmc/mixin/ExampleMixin.java @@ -0,0 +1,15 @@ +package ro.fishmc.mixin; + +import net.minecraft.server.MinecraftServer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(MinecraftServer.class) +public class ExampleMixin { + @Inject(at = @At("HEAD"), method = "loadWorld") + private void init(CallbackInfo info) { + // This code is injected into the start of MinecraftServer.loadWorld()V + } +} \ No newline at end of file diff --git a/src/main/java/ro/fishmc/FishMC.java b/src/main/java/ro/fishmc/FishMC.java index b96b975..c1f99ed 100644 --- a/src/main/java/ro/fishmc/FishMC.java +++ b/src/main/java/ro/fishmc/FishMC.java @@ -5,17 +5,17 @@ import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.registry.FabricBrewingRecipeRegistryBuilder; -import net.minecraft.entity.effect.StatusEffectInstance; -import net.minecraft.entity.effect.StatusEffects; -import net.minecraft.item.Item; -import net.minecraft.item.Items; -import net.minecraft.potion.Potion; -import net.minecraft.potion.Potions; -import net.minecraft.recipe.Ingredient; -import net.minecraft.registry.Registries; -import net.minecraft.registry.Registry; -import net.minecraft.registry.entry.RegistryEntry; -import net.minecraft.util.Identifier; +import net.minecraft.core.Holder; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.effect.MobEffects; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.alchemy.Potion; +import net.minecraft.world.item.alchemy.Potions; +import net.minecraft.world.item.crafting.Ingredient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -27,88 +27,88 @@ public class FishMC implements ModInitializer { public static final Logger LOGGER = LoggerFactory.getLogger("fishmc"); public static final Potion DECAY = Registry.register( - Registries.POTION, - Identifier.of("fishmc", "decay"), + BuiltInRegistries.POTION, + ResourceLocation.fromNamespaceAndPath("fishmc", "decay"), new Potion( - new StatusEffectInstance( - StatusEffects.WITHER, + new MobEffectInstance( + MobEffects.WITHER, 3600, 1))); public static final Potion BLINDNESS = Registry.register( - Registries.POTION, - Identifier.of("fishmc", "blindness"), + BuiltInRegistries.POTION, + ResourceLocation.fromNamespaceAndPath("fishmc", "blindness"), new Potion( - new StatusEffectInstance( - StatusEffects.BLINDNESS, + new MobEffectInstance( + MobEffects.BLINDNESS, 3600, 0))); public static final Potion GLOWING = Registry.register( - Registries.POTION, - Identifier.of("fishmc", "glowing"), + BuiltInRegistries.POTION, + ResourceLocation.fromNamespaceAndPath("fishmc", "glowing"), new Potion( - new StatusEffectInstance( - StatusEffects.GLOWING, + new MobEffectInstance( + MobEffects.GLOWING, 800, 0))); public static final Potion LEVITATION = Registry.register( - Registries.POTION, - Identifier.of("fishmc", "levitation"), + BuiltInRegistries.POTION, + ResourceLocation.fromNamespaceAndPath("fishmc", "levitation"), new Potion( - new StatusEffectInstance( - StatusEffects.LEVITATION, + new MobEffectInstance( + MobEffects.LEVITATION, 3600, 0))); public static final Potion STUNNED = Registry.register( - Registries.POTION, - Identifier.of("fishmc", "stunned"),new Potion(new StatusEffectInstance[]{new StatusEffectInstance(StatusEffects.SLOWNESS, 400, 200), new StatusEffectInstance(StatusEffects.WEAKNESS, 400, 200), new StatusEffectInstance(StatusEffects.MINING_FATIGUE, 400, 200)})); + BuiltInRegistries.POTION, + ResourceLocation.fromNamespaceAndPath("fishmc", "stunned"),new Potion(new MobEffectInstance[]{new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 400, 200), new MobEffectInstance(MobEffects.WEAKNESS, 400, 200), new MobEffectInstance(MobEffects.DIG_SLOWDOWN, 400, 200)})); public static final Potion SHULKERCRAFT = Registry.register( - Registries.POTION, - Identifier.of("fishmc", "shulkercraft"),new Potion(new StatusEffectInstance[]{new StatusEffectInstance(StatusEffects.SLOWNESS, 200, 200), new StatusEffectInstance(StatusEffects.RESISTANCE, 200, 2)})); + BuiltInRegistries.POTION, + ResourceLocation.fromNamespaceAndPath("fishmc", "shulkercraft"),new Potion(new MobEffectInstance[]{new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 200, 200), new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 200, 2)})); public static final Potion CRAFTABLE_DECAY = Registry.register( - Registries.POTION, - Identifier.of("fishmc", "craftable_decay"), + BuiltInRegistries.POTION, + ResourceLocation.fromNamespaceAndPath("fishmc", "craftable_decay"), new Potion( - new StatusEffectInstance( - StatusEffects.WITHER, + new MobEffectInstance( + MobEffects.WITHER, 400, 1))); public static final Potion CRAFTABLE_BLINDNESS = Registry.register( - Registries.POTION, - Identifier.of("fishmc", "craftable_blindness"), + BuiltInRegistries.POTION, + ResourceLocation.fromNamespaceAndPath("fishmc", "craftable_blindness"), new Potion( - new StatusEffectInstance( - StatusEffects.BLINDNESS, + new MobEffectInstance( + MobEffects.BLINDNESS, 400, 0))); public static final Potion CRAFTABLE_GLOWING = Registry.register( - Registries.POTION, - Identifier.of("fishmc", "craftable_glowing"), + BuiltInRegistries.POTION, + ResourceLocation.fromNamespaceAndPath("fishmc", "craftable_glowing"), new Potion( - new StatusEffectInstance( - StatusEffects.GLOWING, + new MobEffectInstance( + MobEffects.GLOWING, 400, 0))); public static final Potion CRAFTABLE_LEVITATION = Registry.register( - Registries.POTION, - Identifier.of("fishmc", "craftable_levitation"), + BuiltInRegistries.POTION, + ResourceLocation.fromNamespaceAndPath("fishmc", "craftable_levitation"), new Potion( - new StatusEffectInstance( - StatusEffects.LEVITATION, + new MobEffectInstance( + MobEffects.LEVITATION, 400, 0))); public static final Potion CRAFTABLE_STUNNED = Registry.register( - Registries.POTION, - Identifier.of("fishmc", "craftable_stunned"),new Potion(new StatusEffectInstance[]{new StatusEffectInstance(StatusEffects.SLOWNESS, 400, 200), new StatusEffectInstance(StatusEffects.WEAKNESS, 400, 200), new StatusEffectInstance(StatusEffects.MINING_FATIGUE, 400, 200)})); + BuiltInRegistries.POTION, + ResourceLocation.fromNamespaceAndPath("fishmc", "craftable_stunned"),new Potion(new MobEffectInstance[]{new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 400, 200), new MobEffectInstance(MobEffects.WEAKNESS, 400, 200), new MobEffectInstance(MobEffects.DIG_SLOWDOWN, 400, 200)})); @Override public void onInitialize() { // This code runs as soon as Minecraft is in a mod-load-ready state. @@ -116,75 +116,75 @@ public void onInitialize() { // Proceed with mild caution. LOGGER.info("Welcome to FishMC!"); var bow = new CustomBow( - new Item.Settings().maxDamage(150), + new Item.Properties().durability(150), new RangedConfig(3, -0.7F, 5), - () -> Ingredient.ofItems(Items.OAK_WOOD) + () -> Ingredient.of(Items.OAK_WOOD) ); Registry.register( - Registries.ITEM, - Identifier.of(FishMC.MOD_ID, "shortbow"), + BuiltInRegistries.ITEM, + ResourceLocation.fromNamespaceAndPath(FishMC.MOD_ID, "shortbow"), bow ); ModItems.initialize(); //Registry.registerPotionRecipe(Potions.WATER, Items.POTATO, DECAY); FabricBrewingRecipeRegistryBuilder.BUILD.register(builder -> { - builder.registerPotionRecipe( + builder.addMix( // Input potion. Potions.AWKWARD, // Ingredient Items.WITHER_ROSE, // Output potion. - RegistryEntry.of(CRAFTABLE_DECAY) + Holder.direct(CRAFTABLE_DECAY) ); }); FabricBrewingRecipeRegistryBuilder.BUILD.register(builder -> { - builder.registerPotionRecipe( + builder.addMix( // Input potion. Potions.AWKWARD, // Ingredient Items.FERMENTED_SPIDER_EYE, // Output potion. - RegistryEntry.of(CRAFTABLE_BLINDNESS) + Holder.direct(CRAFTABLE_BLINDNESS) ); }); FabricBrewingRecipeRegistryBuilder.BUILD.register(builder -> { - builder.registerPotionRecipe( + builder.addMix( // Input potion. Potions.AWKWARD, // Ingredient Items.GLOW_BERRIES, // Output potion. - RegistryEntry.of(CRAFTABLE_GLOWING) + Holder.direct(CRAFTABLE_GLOWING) ); }); FabricBrewingRecipeRegistryBuilder.BUILD.register(builder -> { - builder.registerPotionRecipe( + builder.addMix( // Input potion. Potions.AWKWARD, // Ingredient Items.SHULKER_SHELL, // Output potion. - RegistryEntry.of(CRAFTABLE_LEVITATION) + Holder.direct(CRAFTABLE_LEVITATION) ); }); FabricBrewingRecipeRegistryBuilder.BUILD.register(builder -> { - builder.registerPotionRecipe( + builder.addMix( // Input potion. Potions.AWKWARD, // Ingredient Items.OMINOUS_BOTTLE, // Output potion. - RegistryEntry.of(CRAFTABLE_STUNNED) + Holder.direct(CRAFTABLE_STUNNED) ); }); FabricBrewingRecipeRegistryBuilder.BUILD.register(builder -> { - builder.registerPotionRecipe( + builder.addMix( // Input potion. Potions.AWKWARD, // Ingredient Items.SHULKER_BOX, // Output potion. - RegistryEntry.of(SHULKERCRAFT) + Holder.direct(SHULKERCRAFT) ); }); } diff --git a/src/main/java/ro/fishmc/ModItems.java b/src/main/java/ro/fishmc/ModItems.java index 5379766..6d7f5e4 100644 --- a/src/main/java/ro/fishmc/ModItems.java +++ b/src/main/java/ro/fishmc/ModItems.java @@ -1,26 +1,26 @@ package ro.fishmc; import eu.raspberrymods.fishlib.ObsidianTool; -import net.minecraft.item.Item; -import net.minecraft.item.SwordItem; -import net.minecraft.registry.Registries; -import net.minecraft.registry.Registry; -import net.minecraft.util.Identifier; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.SwordItem; public class ModItems { public static Item register(Item item, String id) { // Create the identifier for the item. - Identifier itemID = Identifier.of(FishMC.MOD_ID, id); + ResourceLocation itemID = ResourceLocation.fromNamespaceAndPath(FishMC.MOD_ID, id); // Register the item. - Item registeredItem = Registry.register(Registries.ITEM, itemID, item); + Item registeredItem = Registry.register(BuiltInRegistries.ITEM, itemID, item); // Return the registered item! return registeredItem; } - public static final Item OBSIDIAN_CLAYMORE = register(new SwordItem(ObsidianTool.INSTANCE, new Item.Settings().maxCount(1).fireproof().attributeModifiers( - SwordItem.createAttributeModifiers( + public static final Item OBSIDIAN_CLAYMORE = register(new SwordItem(ObsidianTool.INSTANCE, new Item.Properties().stacksTo(1).fireResistant().attributes( + SwordItem.createAttributes( ObsidianTool.INSTANCE, 12, -0.5f))), "obsidian_claymore"); public static void initialize() {