Skip to content

Commit

Permalink
Add KubeJS API for casings to easily imitate blocks (#697)
Browse files Browse the repository at this point in the history
Technici4n authored Apr 12, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 5975832 commit 0efc2bf
Showing 4 changed files with 63 additions and 4 deletions.
16 changes: 12 additions & 4 deletions docs/ADDING_MACHINES.md
Original file line number Diff line number Diff line change
@@ -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/<casing name>/{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/<casing name>/{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?
);
});
```
```
Original file line number Diff line number Diff line change
@@ -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<MachineCasing, Block> 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
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<MachineCasing, ResourceLocation> imitationsToGenerate = new HashMap<>();
}

0 comments on commit 0efc2bf

Please sign in to comment.