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

Localization and meta-blocktypes #43

Merged
merged 6 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -92,7 +92,7 @@ public void onInitialize(ModContainer mod) {
DeferredRegistration.register(item.getModId(), group, groupedBlock, blockTypes, CALLBACK_ADD_TO_ITEM_GROUP);
}
} catch (IOException ex) {
throw new RuntimeException("There was a problem getting staticdata for mod container '" + item.getModId() + "' with resource id '" + item.getResourceId() + "'.", ex);
LOGGER.warn("There was a problem getting staticdata for mod container '" + item.getModId() + "' with resource id '" + item.getResourceId() + "'.", ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package io.github.debuggyteam.architecture_extensions;

import org.quiltmc.loader.api.minecraft.ClientOnly;

import io.github.debuggyteam.architecture_extensions.api.BlockType.TypedGroupedBlock;
import io.github.debuggyteam.architecture_extensions.blocks.TypedGrouped;
import net.minecraft.block.Block;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;

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";

protected final TypedGroupedBlock typedGroupedBlock;

@ClientOnly
protected Text cachedLocalization = null;

public <T extends Block & TypedGrouped> TypedGroupedBlockItem(T block, Settings settings) {
super(block, settings);
typedGroupedBlock = block.getTypedGroupedBlock();
}

public TypedGroupedBlockItem(Block block, TypedGroupedBlock typedGrouped, Settings settings) {
super(block, settings);
typedGroupedBlock = typedGrouped;
}

@ClientOnly
private Text getBaseTranslationKey() {
Identifier blockId = typedGroupedBlock.groupedBlock().id();

String ideal = GROUPED_BLOCK_PREFIX + "." + blockId.getNamespace() + "." + blockId.getPath();
if (I18n.hasTranslation(ideal)) return Text.translatable(ideal);

String lessIdeal = GROUPED_BLOCK_PREFIX + "." + blockId.getPath();
if (I18n.hasTranslation(lessIdeal)) return Text.translatable(lessIdeal);

//This hover never actually displays since the tooltip is already a hover.
//But this keeps the Null tradition alive and prevents the tooltip from becoming gigantic.
return Text.literal("Null")
.styled(it -> it.withHoverEvent(
HoverEvent.Action.SHOW_TEXT.buildHoverEvent(Text.translatable(MISSING_LOCALIZATION_KEY, Text.literal(ideal)))
));
}

@Override
@ClientOnly
public Text getName() {
if (cachedLocalization == null) {

String translationKey = Util.createTranslationKey("block", Registries.ITEM.getId(this));
if (I18n.hasTranslation(translationKey)) {
cachedLocalization = Text.translatable(translationKey);
} else {
Text baseBlock = getBaseTranslationKey();
String typedGroupedKey = BLOCK_TYPE_PREFIX + "." + typedGroupedBlock.type().toString();
Text blockType = Text.translatable(typedGroupedKey);

cachedLocalization = Text.translatable(BLOCKTYPE_BLOCK_KEY, baseBlock, blockType);
}
}

return cachedLocalization;
}

@Override
public Text getName(ItemStack stack) {
return getName();
}

@Override
public TypedGroupedBlock getTypedGroupedBlock() {
return this.typedGroupedBlock;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.github.debuggyteam.architecture_extensions.api.BlockGroup;
import io.github.debuggyteam.architecture_extensions.api.RecipeConfigurator;
import io.github.debuggyteam.architecture_extensions.api.TextureConfiguration;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.MapColor;
import net.minecraft.util.DyeColor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.debuggyteam.architecture_extensions.api;

import java.util.Locale;
import java.util.function.BiFunction;

import io.github.debuggyteam.architecture_extensions.blocks.RoundArchBlock;
import io.github.debuggyteam.architecture_extensions.blocks.FacadeBlock;
Expand All @@ -12,11 +11,14 @@
import io.github.debuggyteam.architecture_extensions.blocks.TransomBlock;
import io.github.debuggyteam.architecture_extensions.blocks.TubeSteelBlock;
import io.github.debuggyteam.architecture_extensions.util.SafeRenderLayer;

import org.apache.commons.lang3.function.TriFunction;
import org.quiltmc.qsl.block.extensions.api.QuiltBlockSettings;
import org.quiltmc.qsl.item.setting.api.QuiltItemSettings;

import io.github.debuggyteam.architecture_extensions.ArchitectureExtensions;
import io.github.debuggyteam.architecture_extensions.BlockCreationCallback;
import io.github.debuggyteam.architecture_extensions.TypedGroupedBlockItem;
import io.github.debuggyteam.architecture_extensions.blocks.ArchBlock;
import io.github.debuggyteam.architecture_extensions.blocks.BeamBlock;
import io.github.debuggyteam.architecture_extensions.blocks.WallColumnBlock;
Expand All @@ -29,39 +31,38 @@
import io.github.debuggyteam.architecture_extensions.blocks.RoofBlock;
import io.github.debuggyteam.architecture_extensions.blocks.WallPostBlock;
import net.minecraft.block.Block;
import net.minecraft.item.BlockItem;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;

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

private final BiFunction<Block, QuiltBlockSettings, Block> creator;
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);
private final TriFunction<Block, QuiltBlockSettings, TypedGroupedBlock, Block> creator;
private final float strength;
private final String[] variants;
private final SafeRenderLayer renderLayer;

BlockType(BiFunction<Block, QuiltBlockSettings, Block> creator, float strength, String[] variants, SafeRenderLayer renderLayer) {
BlockType(TriFunction<Block, QuiltBlockSettings, TypedGroupedBlock, Block> creator, float strength, String[] variants, SafeRenderLayer renderLayer) {
this.creator = creator;
this.strength = strength;
this.variants = variants;
Expand Down Expand Up @@ -89,13 +90,14 @@ public TypedGroupedBlock register(BlockGroup group, BlockGroup.GroupedBlock grou

var blockSettings = QuiltBlockSettings.copyOf(baseBlock).strength(strength);
groupedBlock.mapColor().map(blockSettings::mapColor);
var block = Registry.register(Registries.BLOCK, id, creator.apply(baseBlock, blockSettings));

Registry.register(Registries.ITEM, id, new BlockItem(block, new QuiltItemSettings()));
var typedGroupedBlock = new TypedGroupedBlock(this, groupedBlock, id);
var block = Registry.register(Registries.BLOCK, id, creator.apply(baseBlock, blockSettings, typedGroupedBlock));

Registry.register(Registries.ITEM, id, new TypedGroupedBlockItem(block, typedGroupedBlock, new QuiltItemSettings()));

if (callback != null) callback.onBlockCreated(group, this, baseBlock, block);

return new TypedGroupedBlock(this, groupedBlock, id);
return typedGroupedBlock;
}

private static final String[] noVariants() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.github.debuggyteam.architecture_extensions.api;

public enum MetaBlockType {
WOOD(
BlockType.FACADE, BlockType.ROUND_FENCE_POST, BlockType.ROUND_ARCH, BlockType.OCTAGONAL_COLUMN,
BlockType.BEAM, BlockType.FENCE_POST, BlockType.JOIST, BlockType.CROWN_MOLDING, BlockType.POST_CAP,
BlockType.POST_LANTERN, BlockType.LATTICE, BlockType.TRANSOM
),
STONE(
BlockType.ARCH, BlockType.WALL_COLUMN, BlockType.ROOF, BlockType.WALL_POST, BlockType.FACADE,
BlockType.ROUND_FENCE_POST, BlockType.ROUND_ARCH, BlockType.OCTAGONAL_COLUMN
),
AQUATIC_STONE(
BlockType.ARCH, BlockType.WALL_COLUMN, BlockType.WALL_POST, BlockType.FACADE, BlockType.ROUND_FENCE_POST,
BlockType.ROUND_ARCH, BlockType.OCTAGONAL_COLUMN
),
PROCESSED_STONE(
BlockType.ARCH, BlockType.WALL_COLUMN, BlockType.ROOF, BlockType.WALL_POST, BlockType.FACADE,
BlockType.ROUND_FENCE_POST, BlockType.ROUND_ARCH, BlockType.OCTAGONAL_COLUMN
),
BRICK(
BlockType.ARCH, BlockType.WALL_COLUMN, BlockType.ROOF, BlockType.WALL_POST, BlockType.FACADE,
BlockType.ROUND_FENCE_POST, BlockType.ROUND_ARCH, BlockType.OCTAGONAL_COLUMN
),
TILE(
BlockType.ARCH, BlockType.WALL_COLUMN, BlockType.ROOF, BlockType.WALL_POST, BlockType.FACADE,
BlockType.ROUND_FENCE_POST, BlockType.ROUND_ARCH, BlockType.OCTAGONAL_COLUMN
),
CRYSTAL(
BlockType.ARCH, BlockType.WALL_COLUMN, BlockType.ROOF, BlockType.WALL_POST, BlockType.FACADE,
BlockType.ROUND_FENCE_POST, BlockType.ROUND_ARCH, BlockType.OCTAGONAL_COLUMN
),
TERRACOTTA(BlockType.FACADE),
CONCRETE(BlockType.FACADE),
METAL(
BlockType.ROD, BlockType.FACADE, BlockType.I_BEAM, BlockType.TUBE_METAL
)
;

private final BlockType[] blockTypes;

MetaBlockType(BlockType...blockTypes) {
this.blockTypes = blockTypes;
}

public BlockType[] blockTypes() {
return this.blockTypes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ static RecipeConfigurator simple(String id) {
break;
}
};

static final RecipeConfigurator CREATIVE = (type, templateConsumer) -> {};

static record RecipeTemplate(String id, boolean simple, boolean tablesaw) {
RecipeTemplate(String id, boolean tablesaw) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
package io.github.debuggyteam.architecture_extensions.blocks;

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

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

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

@Override
public TypedGroupedBlock getTypedGroupedBlock() {
return typedGroupedBlock;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;

public class IBeamBlock extends PillarBlock implements Waterloggable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.HorizontalFacingBlock;
import net.minecraft.block.PaneBlock;
import net.minecraft.block.PillarBlock;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.Waterloggable;
import net.minecraft.fluid.FluidState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;

public class TransomBlock extends HorizontalFacingBlock {
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
Expand Down Expand Up @@ -46,8 +45,6 @@ public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos
// Deals with placing the block properly in accordance to direction.
@Override
public BlockState getPlacementState(ItemPlacementContext context) {
World world = context.getWorld();
BlockPos pos = context.getBlockPos();
return this.getDefaultState().with(Properties.HORIZONTAL_FACING, context.getPlayerFacing()).with(WATERLOGGED, context.getWorld().getFluidState(context.getBlockPos()).getFluid() == Fluids.WATER);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.github.debuggyteam.architecture_extensions.blocks;

import io.github.debuggyteam.architecture_extensions.api.BlockType.TypedGroupedBlock;

public interface TypedGrouped {
public TypedGroupedBlock getTypedGroupedBlock();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.Axis;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.state.property.Property;
import net.minecraft.util.BlockRotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
Expand Down

This file was deleted.

Loading