-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated Rhino, added WIP Block.registerBuildingMaterial(), removed MapJS
- Loading branch information
1 parent
f1befc4
commit 20f9cbc
Showing
30 changed files
with
264 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
src/main/java/dev/latvian/mods/kubejs/bindings/BuildingMaterialProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package dev.latvian.mods.kubejs.bindings; | ||
|
||
import dev.latvian.mods.kubejs.block.BlockBuilder; | ||
import dev.latvian.mods.kubejs.block.custom.ButtonOrPressurePlateBuilder; | ||
import dev.latvian.mods.kubejs.registry.RegistryKubeEvent; | ||
import dev.latvian.mods.kubejs.util.KubeResourceLocation; | ||
import dev.latvian.mods.kubejs.util.TickDuration; | ||
import dev.latvian.mods.rhino.Context; | ||
import dev.latvian.mods.rhino.type.TypeInfo; | ||
import dev.latvian.mods.rhino.util.HideFromJS; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.state.properties.BlockSetType; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Optional; | ||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
|
||
public record BuildingMaterialProperties( | ||
Blocks blocks, | ||
Optional<Boolean> baseBlock, | ||
Optional<Boolean> baseBlockSuffix, | ||
Consumer<BlockBuilder> properties, | ||
Optional<BlockSetType> behaviour, | ||
Optional<TickDuration> ticksToStayPressed | ||
) { | ||
public record Blocks( | ||
Optional<Boolean> slab, | ||
Optional<Boolean> stairs, | ||
Optional<Boolean> fence, | ||
Optional<Boolean> fenceGate, | ||
Optional<Boolean> wall, | ||
Optional<Boolean> pressurePlate, | ||
Optional<Boolean> button, | ||
Optional<Boolean> trapdoor, | ||
Optional<Boolean> door | ||
) { | ||
} | ||
|
||
public static final TypeInfo TYPE_INFO = TypeInfo.of(BuildingMaterialProperties.class); | ||
|
||
private boolean add(Function<Blocks, Optional<Boolean>> func) { | ||
return blocks == null || func.apply(blocks).orElse(true); | ||
} | ||
|
||
@HideFromJS | ||
public void register(Context cx, RegistryKubeEvent<Block> event, KubeResourceLocation id) { | ||
var builder = new ArrayList<BlockBuilder>(); | ||
|
||
if (baseBlock.orElse(true)) { | ||
boolean _baseBlockSuffix = baseBlockSuffix.orElse(true); | ||
var baseBlock = (BlockBuilder) event.create(cx, _baseBlockSuffix ? id.withPath(p -> p + "_block") : id); | ||
builder.add(baseBlock); | ||
|
||
if (_baseBlockSuffix) { | ||
baseBlock.texture(id.wrapped().withPath(p -> "block/" + p).toString()); | ||
} | ||
} | ||
|
||
if (add(Blocks::slab)) { | ||
builder.add((BlockBuilder) event.create(cx, id.withPath(p -> p + "_slab"), "slab")); | ||
} | ||
|
||
if (add(Blocks::stairs)) { | ||
builder.add((BlockBuilder) event.create(cx, id.withPath(p -> p + "_stairs"), "stairs")); | ||
} | ||
|
||
if (add(Blocks::fence)) { | ||
builder.add((BlockBuilder) event.create(cx, id.withPath(p -> p + "_fence"), "fence")); | ||
} | ||
|
||
if (add(Blocks::fenceGate)) { | ||
builder.add((BlockBuilder) event.create(cx, id.withPath(p -> p + "_fence_gate"), "fence_gate")); | ||
} | ||
|
||
if (add(Blocks::wall)) { | ||
builder.add((BlockBuilder) event.create(cx, id.withPath(p -> p + "_wall"), "wall")); | ||
} | ||
|
||
if (add(Blocks::pressurePlate)) { | ||
builder.add((BlockBuilder) event.create(cx, id.withPath(p -> p + "_pressure_plate"), "pressure_plate")); | ||
} | ||
|
||
if (add(Blocks::button)) { | ||
builder.add((BlockBuilder) event.create(cx, id.withPath(p -> p + "_button"), "button")); | ||
} | ||
|
||
if (add(Blocks::trapdoor)) { | ||
builder.add((BlockBuilder) event.create(cx, id.withPath(p -> p + "_trapdoor"), "trapdoor")); | ||
} | ||
|
||
if (add(Blocks::door)) { | ||
builder.add((BlockBuilder) event.create(cx, id.withPath(p -> p + "_door"), "door")); | ||
} | ||
|
||
for (var b : builder) { | ||
if (properties != null) { | ||
properties.accept(b); | ||
} | ||
|
||
if (b instanceof ButtonOrPressurePlateBuilder p) { | ||
behaviour.ifPresent(p::behaviour); | ||
ticksToStayPressed.ifPresent(p::ticksToStayPressed); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/dev/latvian/mods/kubejs/block/custom/ButtonOrPressurePlateBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package dev.latvian.mods.kubejs.block.custom; | ||
|
||
import dev.latvian.mods.kubejs.block.BlockBuilder; | ||
import dev.latvian.mods.kubejs.util.TickDuration; | ||
import dev.latvian.mods.rhino.util.ReturnsSelf; | ||
import net.minecraft.world.level.block.state.properties.BlockSetType; | ||
|
||
public interface ButtonOrPressurePlateBuilder { | ||
@ReturnsSelf | ||
BlockBuilder behaviour(BlockSetType behaviour); | ||
|
||
@ReturnsSelf | ||
BlockBuilder ticksToStayPressed(TickDuration ticks); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.