From d5569b459537d6ffe7a8db02aafd07749cad4999 Mon Sep 17 00:00:00 2001 From: Adam Beckingham Date: Sat, 24 Feb 2024 11:52:26 -0700 Subject: [PATCH] Misc. fixes, warn about certain builds being broken, add returnItem for food items --- _m3ec/actions.py | 4 + _m3ec/util.py | 4 + data/fabric1.16.5/registry/ModItems.m3ecjava | 18 ++- data/fabric1.17.1/registry/ModItems.m3ecjava | 18 ++- data/fabric1.17/registry/ModItems.m3ecjava | 18 ++- data/fabric1.18.1/registry/ModItems.m3ecjava | 18 ++- data/fabric1.18.2/registry/ModItems.m3ecjava | 18 ++- data/fabric1.18/registry/ModItems.m3ecjava | 18 ++- data/fabric1.19.2/registry/ModItems.m3ecjava | 18 ++- data/fabric1.19.3/registry/ModItems.m3ecjava | 18 ++- data/fabric1.19.4/registry/ModItems.m3ecjava | 18 ++- data/fabric1.19/registry/ModItems.m3ecjava | 18 ++- data/fabric1.20.1/registry/ModItems.m3ecjava | 6 +- data/fabric_common/classes/FoodItem.m3ecjava | 34 ++++++ data/fabric_common/fabric_preactions.json | 9 +- .../food_status_effects.json | 28 ++++- data/forge1.16.5/m3ec_build.json | 4 + data/forge1.18.1/m3ec_build.json | 4 + data/forge1.18.2/java/item/ModFoods.m3ecjava | 7 +- data/forge1.19.2/java/item/ModFoods.m3ecjava | 7 +- data/forge1.19/java/item/ModFoods.m3ecjava | 7 +- data/forge1.20.1/java/item/ModFoods.m3ecjava | 7 +- data/forge1.20.1/java/item/ModItems.m3ecjava | 4 +- data/forge_common/classes/FoodItem.m3ecjava | 33 ++++++ data/forge_common/food_status_effects.json | 107 ++++++++++++++++++ data/forge_common/forge_preactions.json | 9 +- 26 files changed, 401 insertions(+), 53 deletions(-) create mode 100644 data/fabric_common/classes/FoodItem.m3ecjava rename data/{common/actions => fabric_common}/food_status_effects.json (66%) create mode 100644 data/forge_common/classes/FoodItem.m3ecjava create mode 100644 data/forge_common/food_status_effects.json diff --git a/_m3ec/actions.py b/_m3ec/actions.py index 79044e7..d0fba71 100644 --- a/_m3ec/actions.py +++ b/_m3ec/actions.py @@ -117,10 +117,14 @@ def execActions(actions, d, accumulator=None): accumulator = action["dict"][k] elif "default" in ak: accumulator = action["default"] + else: + accumulator = None elif k in d.keys(): accumulator = d[k] elif "default" in ak: accumulator = action["default"] + else: + accumulator = None if "var" in ak: d[readf(action["var"], d)] = readf(accumulator, d) diff --git a/_m3ec/util.py b/_m3ec/util.py index d495707..1205103 100644 --- a/_m3ec/util.py +++ b/_m3ec/util.py @@ -126,6 +126,10 @@ def checkConditionString(condition, d): if condition[1] in val: return not inverted return inverted + elif condition[0] == "#containskey": + if condition[1] in val.keys(): + return not inverted + return inverted elif condition[0] == "#typeis": if condition[1] == "int" and type(val) is int: return not inverted diff --git a/data/fabric1.16.5/registry/ModItems.m3ecjava b/data/fabric1.16.5/registry/ModItems.m3ecjava index da3da52..9e8dae2 100644 --- a/data/fabric1.16.5/registry/ModItems.m3ecjava +++ b/data/fabric1.16.5/registry/ModItems.m3ecjava @@ -28,10 +28,20 @@ ${mod.item.$%v.extraItemSettings}---fi);---end //Food ---iter mod.registry.food.names - public static final Item ${mod.food.$%v.uppercased} = new Item(new Item.Settings().group(${mod.creativemodetab}).food(new FoodComponent.Builder().hunger(${mod.food.$%v.hunger}).saturationModifier(${mod.food.$%v.saturation})---if mod.food.$%v.snack -.snack()---fi---if mod.food.$%v.alwaysEdible -.alwaysEdible()---fi---if mod.food.$%v.statusEffects -${mod.food.$%v.statusEffects}---fi.build()));---end + public static final Item ${mod.food.$%v.uppercased} = new FoodItem(new Item.Settings().group(${mod.creativemodetab}).food(new FoodComponent.Builder() +---if mod.food.$%v.hunger +.hunger(${mod.food.$%v.hunger})---fi +---if mod.food.$%v.saturation +.saturationModifier(${mod.food.$%v.saturation})---fi +---if mod.food.$%v.snack +.snack()---fi +---if mod.food.$%v.alwaysEdible +.alwaysEdible()---fi +---if mod.food.$%v.statusEffects +${mod.food.$%v.statusEffects}---fi +.build()) +---if mod.food.$%v.returnitem +, ${mod.food.$%v.returnItem}---fi);---end //Block Items ---iter mod.registry.blockitem.names diff --git a/data/fabric1.17.1/registry/ModItems.m3ecjava b/data/fabric1.17.1/registry/ModItems.m3ecjava index da3da52..265e314 100644 --- a/data/fabric1.17.1/registry/ModItems.m3ecjava +++ b/data/fabric1.17.1/registry/ModItems.m3ecjava @@ -28,10 +28,20 @@ ${mod.item.$%v.extraItemSettings}---fi);---end //Food ---iter mod.registry.food.names - public static final Item ${mod.food.$%v.uppercased} = new Item(new Item.Settings().group(${mod.creativemodetab}).food(new FoodComponent.Builder().hunger(${mod.food.$%v.hunger}).saturationModifier(${mod.food.$%v.saturation})---if mod.food.$%v.snack -.snack()---fi---if mod.food.$%v.alwaysEdible -.alwaysEdible()---fi---if mod.food.$%v.statusEffects -${mod.food.$%v.statusEffects}---fi.build()));---end + public static final Item ${mod.food.$%v.uppercased} = new FoodItem(Item.Settings().group(${mod.creativemodetab}).food(new FoodComponent.Builder() +---if mod.food.$%v.hunger +.hunger(${mod.food.$%v.hunger})---fi +---if mod.food.$%v.saturation +.saturationModifier(${mod.food.$%v.saturation})---fi +---if mod.food.$%v.snack +.snack()---fi +---if mod.food.$%v.alwaysEdible +.alwaysEdible()---fi +---if mod.food.$%v.statusEffects +${mod.food.$%v.statusEffects}---fi +.build()) +---if mod.food.$%v.returnitem +, ${mod.food.$%v.returnItem}---fi);---end //Block Items ---iter mod.registry.blockitem.names diff --git a/data/fabric1.17/registry/ModItems.m3ecjava b/data/fabric1.17/registry/ModItems.m3ecjava index da3da52..265e314 100644 --- a/data/fabric1.17/registry/ModItems.m3ecjava +++ b/data/fabric1.17/registry/ModItems.m3ecjava @@ -28,10 +28,20 @@ ${mod.item.$%v.extraItemSettings}---fi);---end //Food ---iter mod.registry.food.names - public static final Item ${mod.food.$%v.uppercased} = new Item(new Item.Settings().group(${mod.creativemodetab}).food(new FoodComponent.Builder().hunger(${mod.food.$%v.hunger}).saturationModifier(${mod.food.$%v.saturation})---if mod.food.$%v.snack -.snack()---fi---if mod.food.$%v.alwaysEdible -.alwaysEdible()---fi---if mod.food.$%v.statusEffects -${mod.food.$%v.statusEffects}---fi.build()));---end + public static final Item ${mod.food.$%v.uppercased} = new FoodItem(Item.Settings().group(${mod.creativemodetab}).food(new FoodComponent.Builder() +---if mod.food.$%v.hunger +.hunger(${mod.food.$%v.hunger})---fi +---if mod.food.$%v.saturation +.saturationModifier(${mod.food.$%v.saturation})---fi +---if mod.food.$%v.snack +.snack()---fi +---if mod.food.$%v.alwaysEdible +.alwaysEdible()---fi +---if mod.food.$%v.statusEffects +${mod.food.$%v.statusEffects}---fi +.build()) +---if mod.food.$%v.returnitem +, ${mod.food.$%v.returnItem}---fi);---end //Block Items ---iter mod.registry.blockitem.names diff --git a/data/fabric1.18.1/registry/ModItems.m3ecjava b/data/fabric1.18.1/registry/ModItems.m3ecjava index 8343142..c42ab5a 100644 --- a/data/fabric1.18.1/registry/ModItems.m3ecjava +++ b/data/fabric1.18.1/registry/ModItems.m3ecjava @@ -28,10 +28,20 @@ ${mod.item.$%v.extraItemSettings}---fi);---end //Food ---iter mod.registry.food.names - public static final Item ${mod.food.$%v.uppercased} = new Item(new Item.Settings().group(${mod.creativemodetab}).food(new FoodComponent.Builder().hunger(${mod.food.$%v.hunger}).saturationModifier(${mod.food.$%v.saturation})---if mod.food.$%v.snack -.snack()---fi---if mod.food.$%v.alwaysEdible -.alwaysEdible()---fi---if mod.food.$%v.statusEffects -${mod.food.$%v.statusEffects}---fi.build()));---end + public static final Item ${mod.food.$%v.uppercased} = new FoodItem(new Item.Settings().group(${mod.creativemodetab}).food(new FoodComponent.Builder() +---if mod.food.$%v.hunger +.hunger(${mod.food.$%v.hunger})---fi +---if mod.food.$%v.saturation +.saturationModifier(${mod.food.$%v.saturation})---fi +---if mod.food.$%v.snack +.snack()---fi +---if mod.food.$%v.alwaysEdible +.alwaysEdible()---fi +---if mod.food.$%v.statusEffects +${mod.food.$%v.statusEffects}---fi +.build()) +---if mod.food.$%v.returnitem +, ${mod.food.$%v.returnItem}---fi);---end //Block Items ---iter mod.registry.blockitem.names diff --git a/data/fabric1.18.2/registry/ModItems.m3ecjava b/data/fabric1.18.2/registry/ModItems.m3ecjava index 8343142..c42ab5a 100644 --- a/data/fabric1.18.2/registry/ModItems.m3ecjava +++ b/data/fabric1.18.2/registry/ModItems.m3ecjava @@ -28,10 +28,20 @@ ${mod.item.$%v.extraItemSettings}---fi);---end //Food ---iter mod.registry.food.names - public static final Item ${mod.food.$%v.uppercased} = new Item(new Item.Settings().group(${mod.creativemodetab}).food(new FoodComponent.Builder().hunger(${mod.food.$%v.hunger}).saturationModifier(${mod.food.$%v.saturation})---if mod.food.$%v.snack -.snack()---fi---if mod.food.$%v.alwaysEdible -.alwaysEdible()---fi---if mod.food.$%v.statusEffects -${mod.food.$%v.statusEffects}---fi.build()));---end + public static final Item ${mod.food.$%v.uppercased} = new FoodItem(new Item.Settings().group(${mod.creativemodetab}).food(new FoodComponent.Builder() +---if mod.food.$%v.hunger +.hunger(${mod.food.$%v.hunger})---fi +---if mod.food.$%v.saturation +.saturationModifier(${mod.food.$%v.saturation})---fi +---if mod.food.$%v.snack +.snack()---fi +---if mod.food.$%v.alwaysEdible +.alwaysEdible()---fi +---if mod.food.$%v.statusEffects +${mod.food.$%v.statusEffects}---fi +.build()) +---if mod.food.$%v.returnitem +, ${mod.food.$%v.returnItem}---fi);---end //Block Items ---iter mod.registry.blockitem.names diff --git a/data/fabric1.18/registry/ModItems.m3ecjava b/data/fabric1.18/registry/ModItems.m3ecjava index 8343142..c42ab5a 100644 --- a/data/fabric1.18/registry/ModItems.m3ecjava +++ b/data/fabric1.18/registry/ModItems.m3ecjava @@ -28,10 +28,20 @@ ${mod.item.$%v.extraItemSettings}---fi);---end //Food ---iter mod.registry.food.names - public static final Item ${mod.food.$%v.uppercased} = new Item(new Item.Settings().group(${mod.creativemodetab}).food(new FoodComponent.Builder().hunger(${mod.food.$%v.hunger}).saturationModifier(${mod.food.$%v.saturation})---if mod.food.$%v.snack -.snack()---fi---if mod.food.$%v.alwaysEdible -.alwaysEdible()---fi---if mod.food.$%v.statusEffects -${mod.food.$%v.statusEffects}---fi.build()));---end + public static final Item ${mod.food.$%v.uppercased} = new FoodItem(new Item.Settings().group(${mod.creativemodetab}).food(new FoodComponent.Builder() +---if mod.food.$%v.hunger +.hunger(${mod.food.$%v.hunger})---fi +---if mod.food.$%v.saturation +.saturationModifier(${mod.food.$%v.saturation})---fi +---if mod.food.$%v.snack +.snack()---fi +---if mod.food.$%v.alwaysEdible +.alwaysEdible()---fi +---if mod.food.$%v.statusEffects +${mod.food.$%v.statusEffects}---fi +.build()) +---if mod.food.$%v.returnitem +, ${mod.food.$%v.returnItem}---fi);---end //Block Items ---iter mod.registry.blockitem.names diff --git a/data/fabric1.19.2/registry/ModItems.m3ecjava b/data/fabric1.19.2/registry/ModItems.m3ecjava index 0350a42..28a31e5 100644 --- a/data/fabric1.19.2/registry/ModItems.m3ecjava +++ b/data/fabric1.19.2/registry/ModItems.m3ecjava @@ -28,10 +28,20 @@ ${mod.item.$%v.extraItemSettings}---fi);---end //Food ---iter mod.registry.food.names - public static final Item ${mod.food.$%v.uppercased} = new Item(new Item.Settings().group(${mod.creativemodetab}).food(new FoodComponent.Builder().hunger(${mod.food.$%v.hunger}).saturationModifier(${mod.food.$%v.saturation})---if mod.food.$%v.snack -.snack()---fi---if mod.food.$%v.alwaysEdible -.alwaysEdible()---fi---if mod.food.$%v.statusEffects -${mod.food.$%v.statusEffects}---fi.build()));---end + public static final Item ${mod.food.$%v.uppercased} = new FoodItem(new Item.Settings().group(${mod.creativemodetab}).food(new FoodComponent.Builder() +---if mod.food.$%v.hunger +.hunger(${mod.food.$%v.hunger})---fi +---if mod.food.$%v.saturation +.saturationModifier(${mod.food.$%v.saturation})---fi +---if mod.food.$%v.snack +.snack()---fi +---if mod.food.$%v.alwaysEdible +.alwaysEdible()---fi +---if mod.food.$%v.statusEffects +${mod.food.$%v.statusEffects}---fi +.build()) +---if mod.food.$%v.returnitem +, ${mod.food.$%v.returnItem}---fi);---end //Block Items ---iter mod.registry.blockitem.names diff --git a/data/fabric1.19.3/registry/ModItems.m3ecjava b/data/fabric1.19.3/registry/ModItems.m3ecjava index 38c20c1..6f0a63f 100644 --- a/data/fabric1.19.3/registry/ModItems.m3ecjava +++ b/data/fabric1.19.3/registry/ModItems.m3ecjava @@ -31,10 +31,20 @@ ${mod.item.$%v.extraItemSettings}---fi);---end //Food ---iter mod.registry.food.names - public static final Item ${mod.food.$%v.uppercased} = new Item(new FabricItemSettings().food(new FoodComponent.Builder().hunger(${mod.food.$%v.hunger}).saturationModifier(${mod.food.$%v.saturation})---if mod.food.$%v.snack -.snack()---fi---if mod.food.$%v.alwaysEdible -.alwaysEdible()---fi---if mod.food.$%v.statusEffects -${mod.food.$%v.statusEffects}---fi.build()));---end + public static final Item ${mod.food.$%v.uppercased} = new FoodItem(new FabricItemSettings().food(new FoodComponent.Builder() +---if mod.food.$%v.hunger +.hunger(${mod.food.$%v.hunger})---fi +---if mod.food.$%v.saturation +.saturationModifier(${mod.food.$%v.saturation})---fi +---if mod.food.$%v.snack +.snack()---fi +---if mod.food.$%v.alwaysEdible +.alwaysEdible()---fi +---if mod.food.$%v.statusEffects +${mod.food.$%v.statusEffects}---fi +.build()) +---if mod.food.$%v.returnitem +, ${mod.food.$%v.returnItem}---fi);---end //Block Items ---iter mod.registry.blockitem.names diff --git a/data/fabric1.19.4/registry/ModItems.m3ecjava b/data/fabric1.19.4/registry/ModItems.m3ecjava index 51d00be..d35fd99 100644 --- a/data/fabric1.19.4/registry/ModItems.m3ecjava +++ b/data/fabric1.19.4/registry/ModItems.m3ecjava @@ -31,10 +31,20 @@ ${mod.item.$%v.extraItemSettings}---fi);---end //Food ---iter mod.registry.food.names - public static final Item ${mod.food.$%v.uppercased} = new Item(new FabricItemSettings().food(new FoodComponent.Builder().hunger(${mod.food.$%v.hunger}).saturationModifier(${mod.food.$%v.saturation})---if mod.food.$%v.snack -.snack()---fi---if mod.food.$%v.alwaysEdible -.alwaysEdible()---fi---if mod.food.$%v.statusEffects -${mod.food.$%v.statusEffects}---fi.build()));---end + public static final Item ${mod.food.$%v.uppercased} = new FoodItem(new FabricItemSettings().food(new FoodComponent.Builder() +---if mod.food.$%v.hunger +.hunger(${mod.food.$%v.hunger})---fi +---if mod.food.$%v.saturation +.saturationModifier(${mod.food.$%v.saturation})---fi +---if mod.food.$%v.snack +.snack()---fi +---if mod.food.$%v.alwaysEdible +.alwaysEdible()---fi +---if mod.food.$%v.statusEffects +${mod.food.$%v.statusEffects}---fi +.build()) +---if mod.food.$%v.returnitem +, ${mod.food.$%v.returnItem}---fi);---end //Block Items ---iter mod.registry.blockitem.names diff --git a/data/fabric1.19/registry/ModItems.m3ecjava b/data/fabric1.19/registry/ModItems.m3ecjava index 8343142..c42ab5a 100644 --- a/data/fabric1.19/registry/ModItems.m3ecjava +++ b/data/fabric1.19/registry/ModItems.m3ecjava @@ -28,10 +28,20 @@ ${mod.item.$%v.extraItemSettings}---fi);---end //Food ---iter mod.registry.food.names - public static final Item ${mod.food.$%v.uppercased} = new Item(new Item.Settings().group(${mod.creativemodetab}).food(new FoodComponent.Builder().hunger(${mod.food.$%v.hunger}).saturationModifier(${mod.food.$%v.saturation})---if mod.food.$%v.snack -.snack()---fi---if mod.food.$%v.alwaysEdible -.alwaysEdible()---fi---if mod.food.$%v.statusEffects -${mod.food.$%v.statusEffects}---fi.build()));---end + public static final Item ${mod.food.$%v.uppercased} = new FoodItem(new Item.Settings().group(${mod.creativemodetab}).food(new FoodComponent.Builder() +---if mod.food.$%v.hunger +.hunger(${mod.food.$%v.hunger})---fi +---if mod.food.$%v.saturation +.saturationModifier(${mod.food.$%v.saturation})---fi +---if mod.food.$%v.snack +.snack()---fi +---if mod.food.$%v.alwaysEdible +.alwaysEdible()---fi +---if mod.food.$%v.statusEffects +${mod.food.$%v.statusEffects}---fi +.build()) +---if mod.food.$%v.returnitem +, ${mod.food.$%v.returnItem}---fi);---end //Block Items ---iter mod.registry.blockitem.names diff --git a/data/fabric1.20.1/registry/ModItems.m3ecjava b/data/fabric1.20.1/registry/ModItems.m3ecjava index 262bf59..d35fd99 100644 --- a/data/fabric1.20.1/registry/ModItems.m3ecjava +++ b/data/fabric1.20.1/registry/ModItems.m3ecjava @@ -31,7 +31,7 @@ ${mod.item.$%v.extraItemSettings}---fi);---end //Food ---iter mod.registry.food.names - public static final Item ${mod.food.$%v.uppercased} = new Item(new FabricItemSettings().food(new FoodComponent.Builder() + public static final Item ${mod.food.$%v.uppercased} = new FoodItem(new FabricItemSettings().food(new FoodComponent.Builder() ---if mod.food.$%v.hunger .hunger(${mod.food.$%v.hunger})---fi ---if mod.food.$%v.saturation @@ -42,7 +42,9 @@ ${mod.item.$%v.extraItemSettings}---fi);---end .alwaysEdible()---fi ---if mod.food.$%v.statusEffects ${mod.food.$%v.statusEffects}---fi -.build()));---end +.build()) +---if mod.food.$%v.returnitem +, ${mod.food.$%v.returnItem}---fi);---end //Block Items ---iter mod.registry.blockitem.names diff --git a/data/fabric_common/classes/FoodItem.m3ecjava b/data/fabric_common/classes/FoodItem.m3ecjava new file mode 100644 index 0000000..d884444 --- /dev/null +++ b/data/fabric_common/classes/FoodItem.m3ecjava @@ -0,0 +1,34 @@ +package ${mod.package}.registry; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.TypedActionResult; +import net.minecraft.world.World; + +public class FoodItem extends Item { + private static Item returnItem; + + public FoodItem(Settings settings) { + super(settings); + this.returnItem = null; + } + public FoodItem(Settings settings, Item returnItem) { + super(settings); + this.returnItem = returnItem; + } + + @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)); + } + } + return result; + } +} diff --git a/data/fabric_common/fabric_preactions.json b/data/fabric_common/fabric_preactions.json index 02e4019..d19bd68 100644 --- a/data/fabric_common/fabric_preactions.json +++ b/data/fabric_common/fabric_preactions.json @@ -5,6 +5,11 @@ }, { "action": "execactions", - "file": "${source_path}/common/actions/food_status_effects.json" - } + "file": "${source_path}/fabric_common/food_status_effects.json" + }, + { + "action": "copyf", + "source": "${source_path}/fabric_common/classes/FoodItem.m3ecjava", + "dest": "${build_path}/src/main/java/${mod.packagedir}/registry/FoodItem.java" + } ] \ No newline at end of file diff --git a/data/common/actions/food_status_effects.json b/data/fabric_common/food_status_effects.json similarity index 66% rename from data/common/actions/food_status_effects.json rename to data/fabric_common/food_status_effects.json index 16668d3..e7fa4a3 100644 --- a/data/common/actions/food_status_effects.json +++ b/data/fabric_common/food_status_effects.json @@ -30,7 +30,7 @@ { "action": "setdictkey", "key": "effect", - "value": "${%v^split(' ',3,0)}" + "value": "${%v^split(' ',3,0)^upper}" }, { "action": "setdictkey", @@ -65,10 +65,34 @@ "key": "chance", "value": "1" }, + { + "action": "getdictkey", + "key": "effect", + "dict": { + "DIG_SPEED": "HASTE", + "DIG_SLOWDOWN": "MINING_FATIGUE", + "MOVEMENT_SPEED": "SPEED", + "CONFUSION": "NAUSEA", + "HEAL": "INSTANT_HEALTH", + "DAMAGE_BOOST": "STRENGTH", + "DAMAGE_RESISTANCE": "RESISTANCE", + "HARM": "INSTANT_DAMAGE", + "JUMP": "JUMP_BOOST", + "REGEN": "REGENERATION" + + }, + "var": "convertedeffect" + }, + { + "if": "?convertedeffect != none", + "action": "setdictkey", + "key": "effect", + "value": "${convertedeffect}" + }, { "action": "setdictkey", "key": "statusstring", - "value": "${statusstring}.statusEffect(new StatusEffectInstance(StatusEffects.${effect^upper}, ${duration}, ${level}-1), ${chance})\n" + "value": "${statusstring}.statusEffect(new StatusEffectInstance(StatusEffects.${effect}, ${duration}, ${level}-1), ${chance})\n" } ] }, diff --git a/data/forge1.16.5/m3ec_build.json b/data/forge1.16.5/m3ec_build.json index 7623c62..dbde06b 100644 --- a/data/forge1.16.5/m3ec_build.json +++ b/data/forge1.16.5/m3ec_build.json @@ -3,6 +3,10 @@ "minecraftVersion": "1.16.5", "javaVersion": "8.", "firstActions": [ + { + "action": "print", + "string": "[!] Building for Forge 1.16.5 is currently broken [!]" + }, { "if": [ "^OR", diff --git a/data/forge1.18.1/m3ec_build.json b/data/forge1.18.1/m3ec_build.json index fa92091..3b9a96e 100644 --- a/data/forge1.18.1/m3ec_build.json +++ b/data/forge1.18.1/m3ec_build.json @@ -3,6 +3,10 @@ "minecraftVersion": "1.18.1", "javaVersion": "17.", "firstActions": [ + { + "action": "print", + "string": "[!] Building for Forge 1.16.5 is currently *very* broken [!]" + }, { "if": [ "^OR", diff --git a/data/forge1.18.2/java/item/ModFoods.m3ecjava b/data/forge1.18.2/java/item/ModFoods.m3ecjava index ee6aecd..dce2dec 100644 --- a/data/forge1.18.2/java/item/ModFoods.m3ecjava +++ b/data/forge1.18.2/java/item/ModFoods.m3ecjava @@ -1,9 +1,14 @@ package ${mod.package}.item; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.effect.MobEffects; import net.minecraft.world.food.FoodProperties; public class ModFoods { ---iter mod.registry.food.names public static final FoodProperties ${mod.food.$%v.uppercased} = (new FoodProperties.Builder())---if mod.food.$%v.snack -.fast()---fi.nutrition(${mod.food.$%v.hunger}).saturationMod(${mod.food.$%v.saturation}).build();---end +.fast()---fi.nutrition(${mod.food.$%v.hunger}).saturationMod(${mod.food.$%v.saturation}) +---if mod.food.$%v.statusEffects +${mod.food.$%v.statusEffects}---fi.build();---end } diff --git a/data/forge1.19.2/java/item/ModFoods.m3ecjava b/data/forge1.19.2/java/item/ModFoods.m3ecjava index ee6aecd..dce2dec 100644 --- a/data/forge1.19.2/java/item/ModFoods.m3ecjava +++ b/data/forge1.19.2/java/item/ModFoods.m3ecjava @@ -1,9 +1,14 @@ package ${mod.package}.item; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.effect.MobEffects; import net.minecraft.world.food.FoodProperties; public class ModFoods { ---iter mod.registry.food.names public static final FoodProperties ${mod.food.$%v.uppercased} = (new FoodProperties.Builder())---if mod.food.$%v.snack -.fast()---fi.nutrition(${mod.food.$%v.hunger}).saturationMod(${mod.food.$%v.saturation}).build();---end +.fast()---fi.nutrition(${mod.food.$%v.hunger}).saturationMod(${mod.food.$%v.saturation}) +---if mod.food.$%v.statusEffects +${mod.food.$%v.statusEffects}---fi.build();---end } diff --git a/data/forge1.19/java/item/ModFoods.m3ecjava b/data/forge1.19/java/item/ModFoods.m3ecjava index ee6aecd..dce2dec 100644 --- a/data/forge1.19/java/item/ModFoods.m3ecjava +++ b/data/forge1.19/java/item/ModFoods.m3ecjava @@ -1,9 +1,14 @@ package ${mod.package}.item; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.effect.MobEffects; import net.minecraft.world.food.FoodProperties; public class ModFoods { ---iter mod.registry.food.names public static final FoodProperties ${mod.food.$%v.uppercased} = (new FoodProperties.Builder())---if mod.food.$%v.snack -.fast()---fi.nutrition(${mod.food.$%v.hunger}).saturationMod(${mod.food.$%v.saturation}).build();---end +.fast()---fi.nutrition(${mod.food.$%v.hunger}).saturationMod(${mod.food.$%v.saturation}) +---if mod.food.$%v.statusEffects +${mod.food.$%v.statusEffects}---fi.build();---end } diff --git a/data/forge1.20.1/java/item/ModFoods.m3ecjava b/data/forge1.20.1/java/item/ModFoods.m3ecjava index ee6aecd..dce2dec 100644 --- a/data/forge1.20.1/java/item/ModFoods.m3ecjava +++ b/data/forge1.20.1/java/item/ModFoods.m3ecjava @@ -1,9 +1,14 @@ package ${mod.package}.item; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.effect.MobEffects; import net.minecraft.world.food.FoodProperties; public class ModFoods { ---iter mod.registry.food.names public static final FoodProperties ${mod.food.$%v.uppercased} = (new FoodProperties.Builder())---if mod.food.$%v.snack -.fast()---fi.nutrition(${mod.food.$%v.hunger}).saturationMod(${mod.food.$%v.saturation}).build();---end +.fast()---fi.nutrition(${mod.food.$%v.hunger}).saturationMod(${mod.food.$%v.saturation}) +---if mod.food.$%v.statusEffects +${mod.food.$%v.statusEffects}---fi.build();---end } diff --git a/data/forge1.20.1/java/item/ModItems.m3ecjava b/data/forge1.20.1/java/item/ModItems.m3ecjava index 10f6612..d0d572f 100644 --- a/data/forge1.20.1/java/item/ModItems.m3ecjava +++ b/data/forge1.20.1/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().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/forge_common/classes/FoodItem.m3ecjava b/data/forge_common/classes/FoodItem.m3ecjava new file mode 100644 index 0000000..639524d --- /dev/null +++ b/data/forge_common/classes/FoodItem.m3ecjava @@ -0,0 +1,33 @@ +package ${mod.package}.item; + + +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; + +public class FoodItem extends Item { + private static Item returnItem; + + public FoodItem(Properties pProperties) { + super(pProperties); + returnItem = null; + } + + public FoodItem(Properties pProperties, Item item) { + super(pProperties); + returnItem = 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)); + } + return result; + } +} diff --git a/data/forge_common/food_status_effects.json b/data/forge_common/food_status_effects.json new file mode 100644 index 0000000..1e68747 --- /dev/null +++ b/data/forge_common/food_status_effects.json @@ -0,0 +1,107 @@ +[ + { + "iterate": "mod.registry.food.names", + "action": "execactions", + "actions": [ + { + "if": "?!mod.food.${%v}.saturation #endswith f", + "action": "setdictkey", + "key": "mod.food.${%v}.saturation", + "value": "${mod.food.${%v}.saturation}f" + }, + { + "action": "setdictkey", + "key": "outer", + "value": "${%v}" + }, + { + "if": "?mod.food.${%v}.statuseffects #typeis list", + "action": "execactions", + "actions": [ + { + "action": "setdictkey", + "key": "statusstring", + "value": "" + }, + { + "iterate": "mod.food.${outer}.statusEffects", + "action": "execactions", + "actions": [ + { + "action": "setdictkey", + "key": "effect", + "value": "${%v^split(' ',3,0)^upper}" + }, + { + "action": "setdictkey", + "key": "level", + "value": "${%v^split(' ',3,1)}" + }, + { + "action": "setdictkey", + "key": "duration", + "value": "${%v^split(' ',3,2)}" + }, + { + "action": "setdictkey", + "key": "chance", + "value": "${%v^split(' ',3,3)}" + }, + { + "if": "?level == none", + "action": "setdictkey", + "key": "level", + "value": "2" + }, + { + "if": "?duration == none", + "action": "setdictkey", + "key": "duration", + "value": "600" + }, + { + "if": "?chance == none", + "action": "setdictkey", + "key": "chance", + "value": "1" + }, + { + "action": "getdictkey", + "key": "${effect}", + "dict": { + "HASTE": "DIG_SPEED", + "MINING_FATIGUE": "DIG_SLOWDOWN", + "SPEED": "MOVEMENT_SPEED", + "NAUSEA": "CONFUSION", + "INSTANT_HEALTH": "HEAL", + "STRENGTH": "DAMAGE_BOOST", + "RESISTANCE": "DAMAGE_RESISTANCE", + "INSTANT_DAMAGE": "HARM", + "JUMP_BOOST": "JUMP", + "REGEN": "REGENERATION" + }, + "var": "convertedeffect" + }, + { + "if": "?!convertedeffect #typeis none", + "action": "setdictkey", + "key": "effect", + "value": "${convertedeffect}" + }, + { + "action": "setdictkey", + "key": "statusstring", + "value": "${statusstring}.effect(() -> new MobEffectInstance(MobEffects.${effect}, ${duration}, ${level}-1), ${chance})\n" + } + ] + }, + { + "action": "setdictkey", + "key": "mod.food.${outer}.statuseffects", + "value": "${statusstring}" + } + ] + } + ] + } +] \ No newline at end of file diff --git a/data/forge_common/forge_preactions.json b/data/forge_common/forge_preactions.json index aa29351..8b08fca 100644 --- a/data/forge_common/forge_preactions.json +++ b/data/forge_common/forge_preactions.json @@ -38,6 +38,11 @@ }, { "action": "execactions", - "file": "${source_path}/common/actions/food_status_effects.json" - } + "file": "${source_path}/forge_common/food_status_effects.json" + }, + { + "action": "copyf", + "source": "${source_path}/forge_common/classes/FoodItem.m3ecjava", + "dest": "${build_path}/src/main/java/${mod.packagedir}/item/FoodItem.java" + } ] \ No newline at end of file