diff --git a/docs/ADDING_MACHINES.md b/docs/ADDING_MACHINES.md index 4d71738a5..9a4f09405 100644 --- a/docs/ADDING_MACHINES.md +++ b/docs/ADDING_MACHINES.md @@ -316,14 +316,22 @@ Methods that config exposes: ## Adding new casing types See [MACHINE_MODELS.md](MACHINE_MODELS.md) for an explanation of machine models and what casings are. -You can add new casings using the `register` function in the `MIMachineEvents.registerCasings` event. +You can add new casings using the `MIMachineEvents.registerCasings` event. +- Use the `register` function if you will also be adding a JSON model for the casing. +- Use the `registerBlockImitation` function to add a casing that will imitate another block. -Remember that the top, side and bottom textures of a casing must be `modern_industrialization:textures/block/casings//{top,side,bottom}.png`. +If you use `register` and want a texture-based casing model, +remember that the top, side and bottom textures of a casing must be `modern_industrialization:textures/block/casings//{top,side,bottom}.png`. -For example, to register two new casings: +For example: ```js MIMachineEvents.registerCasings(event => { + // Register two casings. + // This doesn't register any model! Either add models or add the top/side/bottom textures. event.register("my_fancy_casing", "my_other_casing"); + + // This registers a new casing with the same model as a diamond block! + event.registerBlockImitation("my_diamond_casing", "minecraft:diamond_block"); }) ``` @@ -393,4 +401,4 @@ MIMachineEvents.registerMachines(event => { true, false, false // front overlay?, top overlay?, side overlay? ); }); -``` \ No newline at end of file +``` diff --git a/src/client/java/aztech/modern_industrialization/datagen/model/MachineCasingsProvider.java b/src/client/java/aztech/modern_industrialization/datagen/model/MachineCasingsProvider.java index a7738eece..430dac3a8 100644 --- a/src/client/java/aztech/modern_industrialization/datagen/model/MachineCasingsProvider.java +++ b/src/client/java/aztech/modern_industrialization/datagen/model/MachineCasingsProvider.java @@ -37,8 +37,10 @@ import java.util.function.BiConsumer; import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; import net.minecraft.data.CachedOutput; import net.minecraft.data.DataProvider; +import net.minecraft.resources.ResourceKey; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; @@ -91,6 +93,10 @@ private void generate(BiConsumer imitateBlock) { imitateBlock.accept(MachineCasings.SOLID_TITANIUM, MIMaterials.TITANIUM.getPart(MIParts.MACHINE_CASING_SPECIAL).asBlock()); imitateBlock.accept(MachineCasings.NUCLEAR, MIMaterials.NUCLEAR_ALLOY.getPart(MIParts.MACHINE_CASING_SPECIAL).asBlock()); imitateBlock.accept(MachineCasings.PLASMA_HANDLING_IRIDIUM, MIMaterials.IRIDIUM.getPart(MIParts.MACHINE_CASING_SPECIAL).asBlock()); + + for (var entry : MachineCasingImitations.imitationsToGenerate.entrySet()) { + imitateBlock.accept(entry.getKey(), BuiltInRegistries.BLOCK.getOrThrow(ResourceKey.create(Registries.BLOCK, entry.getValue()))); + } } @Override diff --git a/src/main/java/aztech/modern_industrialization/compat/kubejs/machine/RegisterCasingsEventJS.java b/src/main/java/aztech/modern_industrialization/compat/kubejs/machine/RegisterCasingsEventJS.java index 8b92dc66c..6f550fa06 100644 --- a/src/main/java/aztech/modern_industrialization/compat/kubejs/machine/RegisterCasingsEventJS.java +++ b/src/main/java/aztech/modern_industrialization/compat/kubejs/machine/RegisterCasingsEventJS.java @@ -23,8 +23,11 @@ */ package aztech.modern_industrialization.compat.kubejs.machine; +import aztech.modern_industrialization.datagen.model.MachineCasingImitations; import aztech.modern_industrialization.machines.models.MachineCasings; import dev.latvian.mods.kubejs.event.EventJS; +import java.util.Objects; +import net.minecraft.resources.ResourceLocation; public class RegisterCasingsEventJS extends EventJS { public void register(String... names) { @@ -36,4 +39,13 @@ public void register(String... names) { MachineCasings.create(name); } } + + public void registerBlockImitation(String name, ResourceLocation block) { + Objects.requireNonNull(block, "block may not be null"); + if (name.contains(":")) { + throw new IllegalArgumentException("Casing name cannot contain ':'."); + } + + MachineCasingImitations.imitationsToGenerate.put(MachineCasings.create(name), block); + } } diff --git a/src/main/java/aztech/modern_industrialization/datagen/model/MachineCasingImitations.java b/src/main/java/aztech/modern_industrialization/datagen/model/MachineCasingImitations.java new file mode 100644 index 000000000..ec4fee38f --- /dev/null +++ b/src/main/java/aztech/modern_industrialization/datagen/model/MachineCasingImitations.java @@ -0,0 +1,33 @@ +/* + * MIT License + * + * Copyright (c) 2020 Azercoco & Technici4n + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package aztech.modern_industrialization.datagen.model; + +import aztech.modern_industrialization.machines.models.MachineCasing; +import java.util.HashMap; +import java.util.Map; +import net.minecraft.resources.ResourceLocation; + +public class MachineCasingImitations { + public static final Map imitationsToGenerate = new HashMap<>(); +}