generated from QuiltMC/quilt-template-mod
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from DebuggyTeam/falk_work
Localization, Meta-Blocktypes, Creative Recipe Configurator, and base-block RenderLayer
- Loading branch information
Showing
21 changed files
with
237 additions
and
124 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
89 changes: 89 additions & 0 deletions
89
src/main/java/io/github/debuggyteam/architecture_extensions/TypedGroupedBlockItem.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,89 @@ | ||
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.text.TextColor; | ||
import net.minecraft.util.Formatting; | ||
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("Missing") | ||
.styled(it -> it.withHoverEvent( | ||
HoverEvent.Action.SHOW_TEXT.buildHoverEvent(Text.translatable(MISSING_LOCALIZATION_KEY, Text.literal(ideal))) | ||
) | ||
.withItalic(true) | ||
.withColor(TextColor.fromFormatting(Formatting.GRAY))); | ||
} | ||
|
||
@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; | ||
} | ||
} |
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
49 changes: 49 additions & 0 deletions
49
src/main/java/io/github/debuggyteam/architecture_extensions/api/MetaBlockType.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,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; | ||
} | ||
} |
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
13 changes: 11 additions & 2 deletions
13
src/main/java/io/github/debuggyteam/architecture_extensions/blocks/ArchBlock.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 |
---|---|---|
@@ -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; | ||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
src/main/java/io/github/debuggyteam/architecture_extensions/blocks/TypedGrouped.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,7 @@ | ||
package io.github.debuggyteam.architecture_extensions.blocks; | ||
|
||
import io.github.debuggyteam.architecture_extensions.api.BlockType.TypedGroupedBlock; | ||
|
||
public interface TypedGrouped { | ||
public TypedGroupedBlock getTypedGroupedBlock(); | ||
} |
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.