diff --git a/_m3ec/util.py b/_m3ec/util.py index 9f041cd..2ef2f88 100644 --- a/_m3ec/util.py +++ b/_m3ec/util.py @@ -857,6 +857,10 @@ def readf(data, d): w = w.capitalize() elif fn.lower() == "title": w = w.title() + elif fn.lower() == "class": + w = "".join([s.capitalize() for s in w.replace("_", " ").split(" ")]) + elif fn.lower() == "bool": + w = "true" if w else "false" elif fn.lower() == "float": if type(w) is str: if not w.endswith("f"): diff --git a/data/default_content_files/fluid.m3ec b/data/default_content_files/fluid.m3ec new file mode 100644 index 0000000..a5d356b --- /dev/null +++ b/data/default_content_files/fluid.m3ec @@ -0,0 +1,26 @@ +@: fluid +fluid: SimpleFluid +contentid: +title: +texture: + +# block to copy properties from +copyblock: Blocks.WATER + +# update speed of the fluid? +# probably measured in ticks +tickrate: 5 + +# fluid level decrease per block spread +decreaseperblock: 1 + +# flow speed of the fluid. +# probably measured in ticks +flowspeed: 4 + +# Whether the fluid creates source blocks like water +isinfinite: false + +# Hex color of fluid. +# 2 digits for each Red, Green, Blue, Alpha +color: 0x808080D0 diff --git a/data/fabric1.20.1/MainClass.m3ecjava b/data/fabric1.20.1/MainClass.m3ecjava index 85c04fe..4482478 100644 --- a/data/fabric1.20.1/MainClass.m3ecjava +++ b/data/fabric1.20.1/MainClass.m3ecjava @@ -2,10 +2,9 @@ package ${mod.package}; import ${mod.package}.registry.ModBlocks; import ${mod.package}.registry.ModItems; ----iter mod.registry.recipetype.names -import ${mod.package}.recipetype.${mod.recipetype.$%v.class}Serializer; -import ${mod.package}.recipetype.${mod.recipetype.$%v.class}Recipe;---end - +import ${mod.package}.registry.ModFluids; +---if mod.registry.recipetype #length nonzero +import ${mod.package}.recipetype.*;---fi ---iter mainclass.imports import $%v;---end import net.fabricmc.loader.api.FabricLoader; @@ -67,6 +66,7 @@ public class ${mod.class} implements ModInitializer { $%v---end ModItems.RegisterItems(); ModBlocks.RegisterBlocks(); + ModFluids.RegisterFluids(); ---iter mod.registry.recipetype.names Registry.register(Registry.RECIPE_SERIALIZER, ${mod.recipetype.$%v.class}Serializer.ID, ${mod.recipetype.$%v.class}Serializer.INSTANCE); Registry.register(Registry.RECIPE_TYPE, new Identifier(${mod.class}.MOD_ID, "$%v"), ${mod.recipetype.$%v.class}Recipe.Type.INSTANCE);---end @@ -87,6 +87,8 @@ public class ${mod.class} implements ModInitializer { entries.add(ModItems.${mod.tool.$%v^upper});---end ---iter mod.registry.sapling.names entries.add(ModItems.${mod.sapling.$%v^upper});---end +---iter mod.registry.fluid.names + entries.add(ModFluids.${mod.fluid.$%v^upper}_BUCKET);---end }) .build() );---fi diff --git a/data/fabric1.20.1/MainClassClient.m3ecjava b/data/fabric1.20.1/MainClassClient.m3ecjava new file mode 100644 index 0000000..df3c001 --- /dev/null +++ b/data/fabric1.20.1/MainClassClient.m3ecjava @@ -0,0 +1,23 @@ +package ${mod.package}; + +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; +import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry; +import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry; +import net.fabricmc.fabric.api.client.render.fluid.v1.SimpleFluidRenderHandler; +import ${mod.package}.registry.ModBlocks; +import ${mod.package}.registry.ModFluids; +import net.minecraft.client.render.RenderLayer; + +public class ${mod.class}Client implements ClientModInitializer { + @Override + public void onInitializeClient() { + +---iter mod.registry.fluid.names + FluidRenderHandlerRegistry.INSTANCE.register(ModFluids.STILL_${mod.fluid.$%v^upper}, ModFluids.FLOWING_${mod.fluid.$%v^upper}, + SimpleFluidRenderHandler.coloredWater(${mod.fluid.$%v.color})); + BlockRenderLayerMap.INSTANCE.putFluids(RenderLayer.getTranslucent(), + ModFluids.STILL_${mod.fluid.$%v^upper}, ModFluids.FLOWING_${mod.fluid.$%v^upper}); +---end + } +} \ No newline at end of file diff --git a/data/fabric1.20.1/m3ec_build.json b/data/fabric1.20.1/m3ec_build.json index caa045e..e0a1e48 100644 --- a/data/fabric1.20.1/m3ec_build.json +++ b/data/fabric1.20.1/m3ec_build.json @@ -19,6 +19,7 @@ "action": "makedir", "value": [ "src/main/java/${mod.packagedir}/blocks", + "src/main/java/${mod.packagedir}/fluids", "src/main/java/${mod.packagedir}/features", "src/main/java/${mod.packagedir}/recipetype", "src/main/resources/assets/minecraft", @@ -119,6 +120,10 @@ "source": "MainClass.m3ecjava", "dest": "src/main/java/${mod.packagedir}/${mod.class}.java" }, + { + "source": "MainClassClient.m3ecjava", + "dest": "src/main/java/${mod.packagedir}/${mod.class}Client.java" + }, { "source": "registry/ModBlocks.m3ecjava", "dest": "src/main/java/${mod.packagedir}/registry/ModBlocks.java" @@ -127,6 +132,10 @@ "source": "registry/ModItems.m3ecjava", "dest": "src/main/java/${mod.packagedir}/registry/ModItems.java" }, + { + "source": "registry/ModFluids.m3ecjava", + "dest": "src/main/java/${mod.packagedir}/registry/ModFluids.java" + }, { "iterate": "mod.registry.toolmaterial.names", "source": "../fabric_common/ToolMaterial.m3ecjava", @@ -157,6 +166,11 @@ "source": "recipetype/RecipeSerializer.m3ecjava", "dest": "src/main/java/${mod.packagedir}/recipetype/${mod.recipetype.${%v}.class}Serializer.java" }, + { + "iterate": "mod.registry.fluid.names", + "source": "registry/Fluid.m3ecjava", + "dest": "src/main/java/${mod.packagedir}/fluids/${mod.fluid.${%v}.class}Fluid.java" + }, { "iterate": "mod.registry.sapling.names", "source": "registry/SaplingBlock.m3ecjava", diff --git a/data/fabric1.20.1/registry/Fluid.m3ecjava b/data/fabric1.20.1/registry/Fluid.m3ecjava new file mode 100644 index 0000000..a2a7756 --- /dev/null +++ b/data/fabric1.20.1/registry/Fluid.m3ecjava @@ -0,0 +1,121 @@ +package ${mod.package}.fluids; + +import ${mod.package}.registry.ModFluids; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.fluid.FlowableFluid; +import net.minecraft.fluid.Fluid; +import net.minecraft.fluid.FluidState; +import net.minecraft.item.Item; +import net.minecraft.state.StateManager; +import net.minecraft.state.property.Properties; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.BlockView; +import net.minecraft.world.World; +import net.minecraft.world.WorldAccess; +import net.minecraft.world.WorldView; + +public abstract class ${mod.fluid.${%v}^class}Fluid extends FlowableFluid { + @Override + public Fluid getFlowing() { + return ModFluids.FLOWING_${mod.fluid.${%v}^upper}; + } + + @Override + public Fluid getStill() { + return ModFluids.STILL_${mod.fluid.${%v}^upper}; + } + + @Override + protected boolean isInfinite(World world) { + return ${mod.fluid.${%v}.isinfinite^bool}; + } + + @Override + protected void beforeBreakingBlock(WorldAccess world, BlockPos pos, BlockState state) { + final BlockEntity blockEntity = state.hasBlockEntity() ? world.getBlockEntity(pos) : null; + Block.dropStacks(state, world, pos, blockEntity); + } + + @Override + protected int getFlowSpeed(WorldView world) { + return ${mod.fluid.${%v}.flowspeed^int}; + } + + @Override + protected int getLevelDecreasePerBlock(WorldView world) { + return ${mod.fluid.${%v}.decreaseperblock^int}; + } + + @Override + public Item getBucketItem() { + return ModFluids.${mod.fluid.${%v}^upper}_BUCKET; + } + + @Override + protected boolean canBeReplacedWith(FluidState state, BlockView world, BlockPos pos, Fluid fluid, Direction direction) { + return false; + } + + @Override + public int getTickRate(WorldView world) { + return ${mod.fluid.${%v}.tickrate}; + } + + @Override + protected float getBlastResistance() { + return 100f; + } + + @Override + public boolean matchesType(Fluid fluid) { + return fluid == getStill() || fluid == getFlowing(); + } + + @Override + protected BlockState toBlockState(FluidState state) { + return ModFluids.${mod.fluid.${%v}^upper}_FLUID_BLOCK.getDefaultState().with(Properties.LEVEL_15, getBlockStateLevel(state)); + } + + @Override + public boolean isStill(FluidState state) { + return false; + } + + @Override + public int getLevel(FluidState state) { + return 0; + } + + public static class Flowing extends ${mod.fluid.${%v}^class}Fluid { + @Override + protected void appendProperties(StateManager.Builder builder) { + super.appendProperties(builder); + builder.add(LEVEL); + } + + @Override + public int getLevel(FluidState state) { + return state.get(LEVEL); + } + + @Override + public boolean isStill(FluidState state) { + return false; + } + } + + public static class Still extends ${mod.fluid.${%v}^class}Fluid { + @Override + public int getLevel(FluidState state) { + return 8; + } + + @Override + public boolean isStill(FluidState state) { + return true; + } + } +} diff --git a/data/fabric1.20.1/registry/ModFluids.m3ecjava b/data/fabric1.20.1/registry/ModFluids.m3ecjava new file mode 100644 index 0000000..07dac10 --- /dev/null +++ b/data/fabric1.20.1/registry/ModFluids.m3ecjava @@ -0,0 +1,36 @@ +package ${mod.package}.registry; + +import ${mod.package}.${mod.class}; +import ${mod.package}.fluids.*; +import net.fabricmc.fabric.api.block.v1.FabricBlock; +import net.fabricmc.fabric.api.item.v1.FabricItemSettings; +import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.minecraft.block.Block; +import net.minecraft.block.Blocks; +import net.minecraft.block.FluidBlock; +import net.minecraft.fluid.FlowableFluid; +import net.minecraft.item.BucketItem; +import net.minecraft.item.Item; +import net.minecraft.item.Items; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; +import net.minecraft.util.Identifier; + +public class ModFluids { +---iter mod.registry.fluid.names + public static final FlowableFluid STILL_${mod.fluid.$%v^upper} = Registry.register(Registries.FLUID, + new Identifier(TestRubyMod.MOD_ID, "${mod.fluid.$%v}"), + new ${mod.fluid.$%v^class}Fluid.Still()); + public static final FlowableFluid FLOWING_${mod.fluid.$%v^upper} = Registry.register(Registries.FLUID, + new Identifier(TestRubyMod.MOD_ID, "flowing_${mod.fluid.$%v}"), + new ${mod.fluid.$%v^class}Fluid.Flowing()); + public static final Block ${mod.fluid.$%v^upper}_FLUID_BLOCK = Registry.register(Registries.BLOCK, + new Identifier(TestRubyMod.MOD_ID, "${mod.fluid.$%v}_block"), + new FluidBlock(ModFluids.STILL_${mod.fluid.$%v^upper}, FabricBlockSettings.copyOf(${mod.fluid.$%v.copyblock}))); + public static final Item ${mod.fluid.$%v^upper}_BUCKET = Registry.register(Registries.ITEM, + new Identifier(TestRubyMod.MOD_ID, "${mod.fluid.$%v}_bucket"), + new BucketItem(ModFluids.STILL_${mod.fluid.$%v^upper}, new FabricItemSettings().recipeRemainder(Items.BUCKET).maxCount(1))); +---end + + public static void RegisterFluids() {} +} diff --git a/m3ec.py b/m3ec.py index 46e3ea2..f9b995e 100644 --- a/m3ec.py +++ b/m3ec.py @@ -10,7 +10,7 @@ def interpret_args(argv): if argv[0].lower() == "help": print("""Usage: project_path all|fabric|forge[gameversion]|fabric[gameversion] -gen|generate manifest|item|food|fuel|block|sapling|ore|(shaped|shapeless|smelting|stonecutting|smithing)recipe|armor[material]|tool[material] [output_file] +gen|generate manifest|item|food|fuel|block|fluid|sapling|ore|(shaped|shapeless|smelting|stonecutting|smithing)recipe|armor[material]|tool[material] [output_file] """) elif len(argv) > 1: if argv[0].lower() in ("generate", "gen"): @@ -145,7 +145,7 @@ def build(project_path, modenv): def build_mod(modloader, version, modenv, manifest_dict): - content_types_list = ["item", "food", "fuel", "block", "ore", "recipe", "armor", "tool", + content_types_list = ["item", "food", "fuel", "block", "fluid", "ore", "recipe", "armor", "tool", "armormaterial", "toolmaterial", "enchantment", "recipetype", "sapling"] print(f"\n\ \n\ diff --git a/testrubymod/fluids/molten_ruby.m3ec b/testrubymod/fluids/molten_ruby.m3ec new file mode 100644 index 0000000..dee400f --- /dev/null +++ b/testrubymod/fluids/molten_ruby.m3ec @@ -0,0 +1,26 @@ +@: fluid +fluid: SimpleFluid +contentid: molten_ruby +title: Molten Ruby +texture: molten_ruby.png + +# block to copy properties from +copyblock: Blocks.LAVA + +# update speed of the fluid? +# probably measured in ticks +tickrate: 5 + +# fluid level decrease per block spread +decreaseperblock: 1 + +# flow speed of the fluid. +# probably measured in ticks +flowspeed: 4 + +# Whether the fluid creates source blocks like water +isinfinite: false + +# Hex color of fluid. +# 2 digits for each Red, Green, Blue, Alpha +color: 0xE02020D0 diff --git a/testrubymod/manifest.txt b/testrubymod/manifest.txt index a0283c6..9100e5a 100644 --- a/testrubymod/manifest.txt +++ b/testrubymod/manifest.txt @@ -49,6 +49,7 @@ mod: #paths to mod items, blocks, recipes, etc +.paths: items +.paths: blocks ++.paths: fluids +.paths: recipes +.paths: foods +.paths: armor diff --git a/testrubymod/textures/molten_ruby.png b/testrubymod/textures/molten_ruby.png new file mode 100644 index 0000000..201774c Binary files /dev/null and b/testrubymod/textures/molten_ruby.png differ