Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add server translation option, clean up BlockType and block creation #44

Merged
merged 4 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

public class TypedGroupedBlockItem extends BlockItem implements TypedGrouped {
public static final String BLOCKTYPE_BLOCK_KEY = "architecture_extensions.block_type_block";
public static final String GROUPED_BLOCK_PREFIX = "architecture_extensions.grouped_block";
public static final String BLOCK_TYPE_PREFIX = "architecture_extensions.block_type";
public static final String MISSING_LOCALIZATION_KEY = "architecture_extensions.i18n.missing_key";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,83 @@

public final class VanillaBlockGroups {
public static final BlockGroup WOOD = BlockGroup.of(
new BlockGroup.GroupedBlock("oak", Blocks.OAK_LOG, TextureConfiguration.WOOD_WITH_LOG.apply(new Identifier("oak")), RecipeConfigurator.SAWING, MapColor.WOOD),
new BlockGroup.GroupedBlock("spruce", Blocks.SPRUCE_LOG, TextureConfiguration.WOOD_WITH_LOG.apply(new Identifier("spruce")), RecipeConfigurator.SAWING, MapColor.PODZOL),
new BlockGroup.GroupedBlock("birch", Blocks.BIRCH_LOG, TextureConfiguration.WOOD_WITH_LOG.apply(new Identifier("birch")), RecipeConfigurator.SAWING, MapColor.SAND),
new BlockGroup.GroupedBlock("jungle", Blocks.JUNGLE_LOG, TextureConfiguration.WOOD_WITH_LOG.apply(new Identifier("jungle")), RecipeConfigurator.SAWING, MapColor.DIRT),
new BlockGroup.GroupedBlock("acacia", Blocks.ACACIA_LOG, TextureConfiguration.WOOD_WITH_LOG.apply(new Identifier("acacia")), RecipeConfigurator.SAWING, MapColor.ORANGE),
new BlockGroup.GroupedBlock("cherry", Blocks.CHERRY_LOG, TextureConfiguration.WOOD_WITH_LOG.apply(new Identifier("cherry")), RecipeConfigurator.SAWING, MapColor.WHITE_TERRACOTTA),
new BlockGroup.GroupedBlock("dark_oak", Blocks.DARK_OAK_LOG, TextureConfiguration.WOOD_WITH_LOG.apply(new Identifier("dark_oak")), RecipeConfigurator.SAWING, MapColor.BROWN),
new BlockGroup.GroupedBlock("mangrove", Blocks.MANGROVE_LOG, TextureConfiguration.WOOD_WITH_LOG.apply(new Identifier("mangrove")), RecipeConfigurator.SAWING, MapColor.RED),
new BlockGroup.GroupedBlock("bamboo", Blocks.BAMBOO_PLANKS, (type, textureId) -> "minecraft:block/bamboo_planks", RecipeConfigurator.SAWING, MapColor.YELLOW),
new BlockGroup.GroupedBlock("crimson", Blocks.CRIMSON_STEM, TextureConfiguration.WOOD_WITH_STEM.apply(new Identifier("crimson")), RecipeConfigurator.SAWING, MapColor.CRIMSON_STEM),
new BlockGroup.GroupedBlock("warped", Blocks.WARPED_STEM, TextureConfiguration.WOOD_WITH_STEM.apply(new Identifier("warped")), RecipeConfigurator.SAWING, MapColor.WARPED_STEM)
BlockGroup.GroupedBlock.builder(Blocks.OAK_LOG)
.id(new Identifier("oak"))
.textures(TextureConfiguration.WOOD_WITH_LOG.apply(new Identifier("oak")))
.usesTablesaw()
.mapColor(MapColor.WOOD)
.build(),

BlockGroup.GroupedBlock.builder(Blocks.SPRUCE_LOG)
.id(new Identifier("spruce"))
.textures(TextureConfiguration.WOOD_WITH_LOG.apply(new Identifier("spruce")))
.usesTablesaw()
.mapColor(MapColor.PODZOL)
.build(),

BlockGroup.GroupedBlock.builder(Blocks.BIRCH_LOG)
.id(new Identifier("birch"))
.textures(TextureConfiguration.WOOD_WITH_LOG.apply(new Identifier("birch")))
.usesTablesaw()
.mapColor(MapColor.SAND)
.build(),

BlockGroup.GroupedBlock.builder(Blocks.JUNGLE_LOG)
.id(new Identifier("jungle"))
.textures(TextureConfiguration.WOOD_WITH_LOG.apply(new Identifier("jungle")))
.usesTablesaw()
.mapColor(MapColor.DIRT)
.build(),

BlockGroup.GroupedBlock.builder(Blocks.ACACIA_LOG)
.id(new Identifier("acacia"))
.textures(TextureConfiguration.WOOD_WITH_LOG.apply(new Identifier("acacia")))
.usesTablesaw()
.mapColor(MapColor.ORANGE)
.build(),

BlockGroup.GroupedBlock.builder(Blocks.CHERRY_LOG)
.id(new Identifier("cherry"))
.textures(TextureConfiguration.WOOD_WITH_LOG.apply(new Identifier("cherry")))
.usesTablesaw()
.mapColor(MapColor.WHITE_TERRACOTTA)
.build(),

BlockGroup.GroupedBlock.builder(Blocks.DARK_OAK_LOG)
.id(new Identifier("dark_oak"))
.textures(TextureConfiguration.WOOD_WITH_LOG.apply(new Identifier("dark_oak")))
.usesTablesaw()
.mapColor(MapColor.BROWN)
.build(),

BlockGroup.GroupedBlock.builder(Blocks.MANGROVE_LOG)
.id(new Identifier("mangrove"))
.textures(TextureConfiguration.WOOD_WITH_LOG.apply(new Identifier("mangrove")))
.usesTablesaw()
.mapColor(MapColor.RED)
.build(),

BlockGroup.GroupedBlock.builder(Blocks.BAMBOO_PLANKS)
.id(new Identifier("bamboo"))
.textures((type, textureId) -> "minecraft:block/bamboo_planks")
.usesTablesaw()
.mapColor(MapColor.YELLOW)
.build(),


BlockGroup.GroupedBlock.builder(Blocks.CRIMSON_STEM)
.id(new Identifier("crimson"))
.textures(TextureConfiguration.WOOD_WITH_STEM.apply(new Identifier("crimson")))
.usesTablesaw()
.mapColor(MapColor.CRIMSON_STEM)
.build(),

BlockGroup.GroupedBlock.builder(Blocks.WARPED_STEM)
.id(new Identifier("warped"))
.textures(TextureConfiguration.WOOD_WITH_STEM.apply(new Identifier("warped")))
.usesTablesaw()
.mapColor(MapColor.WARPED_STEM)
.build()
);

public static final BlockGroup STONE = BlockGroup.of(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.debuggyteam.architecture_extensions.api;

import java.lang.reflect.Field;
import java.util.Iterator;
import java.util.Optional;
import java.util.Set;
Expand All @@ -9,8 +10,10 @@

import io.github.debuggyteam.architecture_extensions.util.SafeRenderLayer;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.MapColor;
import net.minecraft.registry.Registries;
import net.minecraft.util.DyeColor;
import net.minecraft.util.Identifier;

public final class BlockGroup implements Iterable<BlockGroup.GroupedBlock> {
Expand Down Expand Up @@ -62,5 +65,153 @@ public GroupedBlock(String id, Block baseBlock, TextureConfiguration textureConf
public GroupedBlock(Identifier id, Identifier baseBlockId, Supplier<Block> baseBlock, TextureConfiguration textureConfiguration, RecipeConfigurator recipeConfigurator) {
this(id, baseBlockId, baseBlock, textureConfiguration, recipeConfigurator, Optional.empty());
}

public static Builder builder() {
return new Builder();
}

public static Builder builder(Identifier id) {
return new Builder(id);
}

public static Builder builder(Block block) {
return new Builder(block);
}

public static class Builder {
private Identifier id;
private Identifier baseBlockId;
private Supplier<Block> baseBlock;
private TextureConfiguration textures;
private RecipeConfigurator recipes = RecipeConfigurator.CREATIVE;
private Optional<MapColor> mapColor = Optional.empty();
private SafeRenderLayer renderLayer = SafeRenderLayer.SOLID;

public Builder() {}

public Builder(Identifier id) {
this.id = id;
this.baseBlockId = id;
Block maybeBlock = Registries.BLOCK.get(id);
if (maybeBlock != Blocks.AIR) baseBlock = () -> maybeBlock;
}

public Builder(Block block) {
baseBlock = () -> block;
this.id = Registries.BLOCK.getId(block);
this.baseBlockId = this.id;
}

public Builder id(Identifier id) {
this.id = id;
return this;
}

public Builder baseBlockId(Identifier id) {
this.baseBlockId = id;
return this;
}

public Builder baseBlock(Block block) {
this.baseBlock = () -> block;
return this;
}

public Builder baseBlock(Supplier<Block> blockSupplier) {
this.baseBlock = blockSupplier;
return this;
}

public Builder textures(String singleTexture) {
this.textures = TextureConfiguration.create(
(it) -> singleTexture,
(it) -> singleTexture,
(it) -> singleTexture,
(it) -> singleTexture);
return this;
}

public Builder textures(TextureConfiguration config) {
this.textures = config;
return this;
}

public Builder creativeOnly() {
this.recipes = RecipeConfigurator.CREATIVE;
return this;
}

public Builder usesTablesaw() {
this.recipes = RecipeConfigurator.SAWING;
return this;
}

public Builder usesStonecutter() {
this.recipes = RecipeConfigurator.STONECUTTER;
return this;
}

public Builder usesCraftingTable() {
this.recipes = RecipeConfigurator.CRAFTING;
return this;
}

public Builder recipes(RecipeConfigurator config) {
this.recipes = config;
return this;
}

public Builder mapColor(DyeColor color) {
this.mapColor = Optional.of(color.getMapColor());
return this;
}

public Builder mapColor(MapColor color) {
this.mapColor = Optional.of(color);
return this;
}

public Builder noMapColor() {
this.mapColor = Optional.empty();
return this;
}

public Builder renderSolid() {
this.renderLayer = SafeRenderLayer.SOLID;
return this;
}

public Builder renderCutout() {
this.renderLayer = SafeRenderLayer.CUTOUT;
return this;
}

public Builder renderTranslucent() {
this.renderLayer = SafeRenderLayer.TRANSLUCENT;
return this;
}

public Builder renderLayer(SafeRenderLayer layer) {
this.renderLayer = layer;
return this;
}

public GroupedBlock build() {
checkFilled();
return new GroupedBlock(id, baseBlockId, baseBlock, textures, recipes, mapColor, renderLayer);
}

private void checkFilled() {
for(Field f : Builder.class.getDeclaredFields()) {
try {
if (f.get(this) == null) {
throw new IllegalArgumentException("Field '"+f.getName()+" must be set for this GroupedBlock.Builder to be complete.");
}
} catch (IllegalArgumentException | IllegalAccessException e) {
//Should be no access problems from here
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,26 @@
import net.minecraft.util.Identifier;

public enum BlockType {
ARCH((baseBlock, settings, grouped) -> new ArchBlock(baseBlock.getDefaultState(), settings, grouped), 2.5f, variantsOf("", "inner", "outer"), SafeRenderLayer.SOLID),
BEAM((baseBlock, settings, grouped) -> new BeamBlock(settings), 1.5f, noVariants(), SafeRenderLayer.SOLID),
H_BEAM((baseBlock, settings, grouped) -> new BeamBlock(settings), 8f, noVariants(), SafeRenderLayer.SOLID),
WALL_COLUMN((baseBlock, settings, grouped) -> new WallColumnBlock(settings), 2.5f, variantsOf("", "cap"), SafeRenderLayer.SOLID),
FENCE_POST((baseBlock, settings, grouped) -> new FencePostBlock(settings), 1.5f, noVariants(), SafeRenderLayer.SOLID),
JOIST((baseBlock, settings, grouped) -> new JoistBlock(settings), 1.5f, noVariants(), SafeRenderLayer.SOLID),
CROWN_MOLDING((baseBlock, settings, grouped) -> new CrownMoldingBlock(baseBlock.getDefaultState(), settings), 1.5f, variantsOf("", "inner", "outer"), SafeRenderLayer.SOLID),
POST_CAP((baseBlock, settings, grouped) -> new PostCapBlock(settings), 1.5f, noVariants(), SafeRenderLayer.SOLID),
POST_LANTERN((baseBlock, settings, grouped) -> new PostLanternBlock(settings), 1.5f, variantsOf("", "hanging"), SafeRenderLayer.SOLID),
ROD((baseBlock, settings, grouped) -> new ArchExRodBlock(settings), 1f, noVariants(), SafeRenderLayer.SOLID),
ROOF((baseBlock, settings, grouped) -> new RoofBlock(baseBlock.getDefaultState(), settings), 2.5f, variantsOf("", "inner", "outer"), SafeRenderLayer.SOLID),
WALL_POST((baseBlock, settings, grouped) -> new WallPostBlock(settings), 2.5f, noVariants(), SafeRenderLayer.SOLID),
LATTICE((baseBlock, settings, grouped) -> new LatticeBlock(settings), 1.5f, noVariants(), SafeRenderLayer.SOLID),
FACADE((baseBlock, settings, grouped) -> new FacadeBlock(settings), 1.5f, noVariants(), SafeRenderLayer.SOLID),
TUBE_METAL((baseBlock, settings, grouped) -> new TubeSteelBlock(settings), 8f, noVariants(), SafeRenderLayer.SOLID),
I_BEAM((baseBlock, settings, grouped) -> new IBeamBlock(settings), 8f, noVariants(), SafeRenderLayer.SOLID),
TRANSOM((baseBlock, settings, grouped) -> new TransomBlock(settings), 1.5f, noVariants(), SafeRenderLayer.TRANSLUCENT),
OCTAGONAL_COLUMN((baseBlock, settings, grouped) -> new OctagonalColumnBlock(settings), 1.5f, variantsOf("", "cap", "double_cap"), SafeRenderLayer.SOLID),
ROUND_ARCH((baseBlock, settings, grouped) -> new RoundArchBlock(settings), 1.5f, noVariants(), SafeRenderLayer.SOLID),
ROUND_FENCE_POST((baseBlock, settings, grouped) -> new RoundFencePostBlock(settings), 1.5f, noVariants(), SafeRenderLayer.SOLID);
ARCH (ArchBlock::new, 2.5f, variantsOf("", "inner", "outer"), SafeRenderLayer.SOLID),
BEAM (BeamBlock::new, 1.5f),
H_BEAM (BeamBlock::new, 8.0f),
WALL_COLUMN (WallColumnBlock::new, 2.5f, variantsOf("", "cap"), SafeRenderLayer.SOLID),
FENCE_POST (FencePostBlock::new, 1.5f),
JOIST (JoistBlock::new, 1.5f),
CROWN_MOLDING(CrownMoldingBlock::new,1.5f, variantsOf("", "inner", "outer"), SafeRenderLayer.SOLID),
POST_CAP (PostCapBlock::new, 1.5f),
POST_LANTERN (PostLanternBlock::new, 1.5f, variantsOf("", "hanging"), SafeRenderLayer.SOLID),
ROD (ArchExRodBlock::new, 1.0f),
ROOF (RoofBlock::new, 2.5f, variantsOf("", "inner", "outer"), SafeRenderLayer.SOLID),
WALL_POST (WallPostBlock::new, 2.5f),
LATTICE (LatticeBlock::new, 1.5f),
FACADE (FacadeBlock::new, 1.5f),
TUBE_METAL (TubeSteelBlock::new, 8.0f),
I_BEAM (IBeamBlock::new, 8.0f),
TRANSOM (TransomBlock::new, 1.5f, noVariants(), SafeRenderLayer.TRANSLUCENT),
OCTAGONAL_COLUMN(OctagonalColumnBlock::new, 1.5f, variantsOf("", "cap", "double_cap"), SafeRenderLayer.SOLID),
ROUND_ARCH (RoundArchBlock::new, 1.5f),
ROUND_FENCE_POST(RoundFencePostBlock::new, 1.5f);

private final TriFunction<Block, QuiltBlockSettings, TypedGroupedBlock, Block> creator;
private final float strength;
Expand All @@ -68,7 +68,14 @@ public enum BlockType {
this.variants = variants;
this.renderLayer = renderLayer;
}


/**
* Makes a BlockType with no variants and solid RenderLayer
* @see #BlockType(TriFunction, float, String[], SafeRenderLayer)
*/
BlockType(TriFunction<Block, QuiltBlockSettings, TypedGroupedBlock, Block> creator, float strength) {
this(creator, strength, noVariants(), SafeRenderLayer.SOLID);
}

public String[] variants() {
return variants;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public interface TextureConfiguration extends BiFunction<BlockType, String, Stri
return new Identifier(id.getNamespace(), "block/" + id.getPath() + "_bottom").toString();
}
);

static final Function<Identifier, TextureConfiguration> ALL = it -> (type, textureId) -> it.toString();

static TextureConfiguration create(Function<BlockType, String> base,
Function<BlockType, String> side,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
package io.github.debuggyteam.architecture_extensions.blocks;

import org.quiltmc.qsl.block.extensions.api.QuiltBlockSettings;

import io.github.debuggyteam.architecture_extensions.api.BlockType.TypedGroupedBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.StairsBlock;
import net.minecraft.text.MutableText;

public class ArchBlock extends StairsBlock implements TypedGrouped {
protected final TypedGroupedBlock typedGroupedBlock;

// This is a super class of settings.
public ArchBlock(BlockState blockState, Settings settings, TypedGroupedBlock typedGrouped) {
public ArchBlock(BlockState blockState, Settings settings, TypedGroupedBlock typedGroupedBlock) {
super(blockState, settings);
this.typedGroupedBlock = typedGrouped;
this.typedGroupedBlock = typedGroupedBlock;
}

public ArchBlock(Block block, QuiltBlockSettings settings, TypedGroupedBlock typedGroupedBlock) {
this(block.getDefaultState(), settings, typedGroupedBlock);
}

@Override
public TypedGroupedBlock getTypedGroupedBlock() {
return typedGroupedBlock;
}

@Override
public MutableText getName() {
return getServerTranslation();
}
}
Loading