From a04883a5cec0ba9b11e8bd8a7452c09086590fe5 Mon Sep 17 00:00:00 2001 From: Adam Beckingham Date: Sat, 24 Feb 2024 13:10:24 -0700 Subject: [PATCH] Food-related fixes --- README.md | 2 +- _m3ec/gradle.py | 3 +++ data/fabric1.16.5/registry/ModItems.m3ecjava | 7 +------ data/fabric1.17.1/registry/ModItems.m3ecjava | 7 +------ data/fabric1.17/registry/ModItems.m3ecjava | 7 +------ data/fabric1.18.1/registry/ModItems.m3ecjava | 7 +------ data/fabric1.18.2/registry/ModItems.m3ecjava | 7 +------ data/fabric1.18/registry/ModItems.m3ecjava | 7 +------ data/fabric1.19.2/registry/ModItems.m3ecjava | 7 +------ data/fabric1.19.3/registry/ModItems.m3ecjava | 7 +------ data/fabric1.19.4/registry/ModItems.m3ecjava | 7 +------ data/fabric1.19/registry/ModItems.m3ecjava | 7 +------ data/fabric1.20.1/registry/ModItems.m3ecjava | 7 +------ data/fabric_common/classes/FoodItem.m3ecjava | 14 ++++++++------ data/forge1.18.1/m3ec_build.json | 2 +- data/forge1.19.2/java/item/ModItems.m3ecjava | 4 +++- data/forge1.19/java/item/ModItems.m3ecjava | 4 +++- data/forge1.20.1/java/item/ModItems.m3ecjava | 4 ++-- data/forge_common/classes/FoodItem.m3ecjava | 15 +++++++++------ m3ec.py | 2 +- 20 files changed, 42 insertions(+), 85 deletions(-) diff --git a/README.md b/README.md index 9d48649..22fbaf0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # M3EC ## Minecraft Multi Mod Environment Compiler -Version 0.8 +Version 0.9 This compiler/script operates on the mentality of "as few files as possible" to create a mod. Check out the `testrubymod` folder for usage examples. diff --git a/_m3ec/gradle.py b/_m3ec/gradle.py index d826db4..9650343 100644 --- a/_m3ec/gradle.py +++ b/_m3ec/gradle.py @@ -16,14 +16,17 @@ def maybe_run_gradle(path, modenv, javaver, md): fname = "gradlew" if "buildjar" in modenvlow or "build" in modenvlow: + print("\n-----------------------------------------------\n\tbuilding JAR\n") subprocess.Popen([os.path.join(path, fname), "build", "jar", javapath], cwd=path).wait() jd = os.path.join(os.path.dirname(path), "built_mod_jars") make_dir(jd) for f in walk(os.path.join(path, "build", "libs")): shutil.copy(f, os.path.join(jd, os.path.splitext(os.path.basename(f))[0]+"-"+md["modloader"]+md["gameversion"]+".jar")) if "runclient" in modenvlow: + print("\n-----------------------------------------------\n\tRunning Client\n") subprocess.Popen([os.path.join(path, fname), "runClient", javapath], cwd=path).wait() if "runserver" in modenvlow: + print("\n-----------------------------------------------\n\tRunning Server\n") subprocess.Popen([os.path.join(path, fname), "runServer", javapath], cwd=path).wait() diff --git a/data/fabric1.16.5/registry/ModItems.m3ecjava b/data/fabric1.16.5/registry/ModItems.m3ecjava index 9e8dae2..a80b3c8 100644 --- a/data/fabric1.16.5/registry/ModItems.m3ecjava +++ b/data/fabric1.16.5/registry/ModItems.m3ecjava @@ -8,12 +8,7 @@ import net.fabricmc.fabric.api.registry.FuelRegistry; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.EquipmentSlot; -import net.minecraft.item.BlockItem; -import net.minecraft.item.FoodComponent; -import net.minecraft.item.Item; -import net.minecraft.item.ArmorItem; -import net.minecraft.item.ToolItem; -import net.minecraft.item.ItemGroup; +import net.minecraft.item.*; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; ---iter moditems.imports diff --git a/data/fabric1.17.1/registry/ModItems.m3ecjava b/data/fabric1.17.1/registry/ModItems.m3ecjava index 265e314..4066a31 100644 --- a/data/fabric1.17.1/registry/ModItems.m3ecjava +++ b/data/fabric1.17.1/registry/ModItems.m3ecjava @@ -8,12 +8,7 @@ import net.fabricmc.fabric.api.registry.FuelRegistry; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.EquipmentSlot; -import net.minecraft.item.BlockItem; -import net.minecraft.item.FoodComponent; -import net.minecraft.item.Item; -import net.minecraft.item.ArmorItem; -import net.minecraft.item.ToolItem; -import net.minecraft.item.ItemGroup; +import net.minecraft.item.*; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; ---iter moditems.imports diff --git a/data/fabric1.17/registry/ModItems.m3ecjava b/data/fabric1.17/registry/ModItems.m3ecjava index 265e314..4066a31 100644 --- a/data/fabric1.17/registry/ModItems.m3ecjava +++ b/data/fabric1.17/registry/ModItems.m3ecjava @@ -8,12 +8,7 @@ import net.fabricmc.fabric.api.registry.FuelRegistry; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.EquipmentSlot; -import net.minecraft.item.BlockItem; -import net.minecraft.item.FoodComponent; -import net.minecraft.item.Item; -import net.minecraft.item.ArmorItem; -import net.minecraft.item.ToolItem; -import net.minecraft.item.ItemGroup; +import net.minecraft.item.*; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; ---iter moditems.imports diff --git a/data/fabric1.18.1/registry/ModItems.m3ecjava b/data/fabric1.18.1/registry/ModItems.m3ecjava index c42ab5a..a9666f6 100644 --- a/data/fabric1.18.1/registry/ModItems.m3ecjava +++ b/data/fabric1.18.1/registry/ModItems.m3ecjava @@ -8,12 +8,7 @@ import net.fabricmc.fabric.api.registry.FuelRegistry; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.EquipmentSlot; -import net.minecraft.item.BlockItem; -import net.minecraft.item.FoodComponent; -import net.minecraft.item.Item; -import net.minecraft.item.ArmorItem; -import net.minecraft.item.ToolItem; -import net.minecraft.item.ItemGroup; +import net.minecraft.item.*; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; ---iter moditems.imports diff --git a/data/fabric1.18.2/registry/ModItems.m3ecjava b/data/fabric1.18.2/registry/ModItems.m3ecjava index c42ab5a..a9666f6 100644 --- a/data/fabric1.18.2/registry/ModItems.m3ecjava +++ b/data/fabric1.18.2/registry/ModItems.m3ecjava @@ -8,12 +8,7 @@ import net.fabricmc.fabric.api.registry.FuelRegistry; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.EquipmentSlot; -import net.minecraft.item.BlockItem; -import net.minecraft.item.FoodComponent; -import net.minecraft.item.Item; -import net.minecraft.item.ArmorItem; -import net.minecraft.item.ToolItem; -import net.minecraft.item.ItemGroup; +import net.minecraft.item.*; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; ---iter moditems.imports diff --git a/data/fabric1.18/registry/ModItems.m3ecjava b/data/fabric1.18/registry/ModItems.m3ecjava index c42ab5a..a9666f6 100644 --- a/data/fabric1.18/registry/ModItems.m3ecjava +++ b/data/fabric1.18/registry/ModItems.m3ecjava @@ -8,12 +8,7 @@ import net.fabricmc.fabric.api.registry.FuelRegistry; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.EquipmentSlot; -import net.minecraft.item.BlockItem; -import net.minecraft.item.FoodComponent; -import net.minecraft.item.Item; -import net.minecraft.item.ArmorItem; -import net.minecraft.item.ToolItem; -import net.minecraft.item.ItemGroup; +import net.minecraft.item.*; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; ---iter moditems.imports diff --git a/data/fabric1.19.2/registry/ModItems.m3ecjava b/data/fabric1.19.2/registry/ModItems.m3ecjava index 28a31e5..e271e4b 100644 --- a/data/fabric1.19.2/registry/ModItems.m3ecjava +++ b/data/fabric1.19.2/registry/ModItems.m3ecjava @@ -8,12 +8,7 @@ import net.fabricmc.fabric.api.registry.FuelRegistry; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.EquipmentSlot; -import net.minecraft.item.BlockItem; -import net.minecraft.item.FoodComponent; -import net.minecraft.item.Item; -import net.minecraft.item.ArmorItem; -import net.minecraft.item.ToolItem; -import net.minecraft.item.ItemGroup; +import net.minecraft.item.*; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; ---iter moditems.imports diff --git a/data/fabric1.19.3/registry/ModItems.m3ecjava b/data/fabric1.19.3/registry/ModItems.m3ecjava index 6f0a63f..dd48ac1 100644 --- a/data/fabric1.19.3/registry/ModItems.m3ecjava +++ b/data/fabric1.19.3/registry/ModItems.m3ecjava @@ -9,12 +9,7 @@ import net.fabricmc.fabric.api.registry.FuelRegistry; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.EquipmentSlot; -import net.minecraft.item.BlockItem; -import net.minecraft.item.FoodComponent; -import net.minecraft.item.Item; -import net.minecraft.item.ArmorItem; -import net.minecraft.item.ToolItem; -import net.minecraft.item.ItemGroup; +import net.minecraft.item.*; import net.minecraft.util.Identifier; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; diff --git a/data/fabric1.19.4/registry/ModItems.m3ecjava b/data/fabric1.19.4/registry/ModItems.m3ecjava index d35fd99..6b220e5 100644 --- a/data/fabric1.19.4/registry/ModItems.m3ecjava +++ b/data/fabric1.19.4/registry/ModItems.m3ecjava @@ -9,12 +9,7 @@ import net.fabricmc.fabric.api.registry.FuelRegistry; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.EquipmentSlot; -import net.minecraft.item.BlockItem; -import net.minecraft.item.FoodComponent; -import net.minecraft.item.Item; -import net.minecraft.item.ArmorItem; -import net.minecraft.item.ToolItem; -import net.minecraft.item.ItemGroup; +import net.minecraft.item.*; import net.minecraft.util.Identifier; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; diff --git a/data/fabric1.19/registry/ModItems.m3ecjava b/data/fabric1.19/registry/ModItems.m3ecjava index c42ab5a..a9666f6 100644 --- a/data/fabric1.19/registry/ModItems.m3ecjava +++ b/data/fabric1.19/registry/ModItems.m3ecjava @@ -8,12 +8,7 @@ import net.fabricmc.fabric.api.registry.FuelRegistry; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.EquipmentSlot; -import net.minecraft.item.BlockItem; -import net.minecraft.item.FoodComponent; -import net.minecraft.item.Item; -import net.minecraft.item.ArmorItem; -import net.minecraft.item.ToolItem; -import net.minecraft.item.ItemGroup; +import net.minecraft.item.*; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; ---iter moditems.imports diff --git a/data/fabric1.20.1/registry/ModItems.m3ecjava b/data/fabric1.20.1/registry/ModItems.m3ecjava index d35fd99..6b220e5 100644 --- a/data/fabric1.20.1/registry/ModItems.m3ecjava +++ b/data/fabric1.20.1/registry/ModItems.m3ecjava @@ -9,12 +9,7 @@ import net.fabricmc.fabric.api.registry.FuelRegistry; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.EquipmentSlot; -import net.minecraft.item.BlockItem; -import net.minecraft.item.FoodComponent; -import net.minecraft.item.Item; -import net.minecraft.item.ArmorItem; -import net.minecraft.item.ToolItem; -import net.minecraft.item.ItemGroup; +import net.minecraft.item.*; import net.minecraft.util.Identifier; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; diff --git a/data/fabric_common/classes/FoodItem.m3ecjava b/data/fabric_common/classes/FoodItem.m3ecjava index d884444..1f6c1e6 100644 --- a/data/fabric_common/classes/FoodItem.m3ecjava +++ b/data/fabric_common/classes/FoodItem.m3ecjava @@ -1,5 +1,6 @@ package ${mod.package}.registry; +import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -22,13 +23,14 @@ public class FoodItem extends Item { } @Override - public TypedActionResult use(World world, PlayerEntity user, Hand hand) { - TypedActionResult result = super.use(world, user, hand); - if (result.getResult() == ActionResult.SUCCESS) { - if (returnItem != null) { - user.giveItemStack(new ItemStack(returnItem, 1)); + public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) { + ItemStack rval = super.finishUsing(stack, world, user); + if (this.isFood() && returnItem != null) { + if (user.isPlayer()) { + PlayerEntity player = world.getPlayerByUuid(user.getUuid()); + player.giveItemStack(new ItemStack(returnItem, 1)); } } - return result; + return rval; } } diff --git a/data/forge1.18.1/m3ec_build.json b/data/forge1.18.1/m3ec_build.json index 3b9a96e..612ac1c 100644 --- a/data/forge1.18.1/m3ec_build.json +++ b/data/forge1.18.1/m3ec_build.json @@ -5,7 +5,7 @@ "firstActions": [ { "action": "print", - "string": "[!] Building for Forge 1.16.5 is currently *very* broken [!]" + "string": "[!] Building for Forge 1.18.1 is currently *very* broken [!]" }, { "if": [ diff --git a/data/forge1.19.2/java/item/ModItems.m3ecjava b/data/forge1.19.2/java/item/ModItems.m3ecjava index db022c9..8cc59e5 100644 --- a/data/forge1.19.2/java/item/ModItems.m3ecjava +++ b/data/forge1.19.2/java/item/ModItems.m3ecjava @@ -18,7 +18,9 @@ public class ModItems { ---iter mod.registry.food.names public static final RegistryObject ${mod.food.$%v.uppercased} = ITEMS.register("$%v", - () -> new Item(new Item.Properties().tab(${mod.creativemodetab}).food(ModFoods.${mod.food.$%v.uppercased})));---end + () -> new FoodItem(new Item.Properties().food(ModFoods.${mod.food.$%v.uppercased}) +---if mod.food.$%v.returnItem +, ${mod.food.$%v.returnItem}---fi));---end ---iter mod.registry.tool.names public static final RegistryObject ${mod.tool.$%v.uppercased} = ITEMS.register("$%v", diff --git a/data/forge1.19/java/item/ModItems.m3ecjava b/data/forge1.19/java/item/ModItems.m3ecjava index db022c9..8cc59e5 100644 --- a/data/forge1.19/java/item/ModItems.m3ecjava +++ b/data/forge1.19/java/item/ModItems.m3ecjava @@ -18,7 +18,9 @@ public class ModItems { ---iter mod.registry.food.names public static final RegistryObject ${mod.food.$%v.uppercased} = ITEMS.register("$%v", - () -> new Item(new Item.Properties().tab(${mod.creativemodetab}).food(ModFoods.${mod.food.$%v.uppercased})));---end + () -> new FoodItem(new Item.Properties().food(ModFoods.${mod.food.$%v.uppercased}) +---if mod.food.$%v.returnItem +, ${mod.food.$%v.returnItem}---fi));---end ---iter mod.registry.tool.names public static final RegistryObject ${mod.tool.$%v.uppercased} = ITEMS.register("$%v", diff --git a/data/forge1.20.1/java/item/ModItems.m3ecjava b/data/forge1.20.1/java/item/ModItems.m3ecjava index d0d572f..2265e1f 100644 --- a/data/forge1.20.1/java/item/ModItems.m3ecjava +++ b/data/forge1.20.1/java/item/ModItems.m3ecjava @@ -18,9 +18,9 @@ public class ModItems { ---iter mod.registry.food.names public static final RegistryObject ${mod.food.$%v.uppercased} = ITEMS.register("$%v", - () -> new FoodItem(new Item.Properties().food(ModFoods.${mod.food.$%v.uppercased})) + () -> new FoodItem(new Item.Properties().food(ModFoods.${mod.food.$%v.uppercased}) ---if mod.food.$%v.returnItem -, ${mod.food.$%v.returnItem}---fi);---end +, ${mod.food.$%v.returnItem}---fi));---end ---iter mod.registry.tool.names public static final RegistryObject ${mod.tool.$%v.uppercased} = ITEMS.register("$%v", diff --git a/data/forge_common/classes/FoodItem.m3ecjava b/data/forge_common/classes/FoodItem.m3ecjava index 639524d..4113d32 100644 --- a/data/forge_common/classes/FoodItem.m3ecjava +++ b/data/forge_common/classes/FoodItem.m3ecjava @@ -1,9 +1,9 @@ package ${mod.package}.item; - import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -23,11 +23,14 @@ public class FoodItem extends Item { } @Override - public InteractionResultHolder use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) { - InteractionResultHolder result = super.use(pLevel, pPlayer, pUsedHand); - if (result.getResult() == InteractionResult.SUCCESS) { - pPlayer.addItem(new ItemStack(returnItem, 1)); + public ItemStack finishUsingItem(ItemStack pStack, Level pLevel, LivingEntity pLivingEntity) { + ItemStack rval = super.finishUsingItem(pStack, pLevel, pLivingEntity); + if (pStack.isEdible() && returnItem != null) { + Player player = pLevel.getPlayerByUUID(pLivingEntity.getUUID()); + if (player != null) { + player.addItem(new ItemStack(returnItem, 1)); + } } - return result; + return rval; } } diff --git a/m3ec.py b/m3ec.py index 145eef1..9893aaa 100644 --- a/m3ec.py +++ b/m3ec.py @@ -765,7 +765,7 @@ def copy_textures(content_type, cid, manifest_dict, project_path, dest_dir): if __name__=='__main__': if len(sys.argv) < 2: print(""" -Minecraft Multiple Mod Environment Compiler v0.7 +Minecraft Multiple Mod Environment Compiler v0.9 Usage: python m3ec.py path modenv where modenv can be any combination of: