Skip to content

Commit

Permalink
Merge pull request #5 from ZZZank/kessjs
Browse files Browse the repository at this point in the history
More custom block/item variants
  • Loading branch information
ZZZank authored Jul 27, 2024
2 parents aa94a38 + e8a03b9 commit b3a0065
Show file tree
Hide file tree
Showing 26 changed files with 1,042 additions and 183 deletions.
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ subprojects {
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
mappings loom.officialMojangMappings()
//jabel, for modern Java syntax
annotationProcessor 'com.github.bsideup.jabel:jabel-javac-plugin:1.0.0'
compileOnly 'com.github.bsideup.jabel:jabel-javac-plugin:1.0.0'
//https://central.sonatype.com/artifact/com.pkware.jabel/jabel-javac-plugin
annotationProcessor 'com.pkware.jabel:jabel-javac-plugin:1.0.1-1'
compileOnly 'com.pkware.jabel:jabel-javac-plugin:1.0.1-1'
}
}

Expand All @@ -38,7 +39,7 @@ allprojects {

tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
sourceCompatibility = 17
sourceCompatibility = 21

// The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too
// JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used.
Expand Down
44 changes: 24 additions & 20 deletions common/src/main/java/dev/latvian/kubejs/BuiltinKubeJSPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,28 +141,32 @@ public void init() {
//block
RegistryInfos.BLOCK.addType("basic", BlockBuilder.class, BlockBuilder::new);
RegistryInfos.BLOCK.addType("detector", DetectorBlock.Builder.class, DetectorBlock.Builder::new);
// RegistryInfo.BLOCK.addType("slab", SlabBlockBuilder.class, SlabBlockBuilder::new);
// RegistryInfo.BLOCK.addType("stairs", StairBlockBuilder.class, StairBlockBuilder::new);
// RegistryInfo.BLOCK.addType("fence", FenceBlockBuilder.class, FenceBlockBuilder::new);
// RegistryInfo.BLOCK.addType("wall", WallBlockBuilder.class, WallBlockBuilder::new);
// RegistryInfo.BLOCK.addType("fence_gate", FenceGateBlockBuilder.class, FenceGateBlockBuilder::new);
// RegistryInfo.BLOCK.addType("pressure_plate", PressurePlateBlockBuilder.class, PressurePlateBlockBuilder::new);
// RegistryInfo.BLOCK.addType("button", ButtonBlockBuilder.class, ButtonBlockBuilder::new);
RegistryInfos.BLOCK.addType("slab", ShapedBlockBuilderProxy.Slab.class, ShapedBlockBuilderProxy.Slab::new);
RegistryInfos.BLOCK.addType("stairs", ShapedBlockBuilderProxy.Stairs.class, ShapedBlockBuilderProxy.Stairs::new);
RegistryInfos.BLOCK.addType("fence", ShapedBlockBuilderProxy.Fence.class, ShapedBlockBuilderProxy.Fence::new);
RegistryInfos.BLOCK.addType("wall", ShapedBlockBuilderProxy.Wall.class, ShapedBlockBuilderProxy.Wall::new);
RegistryInfos.BLOCK.addType("fence_gate", ShapedBlockBuilderProxy.FenceGate.class, ShapedBlockBuilderProxy.FenceGate::new);
RegistryInfos.BLOCK.addType("stone_pressure_plate", ShapedBlockBuilderProxy.StoneButton.class, ShapedBlockBuilderProxy.StoneButton::new);
RegistryInfos.BLOCK.addType("stone_button", ShapedBlockBuilderProxy.StonePressurePlate.class, ShapedBlockBuilderProxy.StonePressurePlate::new);
RegistryInfos.BLOCK.addType("wooden_pressure_plate", ShapedBlockBuilderProxy.WoodenButton.class, ShapedBlockBuilderProxy.WoodenButton::new);
RegistryInfos.BLOCK.addType("wooden_button", ShapedBlockBuilderProxy.WoodenPressurePlate.class, ShapedBlockBuilderProxy.WoodenPressurePlate::new);
// RegistryInfos.BLOCK.addType("pressure_plate", ShapedBlockBuilderProxy.PressurePlate.class, ShapedBlockBuilderProxy.PressurePlate::new);
// RegistryInfos.BLOCK.addType("button", ShapedBlockBuilderProxy.Button.class, ShapedBlockBuilderProxy.Button::new);
// RegistryInfo.BLOCK.addType("falling", FallingBlockBuilder.class, FallingBlockBuilder::new);
// RegistryInfo.BLOCK.addType("crop", CropBlockBuilder.class, CropBlockBuilder::new);
// RegistryInfo.BLOCK.addType("cardinal", HorizontalDirectionalBlockBuilder.class, HorizontalDirectionalBlockBuilder::new);
RegistryInfos.BLOCK.addType("crop", CropBlockBuilder.class, CropBlockBuilder::new);
RegistryInfos.BLOCK.addType("cardinal", HorizontalDirectionalBlockBuilder.class, HorizontalDirectionalBlockBuilder::new);
//item
RegistryInfos.ITEM.addType("basic", ItemBuilder.class, ItemBuilder::new);
// RegistryInfo.ITEM.addType("sword", SwordItemBuilder.class, SwordItemBuilder::new);
// RegistryInfo.ITEM.addType("pickaxe", PickaxeItemBuilder.class, PickaxeItemBuilder::new);
// RegistryInfo.ITEM.addType("axe", AxeItemBuilder.class, AxeItemBuilder::new);
// RegistryInfo.ITEM.addType("shovel", ShovelItemBuilder.class, ShovelItemBuilder::new);
// RegistryInfo.ITEM.addType("shears", ShearsItemBuilder.class, ShearsItemBuilder::new);
// RegistryInfo.ITEM.addType("hoe", HoeItemBuilder.class, HoeItemBuilder::new);
// RegistryInfo.ITEM.addType("helmet", ArmorItemBuilder.Helmet.class, ArmorItemBuilder.Helmet::new);
// RegistryInfo.ITEM.addType("chestplate", ArmorItemBuilder.Chestplate.class, ArmorItemBuilder.Chestplate::new);
// RegistryInfo.ITEM.addType("leggings", ArmorItemBuilder.Leggings.class, ArmorItemBuilder.Leggings::new);
// RegistryInfo.ITEM.addType("boots", ArmorItemBuilder.Boots.class, ArmorItemBuilder.Boots::new);
RegistryInfos.ITEM.addType("sword", CustomItemBuilderProxy.Sword.class, CustomItemBuilderProxy.Sword::new);
RegistryInfos.ITEM.addType("pickaxe", CustomItemBuilderProxy.Pickaxe.class, CustomItemBuilderProxy.Pickaxe::new);
RegistryInfos.ITEM.addType("axe", CustomItemBuilderProxy.Axe.class, CustomItemBuilderProxy.Axe::new);
RegistryInfos.ITEM.addType("shovel", CustomItemBuilderProxy.Shovel.class, CustomItemBuilderProxy.Shovel::new);
RegistryInfos.ITEM.addType("shears", ShearsItemBuilder.class, ShearsItemBuilder::new);
RegistryInfos.ITEM.addType("hoe", CustomItemBuilderProxy.Hoe.class, CustomItemBuilderProxy.Hoe::new);
RegistryInfos.ITEM.addType("helmet", CustomItemBuilderProxy.Helmet.class, CustomItemBuilderProxy.Helmet::new);
RegistryInfos.ITEM.addType("chestplate", CustomItemBuilderProxy.Chestplate.class, CustomItemBuilderProxy.Chestplate::new);
RegistryInfos.ITEM.addType("leggings", CustomItemBuilderProxy.Leggings.class, CustomItemBuilderProxy.Leggings::new);
RegistryInfos.ITEM.addType("boots", CustomItemBuilderProxy.Boots.class, CustomItemBuilderProxy.Boots::new);
RegistryInfos.ITEM.addType("music_disc", RecordItemJS.Builder.class, RecordItemJS.Builder::new);
//misc
RegistryInfos.FLUID.addType("basic", FluidBuilder.class, FluidBuilder::new);
Expand Down Expand Up @@ -557,7 +561,7 @@ public void generateLang(Map<String, String> lang) {

for (var builder : RegistryInfos.ALL_BUILDERS) {
if (builder.overrideLangJson && builder.display != null) {
lang.put(builder.translationKey, builder.display.getString());
lang.put(builder.getTranslationKey(), builder.display.getString());
}
}
}
Expand Down
182 changes: 92 additions & 90 deletions common/src/main/java/dev/latvian/kubejs/block/BlockBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import com.google.gson.JsonObject;
import dev.latvian.kubejs.KubeJSRegistries;
import dev.latvian.kubejs.block.custom.BasicBlockJS;
import dev.latvian.kubejs.block.custom.BasicBlockType;
import dev.latvian.kubejs.block.custom.BlockType;
import dev.latvian.kubejs.client.ModelGenerator;
import dev.latvian.kubejs.client.VariantBlockStateGenerator;
import dev.latvian.kubejs.core.ItemKJS;
import dev.latvian.kubejs.core.BlockKJS;
import dev.latvian.kubejs.generator.AssetJsonGenerator;
import dev.latvian.kubejs.generator.DataJsonGenerator;
import dev.latvian.kubejs.loot.LootBuilder;
Expand All @@ -16,6 +15,7 @@
import dev.latvian.kubejs.script.ScriptType;
import dev.latvian.kubejs.registry.BuilderBase;
import dev.latvian.mods.rhino.annotations.typing.JSInfo;
import dev.latvian.mods.rhino.util.HideFromJS;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import me.shedaniel.architectury.registry.BlockProperties;
import me.shedaniel.architectury.registry.ToolType;
Expand All @@ -30,92 +30,63 @@
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;

/**
* @author LatvianModder
*/
public class BlockBuilder extends BuilderBase<Block> {

public transient BlockType type;
public transient MaterialJS material;
public transient float hardness;
public transient float resistance;
public transient float lightLevel;
public transient ToolType harvestTool;
public transient int harvestLevel;
public transient boolean opaque;
public transient boolean fullBlock;
public transient boolean requiresTool;
public transient String renderType;
public transient Int2IntOpenHashMap color;
public transient BlockType type = BasicBlockType.INSTANCE;
public transient MaterialJS material = MaterialListJS.INSTANCE.map.get("wood");
public transient float hardness = 0.5F;
public transient float resistance = -1F;
public transient float lightLevel = 0F;
public transient ToolType harvestTool = null;
public transient int harvestLevel = -1;
public transient boolean opaque = true;
public transient boolean fullBlock = false;
public transient boolean requiresTool = false;
public transient String renderType = "solid";
public transient Int2IntOpenHashMap color = new Int2IntOpenHashMap();
public transient BlockTintFunction tint;
public transient final JsonObject textures;
public transient String model;
public transient final JsonObject textures = new JsonObject();
public transient String model = "";
public transient BlockItemBuilder itemBuilder;
public transient List<AABB> customShape;
public transient boolean noCollission;
public transient boolean notSolid;
public transient boolean waterlogged;
public transient List<AABB> customShape = new ArrayList<>();
public transient boolean noCollission = false;
public transient boolean notSolid = false;
public transient boolean waterlogged = false;
public transient float slipperiness = 0.6F;
public transient float speedFactor = 1.0F;
public transient float jumpFactor = 1.0F;
public Consumer<RandomTickCallbackJS> randomTickCallback;
public Consumer<RandomTickCallbackJS> randomTickCallback = null;
public Consumer<LootBuilder> lootTable;
public JsonObject blockstateJson;
public JsonObject modelJson;
public transient boolean noValidSpawns;
public transient boolean suffocating;
public transient boolean viewBlocking;
public transient boolean redstoneConductor;
public transient boolean transparent;
public transient Set<String> defaultTags;
public JsonObject blockstateJson = null;
public JsonObject modelJson = null;
public transient boolean noValidSpawns = false;
public transient boolean suffocating = true;
public transient boolean viewBlocking = true;
public transient boolean redstoneConductor = true;
public transient boolean transparent = false;

public transient Block block;
public transient Block block;

public BlockBuilder(ResourceLocation id) {
super(id);
type = BasicBlockType.INSTANCE;
material = MaterialListJS.INSTANCE.map.get("wood");
hardness = 0.5F;
resistance = -1F;
lightLevel = 0F;
harvestTool = null;
harvestLevel = -1;
opaque = true;
fullBlock = false;
requiresTool = false;
renderType = "solid";
color = new Int2IntOpenHashMap();
color.defaultReturnValue(0xFFFFFFFF);
textures = new JsonObject();
color.defaultReturnValue(0xFFFFFFFF);
textureAll(id.getNamespace() + ":block/" + id.getPath());
model = "";
itemBuilder = new BlockItemBuilder(id);
itemBuilder = new BlockItemBuilder(id);
itemBuilder.blockBuilder = this;
customShape = new ArrayList<>();
noCollission = false;
notSolid = false;
waterlogged = false;
randomTickCallback = null;

lootTable = loot -> loot.addPool(pool -> {
lootTable = loot -> loot.addPool(pool -> {
pool.survivesExplosion();
pool.addItem(new ItemStack(block));
});

blockstateJson = null;
modelJson = null;
noValidSpawns = false;
suffocating = true;
viewBlocking = true;
redstoneConductor = true;
transparent = false;
defaultTags = new HashSet<>();
}
}

@Override
public RegistryInfo<Block> getRegistryType() {
Expand All @@ -124,16 +95,19 @@ public RegistryInfo<Block> getRegistryType() {

@Override
public Block createObject() {
return new BasicBlockJS(this);
return this.type.createBlock(this);
}

@Override
public Block transformObject(Block obj) {
((BlockKJS) obj).setBlockBuilderKJS(this);
return obj;
}

@Override
public void createAdditionalObjects() {
if (this.itemBuilder != null) {
KubeJSRegistries.items().register(itemBuilder.id, () -> itemBuilder.createObject());
if (itemBuilder.blockItem instanceof ItemKJS kjsItem) {
kjsItem.setItemBuilderKJS(itemBuilder);
}
KubeJSRegistries.items().register(itemBuilder.id, () -> itemBuilder.get());
}
}

Expand All @@ -142,7 +116,12 @@ public String getBuilderType() {
return "block";
}

public BlockBuilder type(BlockType t) {
@Deprecated
public Set<String> getDefaultTags() {
return tags.stream().map(ResourceLocation::toString).collect(Collectors.toSet());
}

public BlockBuilder type(BlockType t) {
type = t;
type.applyDefaults(this);
return this;
Expand Down Expand Up @@ -392,18 +371,22 @@ public BlockBuilder box(double x0, double y0, double z0, double x1, double y1, d
return box(x0, y0, z0, x1, y1, z1, true);
}

public VoxelShape createShape() {
if (customShape.isEmpty()) {
return Shapes.block();
}
public static VoxelShape createShape(List<AABB> boxes) {
if (boxes.isEmpty()) {
return Shapes.block();
}

VoxelShape shape = Shapes.create(customShape.get(0));
var shape = Shapes.create(boxes.get(0));

for (int i = 1; i < customShape.size(); i++) {
shape = Shapes.or(shape, Shapes.create(customShape.get(i)));
}
for (var i = 1; i < boxes.size(); i++) {
shape = Shapes.or(shape, Shapes.create(boxes.get(i)));
}

return shape;
}

return shape;
public VoxelShape createShape() {
return createShape(this.customShape);
}

public BlockBuilder noCollission() {
Expand Down Expand Up @@ -477,25 +460,44 @@ public BlockBuilder transparent(boolean b) {
}

public BlockBuilder defaultCutout() {
return renderType("cutout").notSolid().noValidSpawns(true).suffocating(false).viewBlocking(false).redstoneConductor(false).transparent(true);
}
return renderType("cutout").notSolid()
.noValidSpawns(true)
.suffocating(false)
.viewBlocking(false)
.redstoneConductor(false)
.transparent(true);
}

public BlockBuilder defaultTranslucent() {
return defaultCutout().renderType("translucent");
}

public BlockBuilder tag(String tag) {
defaultTags.add(tag);
return this;
}
@JSInfo("Tags the block with the given tag.")
public BlockBuilder tag(ResourceLocation tag) {
super.tag(tag);
return this;
}

public BlockBuilder tagBlockAndItem(String tag) {
defaultTags.add(tag);
itemBuilder.tags.add(ResourceLocation.tryParse(tag));
return this;
}
@JSInfo("Tags the item with the given tag.")
public BlockBuilder tagItem(ResourceLocation tag) {
itemBuilder.tag(tag);
return this;
}

@JSInfo("Tags both the block and the item with the given tag.")
public BlockBuilder tagBlockAndItem(ResourceLocation tag) {
tag(tag);
tagItem(tag);
return this;
}

@Deprecated
@HideFromJS
public BlockBuilder tagBlockAndItem(String tag) {
return tagBlockAndItem(new ResourceLocation(tag));
}

public Block.Properties createProperties() {
public Block.Properties createProperties() {
BlockProperties properties = BlockProperties.of(material.getMinecraftMaterial());
properties.sound(material.getSound());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ private MaterialListJS() {
add("berry_bush", Material.PLANT, SoundType.SWEET_BERRY_BUSH);
add("lantern", Material.METAL, SoundType.LANTERN);

//kessjs
add("crop", Material.PLANT, SoundType.CROP);

// Legacy
add("rock", Material.STONE, SoundType.STONE);
add("iron", Material.METAL, SoundType.METAL);
Expand Down
Loading

0 comments on commit b3a0065

Please sign in to comment.