From 5209a616da7ab4dccf24a73eb57ebaef17d6fbd5 Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Sat, 8 Apr 2023 02:00:59 -0400 Subject: [PATCH] Working Forge and Fabric on 1.19.3/4 --- .vscode/launch.json | 14 --- CHANGELOG.md | 29 ++++--- samples/madeinhaxe/README.md | 9 +- samples/obsidianarmor/README.md | 31 +++++++ samples/obsidianarmor/project.xml | 2 +- .../obsidianarmor/ObsidianArmorMod.hx | 30 +++---- .../obsidianarmor/items/ModItems.hx | 86 +++++++++---------- src/net/minecraft/world/item/ArmorItem.hx | 9 +- .../world/item/Equipable.hx | 0 .../pickhaxe/compat/world/item/ArmorItem.hx | 26 ++++-- 10 files changed, 129 insertions(+), 107 deletions(-) delete mode 100644 .vscode/launch.json create mode 100644 samples/obsidianarmor/README.md rename src/net/{minecraft_draft => minecraft}/world/item/Equipable.hx (100%) diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index fd2747c..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "HXCPP", - "type": "hxcpp", - "request": "launch", - "program": "${workspaceFolder}/generated/bin/Main.exe", - } - ] -} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a7ba04..3cbbd58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [0.2.0] - 2023-04-?? +## [0.2.0] - 2023-04-08 ## Added - Implemented basic support for Forge 1.19.3. - `Mod` has been moved to `CommonMod`, and is now a class rather than an interface. @@ -11,20 +11,23 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - New functions you can override: `onCreativeModeTabRegister` to register Creative Mode tabs and `onRegister` to register anything else (blocks, items, fluids). - Added incomplete implementations of `ClientMod` and `ServerMod`, for eventual use for side-only mod events. - Added the `--mappings` argument to `pickhaxe make`. -- Added the `net.pickhaxe.compat.world.item.Item` class. - - This class is an abstract wrapper for `net.minecraft.world.item.Item`, adding new functionality and cross-loader/cross-version convenience functions. - - Use it in place of `Item` where you can. - - Added the `item.register(resourceLocation)` method to correctly add the item to the `ITEMS` registry. - - Make sure this function is called from the `CommonMod.onRegister` function to ensure the item is registered in time. -- Replaced the `net.minecraft.world.item.CreativeModeTab` class with an abstract wrapper. - - This abstract wrapper automatically adds new functionality and cross-loader/cross-version convenience functions. - - You do not need to change the class you are importing to take advantage of this functionality. - - Added the static `CreativeModeTab.builder()` method to generate a proper CreativeModeTab Builder class. - - Added the `creativeModeTab.register(resourceLocation)` method to correctly add the item to the list of Creative Mode tabs. - - Make sure this function is called from the `CommonMod.onRegister` function to ensure the item is registered in time. - - Also assigns a proper display name for the tab as necessary. +- Added several classes to the `net.pickhaxe.compat` package to assist with compatiblity. + - Newly created classes, as well as abstracts wrapping Minecraft classes, are placed in this package to avoid generating new classes in the `net.minecraft` package. + - Added the `net.pickhaxe.compat.world.item.Item` class. + - This class is an abstract wrapper for `net.minecraft.world.item.Item`, adding new functionality and cross-loader/cross-version convenience functions. + - Use it in place of `Item` where you can. + - Added the `item.register(resourceLocation)` method to correctly add the item to the `ITEMS` registry. + - Make sure this function is called from the `CommonMod.onRegister` function to ensure the item is registered in time. + - Replaced the `net.minecraft.world.item.CreativeModeTab` class with an abstract wrapper. + - This abstract wrapper automatically adds new functionality and cross-loader/cross-version convenience functions. + - You do not need to change the class you are importing to take advantage of this functionality. + - Added the static `CreativeModeTab.builder()` method to generate a proper CreativeModeTab Builder class. + - Added the `creativeModeTab.register(resourceLocation)` method to correctly add the item to the list of Creative Mode tabs. + - Make sure this function is called from the `CommonMod.onRegister` function to ensure the item is registered in time. + - Also assigns a proper display name for the tab as necessary. ## Changes - Refactored the Made in Haxe sample project to use the new `CommonMod` lifecycle functions. +- Refactored the Obsidian Armor sample project to use the new `CommonMod` lifecycle functions. - PickHaxe and Haxe are now shaded properly in the mod JAR. - This prevents a crash error caused by including two Forge mods that both used PickHaxe. - The `pickhaxe build` and `pickhaxe make` commands now properly report and exit early if one or more Gradle tasks fails, instead of continuing to perform more Gradle tasks. diff --git a/samples/madeinhaxe/README.md b/samples/madeinhaxe/README.md index 0b7b81f..365e2cf 100644 --- a/samples/madeinhaxe/README.md +++ b/samples/madeinhaxe/README.md @@ -1,14 +1,15 @@ # Made in Haxe -Made in Haxe is a barebones sample mod, which adds a new item and a new Creative Mode tab to hold it. +Made in Haxe is a barebones sample mod, which adds a functionless new item and a new Creative Mode tab to hold it. + ## Compatibility MC Version | Forge | Fabric ---|---|--- -1.19.4 | ✓ | -1.19.3 | ✓ | -1.19.2 | ✗ | ? +1.19.4 | ⚠ | ✓ +1.19.3 | ✓ | ✓ +1.19.2 | ? | ? 1.19.1 | ? | ? 1.19.0 | ? | ? diff --git a/samples/obsidianarmor/README.md b/samples/obsidianarmor/README.md new file mode 100644 index 0000000..16f6582 --- /dev/null +++ b/samples/obsidianarmor/README.md @@ -0,0 +1,31 @@ +# Obsidian Armor + +Obsidian Armor is a sample mod which adds a new armor and tool set, crafted using Obsidian. + + +## Compatibility + +MC Version | Forge | Fabric +---|---|--- +1.19.4 | ⚠ | ✓ +1.19.3 | ✓ | ✓ +1.19.2 | ? | ? +1.19.1 | ? | ? +1.19.0 | ? | ? + +**Legend**: +- `✓`: Builds and runs successfully in a modded game +- `⚠`: Fails to build due to issues with external libraries +- `✗`: Fails to build due to issues with PickHaxe +- `?`: Not tested + +**Issue List**: +- 1.19.4 Forge: Requires using `--mappings mojang` on build and make + + +## Building + +- Make sure you have Haxe 4.3.0 installed. +- `haxelib run pickhaxe build fabric 1.19.3` +- `haxelib run pickhaxe gradlew fabric 1.19.3 build` +- Look in `./build/fabric/1.19.3/` \ No newline at end of file diff --git a/samples/obsidianarmor/project.xml b/samples/obsidianarmor/project.xml index 0d2081c..e11248d 100644 --- a/samples/obsidianarmor/project.xml +++ b/samples/obsidianarmor/project.xml @@ -31,4 +31,4 @@ - \ No newline at end of file + diff --git a/samples/obsidianarmor/src/com/elitemastereric/obsidianarmor/ObsidianArmorMod.hx b/samples/obsidianarmor/src/com/elitemastereric/obsidianarmor/ObsidianArmorMod.hx index 641d63e..70ae915 100644 --- a/samples/obsidianarmor/src/com/elitemastereric/obsidianarmor/ObsidianArmorMod.hx +++ b/samples/obsidianarmor/src/com/elitemastereric/obsidianarmor/ObsidianArmorMod.hx @@ -1,11 +1,19 @@ package com.elitemastereric.obsidianarmor; import com.elitemastereric.obsidianarmor.items.ModItems; -import net.pickhaxe.core.Mod; +import net.pickhaxe.core.CommonMod; import net.pickhaxe.core.Environment; -class ObsidianArmorMod implements Mod { - public function onInitialize():Void { +class ObsidianArmorMod extends CommonMod { + public override function onRegister():Void { + ModItems.register(); + } + + public override function onCreativeModeTabRegister():Void { + ModItems.registerCreativeTab(); + } + + public override function onModInitialize():Void { #if fabric LOGGER.info('Hello Fabric! Welcome to Minecraft ${Environment.MINECRAFT_VERSION}!'); #end @@ -13,21 +21,5 @@ class ObsidianArmorMod implements Mod { #if forge LOGGER.info('Hello Forge! Welcome to Minecraft ${Environment.MINECRAFT_VERSION}!'); #end - - #if (minecraft >= "1.19.3") - LOGGER.info('Minecraft is in 1.19.3 or 1.19.4'); - #else - LOGGER.info('Minecraft is before 1.19.3 or 1.19.4'); - #end - - #if (minecraft >= "1.19.4") - LOGGER.info('Minecraft is in 1.19.4'); - #else - LOGGER.info('Minecraft is before 1.19.4'); - #end - - ModItems.onInitialize(); - - //var test:net.minecraft.advancements.critereon.BlockPredicate = null; } } \ No newline at end of file diff --git a/samples/obsidianarmor/src/com/elitemastereric/obsidianarmor/items/ModItems.hx b/samples/obsidianarmor/src/com/elitemastereric/obsidianarmor/items/ModItems.hx index 017bbda..b50b03e 100644 --- a/samples/obsidianarmor/src/com/elitemastereric/obsidianarmor/items/ModItems.hx +++ b/samples/obsidianarmor/src/com/elitemastereric/obsidianarmor/items/ModItems.hx @@ -2,21 +2,16 @@ package com.elitemastereric.obsidianarmor.items; import com.elitemastereric.obsidianarmor.materials.ObsidianArmorMaterial; import com.elitemastereric.obsidianarmor.materials.ObsidianToolMaterial; -import net.fabricmc.fabric.api.item.v1.FabricItemSettings; -import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup; -import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroupEntries; -import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; + import net.minecraft.core.Registry; -import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.item.ArmorItem.ArmorItem_Type; -import net.minecraft.world.item.ArmorItem; import net.minecraft.world.item.ArmorMaterial; import net.minecraft.world.item.AxeItem; -import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.HoeItem; -import net.minecraft.world.item.Item; +import net.minecraft.world.item.Item.Item_Properties; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.PickaxeItem; @@ -25,6 +20,12 @@ import net.minecraft.world.item.ShovelItem; import net.minecraft.world.item.SwordItem; import net.minecraft.world.item.Tier; +import net.pickhaxe.compat.core.Registries; +import net.pickhaxe.compat.world.item.CreativeModeTab; +import net.pickhaxe.compat.world.item.Item; +//import net.pickhaxe.compat.world.item.ArmorItem; +import net.minecraft.world.item.ArmorItem; + class ModItems { // References to our items. // Item.Settings is used to store properties such as stack size and durability. @@ -44,52 +45,47 @@ class ModItems { public static final OBSIDIAN_LEGGINGS:Item = new ArmorItem(OBSIDIAN_ARMOR_MATERIAL, ArmorItem_Type.LEGGINGS, new Item_Properties().rarity(Rarity.RARE).fireResistant()); public static final OBSIDIAN_BOOTS:Item = new ArmorItem(OBSIDIAN_ARMOR_MATERIAL, ArmorItem_Type.BOOTS, new Item_Properties().rarity(Rarity.RARE).fireResistant()); - // Item Groups - public static final ITEM_GROUP:CreativeModeTab = FabricItemGroup.builder(new ResourceLocation(ObsidianArmorMod.MOD_ID, "obsidian_armor")) - .icon(getCreativeTabIcon) - .build(); + // Creative Mode Tab + public static final CREATIVE_TAB:CreativeModeTab = CreativeModeTab.builder() + .displayItems(function(params, entries) { + entries.accept(OBSIDIAN_AXE); + entries.accept(OBSIDIAN_PICKAXE); + entries.accept(OBSIDIAN_SHOVEL); + entries.accept(OBSIDIAN_SWORD); + entries.accept(OBSIDIAN_HOE); - public static function onInitialize():Void { - // Add each of our items to the item registry. + entries.accept(OBSIDIAN_HELMET); + entries.accept(OBSIDIAN_CHESTPLATE); + entries.accept(OBSIDIAN_LEGGINGS); + entries.accept(OBSIDIAN_BOOTS); + }) + .icon(getTabIcon) + .build(); + public static function register():Void + { ObsidianArmorMod.LOGGER.info("Registering items..."); - var fieldNames:Array = Type.getClassFields(BuiltInRegistries); + OBSIDIAN_PICKAXE.register(new ResourceLocation(ObsidianArmorMod.MOD_ID, "obsidian_pickaxe")); + OBSIDIAN_AXE.register(new ResourceLocation(ObsidianArmorMod.MOD_ID, "obsidian_axe")); + OBSIDIAN_SHOVEL.register(new ResourceLocation(ObsidianArmorMod.MOD_ID, "obsidian_shovel")); + OBSIDIAN_SWORD.register(new ResourceLocation(ObsidianArmorMod.MOD_ID, "obsidian_sword")); + OBSIDIAN_HOE.register(new ResourceLocation(ObsidianArmorMod.MOD_ID, "obsidian_hoe")); - ObsidianArmorMod.LOGGER.info('Fetched registries.'); - - for (fieldName in fieldNames) { - ObsidianArmorMod.LOGGER.info('Registry: ' + fieldName); - } - - // Tools - Registry.register(BuiltInRegistries.ITEM, new ResourceLocation(ObsidianArmorMod.MOD_ID, "obsidian_pickaxe"), OBSIDIAN_PICKAXE); - Registry.register(BuiltInRegistries.ITEM, new ResourceLocation(ObsidianArmorMod.MOD_ID, "obsidian_axe"), OBSIDIAN_AXE); - Registry.register(BuiltInRegistries.ITEM, new ResourceLocation(ObsidianArmorMod.MOD_ID, "obsidian_shovel"), OBSIDIAN_SHOVEL); - Registry.register(BuiltInRegistries.ITEM, new ResourceLocation(ObsidianArmorMod.MOD_ID, "obsidian_sword"), OBSIDIAN_SWORD); - Registry.register(BuiltInRegistries.ITEM, new ResourceLocation(ObsidianArmorMod.MOD_ID, "obsidian_hoe"), OBSIDIAN_HOE); - - // Armor - Registry.register(BuiltInRegistries.ITEM, new ResourceLocation(ObsidianArmorMod.MOD_ID, "obsidian_helmet"), OBSIDIAN_HELMET); - Registry.register(BuiltInRegistries.ITEM, new ResourceLocation(ObsidianArmorMod.MOD_ID, "obsidian_chestplate"), OBSIDIAN_CHESTPLATE); - Registry.register(BuiltInRegistries.ITEM, new ResourceLocation(ObsidianArmorMod.MOD_ID, "obsidian_leggings"), OBSIDIAN_LEGGINGS); - Registry.register(BuiltInRegistries.ITEM, new ResourceLocation(ObsidianArmorMod.MOD_ID, "obsidian_boots"), OBSIDIAN_BOOTS); + OBSIDIAN_HELMET.register(new ResourceLocation(ObsidianArmorMod.MOD_ID, "obsidian_helmet")); + OBSIDIAN_CHESTPLATE.register(new ResourceLocation(ObsidianArmorMod.MOD_ID, "obsidian_chestplate")); + OBSIDIAN_LEGGINGS.register(new ResourceLocation(ObsidianArmorMod.MOD_ID, "obsidian_leggings")); + OBSIDIAN_BOOTS.register(new ResourceLocation(ObsidianArmorMod.MOD_ID, "obsidian_boots")); + } - ItemGroupEvents.modifyEntriesEvent(ITEM_GROUP).register(new ModifyEntriesHaxe(function(content:FabricItemGroupEntries) { - content.add(OBSIDIAN_AXE); - content.add(OBSIDIAN_PICKAXE); - content.add(OBSIDIAN_SHOVEL); - content.add(OBSIDIAN_SWORD); - content.add(OBSIDIAN_HOE); + public static function registerCreativeTab():Void + { + ObsidianArmorMod.LOGGER.info("Registering Creative Mode tab..."); - content.add(OBSIDIAN_HELMET); - content.add(OBSIDIAN_CHESTPLATE); - content.add(OBSIDIAN_LEGGINGS); - content.add(OBSIDIAN_BOOTS); - })); + CREATIVE_TAB.register(new ResourceLocation(ObsidianArmorMod.MOD_ID, "obsidian_armor")); } - static function getCreativeTabIcon():ItemStack { + static function getTabIcon():ItemStack { return new ItemStack(OBSIDIAN_CHESTPLATE); } } \ No newline at end of file diff --git a/src/net/minecraft/world/item/ArmorItem.hx b/src/net/minecraft/world/item/ArmorItem.hx index 1f6cbd0..eca8afe 100644 --- a/src/net/minecraft/world/item/ArmorItem.hx +++ b/src/net/minecraft/world/item/ArmorItem.hx @@ -2,7 +2,8 @@ package net.minecraft.world.item; import net.minecraft.world.entity.EquipmentSlot; -typedef ArmorItem = net.minecraft.world.item.ArmorItem_Minecraft; +// typedef ArmorItem = net.minecraft.world.item.ArmorItem_Minecraft; +typedef ArmorItem = net.pickhaxe.compat.world.item.ArmorItem; @:native("net.minecraft.world.item.ArmorItem") @:mapping("net.minecraft.class_1738") @@ -11,7 +12,7 @@ extern class ArmorItem_Minecraft extends net.minecraft.world.item.Item implement @:mapping("field_7879") public static final DISPENSE_ITEM_BEHAVIOR:net.minecraft.core.dispenser.DispenseItemBehavior; - #if (minecraft >= "1.19.4") + #if minecraft_gteq_1_19_4 /** * @since 1.19.4 */ @@ -55,7 +56,7 @@ extern class ArmorItem_Minecraft extends net.minecraft.world.item.Item implement interactionHand:net.minecraft.world.InteractionHand):net.minecraft.world.InteractionResultHolder; } -#if (minecraft >= "1.19.4") +#if minecraft_gteq_1_19_4 // Use the native ArmorItem_Type enum @:native("net.minecraft.world.item.ArmorItem$Type") @:mapping("net.minecraft.class_1738$class_8051") @@ -153,6 +154,7 @@ abstract ArmorItem_Type(ArmorItem_Type_Inner) return BOOTS; default: net.pickhaxe.core.PickHaxe.logError("Invalid name for ArmorItem_Type: " + name); + return null; } } @@ -170,6 +172,7 @@ abstract ArmorItem_Type(ArmorItem_Type_Inner) return BOOTS; default: net.pickhaxe.core.PickHaxe.logError("Invalid EquipmentSlot for ArmorItem_Type: " + slot); + return null; } } diff --git a/src/net/minecraft_draft/world/item/Equipable.hx b/src/net/minecraft/world/item/Equipable.hx similarity index 100% rename from src/net/minecraft_draft/world/item/Equipable.hx rename to src/net/minecraft/world/item/Equipable.hx diff --git a/src/net/pickhaxe/compat/world/item/ArmorItem.hx b/src/net/pickhaxe/compat/world/item/ArmorItem.hx index e943660..4d82f34 100644 --- a/src/net/pickhaxe/compat/world/item/ArmorItem.hx +++ b/src/net/pickhaxe/compat/world/item/ArmorItem.hx @@ -4,21 +4,31 @@ import net.minecraft.world.item.ArmorItem.ArmorItem_Minecraft; @:forward abstract ArmorItem(ArmorItem_Minecraft) from ArmorItem_Minecraft to ArmorItem_Minecraft { - public overload extern inline function new(armorMaterial:net.minecraft.world.item.ArmorMaterial, slot:EquipmentSlot, + public overload extern inline function new(armorMaterial:net.minecraft.world.item.ArmorMaterial, slot:net.minecraft.world.entity.EquipmentSlot, properties:net.minecraft.world.item.Item.Properties) { - #if (minecraft >= "1.19.4") - this = new ArmorItem_Inner(armorMaterial, ArmorItem_Type.bySlot(slot), properties); + #if minecraft_gteq_1_19_4 + this = new ArmorItem_Minecraft(armorMaterial, net.minecraft.world.item.ArmorItem.ArmorItem_Type.bySlot(slot), properties); #else - this = new ArmorItem_Inner(armorMaterial, slot, properties); + this = new ArmorItem_Minecraft(armorMaterial, slot, properties); #end } - public overload extern inline function new(armorMaterial:net.minecraft.world.item.ArmorMaterial, type:ArmorItem_Type, + public overload extern inline function new(armorMaterial:net.minecraft.world.item.ArmorMaterial, type:net.minecraft.world.item.ArmorItem.ArmorItem_Type, properties:net.minecraft.world.item.Item.Properties) { - #if (minecraft >= "1.19.4") - this = new ArmorItem_Inner(armorMaterial, type, properties); + #if minecraft_gteq_1_19_4 + this = new ArmorItem_Minecraft(armorMaterial, type, properties); #else - this = new ArmorItem_Inner(armorMaterial, type.getSlot(), properties); + this = new ArmorItem_Minecraft(armorMaterial, type.getSlot(), properties); #end }; + + @:to + public inline function toPickHaxeItem():net.pickhaxe.compat.world.item.Item { + return this; + } + + @:to + public inline function toMinecraftItemm():net.minecraft.world.item.Item { + return this; + } } \ No newline at end of file