Skip to content

Commit

Permalink
Working Forge and Fabric on 1.19.3/4
Browse files Browse the repository at this point in the history
  • Loading branch information
EliteMasterEric committed Apr 8, 2023
1 parent a126362 commit 5209a61
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 107 deletions.
14 changes: 0 additions & 14 deletions .vscode/launch.json

This file was deleted.

29 changes: 16 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,31 @@ 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.
- `onInitialize` has been renamed to `onModInitialize`.
- 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.
Expand Down
9 changes: 5 additions & 4 deletions samples/madeinhaxe/README.md
Original file line number Diff line number Diff line change
@@ -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 | ? | ?

Expand Down
31 changes: 31 additions & 0 deletions samples/obsidianarmor/README.md
Original file line number Diff line number Diff line change
@@ -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/`
2 changes: 1 addition & 1 deletion samples/obsidianarmor/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@

<!-- https://spdx.org/licenses/ -->
<mod-license value="MIT" />
</pickhaxe>
</pickhaxe>
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
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

#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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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<String> = 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);
}
}
9 changes: 6 additions & 3 deletions src/net/minecraft/world/item/ArmorItem.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
*/
Expand Down Expand Up @@ -55,7 +56,7 @@ extern class ArmorItem_Minecraft extends net.minecraft.world.item.Item implement
interactionHand:net.minecraft.world.InteractionHand):net.minecraft.world.InteractionResultHolder<net.minecraft.world.item.ItemStack>;
}

#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")
Expand Down Expand Up @@ -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;
}
}

Expand All @@ -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;
}
}

Expand Down
File renamed without changes.
26 changes: 18 additions & 8 deletions src/net/pickhaxe/compat/world/item/ArmorItem.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 5209a61

Please sign in to comment.