Skip to content

Commit

Permalink
Misc. fixes, warn about certain builds being broken, add returnItem f…
Browse files Browse the repository at this point in the history
…or food items
  • Loading branch information
beckadamtheinventor committed Feb 24, 2024
1 parent 42f6ad7 commit d5569b4
Show file tree
Hide file tree
Showing 26 changed files with 401 additions and 53 deletions.
4 changes: 4 additions & 0 deletions _m3ec/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions _m3ec/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions data/fabric1.16.5/registry/ModItems.m3ecjava
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions data/fabric1.17.1/registry/ModItems.m3ecjava
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions data/fabric1.17/registry/ModItems.m3ecjava
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions data/fabric1.18.1/registry/ModItems.m3ecjava
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions data/fabric1.18.2/registry/ModItems.m3ecjava
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions data/fabric1.18/registry/ModItems.m3ecjava
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions data/fabric1.19.2/registry/ModItems.m3ecjava
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions data/fabric1.19.3/registry/ModItems.m3ecjava
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions data/fabric1.19.4/registry/ModItems.m3ecjava
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions data/fabric1.19/registry/ModItems.m3ecjava
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions data/fabric1.20.1/registry/ModItems.m3ecjava
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
34 changes: 34 additions & 0 deletions data/fabric_common/classes/FoodItem.m3ecjava
Original file line number Diff line number Diff line change
@@ -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<ItemStack> use(World world, PlayerEntity user, Hand hand) {
TypedActionResult<ItemStack> result = super.use(world, user, hand);
if (result.getResult() == ActionResult.SUCCESS) {
if (returnItem != null) {
user.giveItemStack(new ItemStack(returnItem, 1));
}
}
return result;
}
}
9 changes: 7 additions & 2 deletions data/fabric_common/fabric_preactions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
{
"action": "setdictkey",
"key": "effect",
"value": "${%v^split(' ',3,0)}"
"value": "${%v^split(' ',3,0)^upper}"
},
{
"action": "setdictkey",
Expand Down Expand Up @@ -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"
}
]
},
Expand Down
Loading

0 comments on commit d5569b4

Please sign in to comment.