autogen block/ item names
This commit is contained in:
parent
9fdca2fa74
commit
ec178f8c75
3 changed files with 42 additions and 8 deletions
|
@ -12,6 +12,8 @@ import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.DoorBlock;
|
import net.minecraft.block.DoorBlock;
|
||||||
import net.minecraft.block.TrapdoorBlock;
|
import net.minecraft.block.TrapdoorBlock;
|
||||||
import net.minecraft.client.render.RenderLayer;
|
import net.minecraft.client.render.RenderLayer;
|
||||||
|
import net.minecraft.text.MutableText;
|
||||||
|
import net.minecraft.text.TranslatableText;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
import org.dimdev.dimdoors.block.entity.ModBlockEntityTypes;
|
import org.dimdev.dimdoors.block.entity.ModBlockEntityTypes;
|
||||||
|
@ -19,6 +21,7 @@ import org.dimdev.dimdoors.item.DimensionalDoorItemRegistrar;
|
||||||
import org.dimdev.dimdoors.listener.BlockRegistryEntryAddedListener;
|
import org.dimdev.dimdoors.listener.BlockRegistryEntryAddedListener;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class DimensionalDoorBlockRegistrar {
|
public class DimensionalDoorBlockRegistrar {
|
||||||
|
@ -44,15 +47,15 @@ public class DimensionalDoorBlockRegistrar {
|
||||||
|
|
||||||
public void handleEntry(Identifier identifier, Block block) {
|
public void handleEntry(Identifier identifier, Block block) {
|
||||||
if (!(block instanceof DimensionalDoorBlock) && block instanceof DoorBlock) {
|
if (!(block instanceof DimensionalDoorBlock) && block instanceof DoorBlock) {
|
||||||
register(identifier, block, DimensionalDoorBlock::new);
|
register(identifier, block, AutoGenDimensionalDoorBlock::new);
|
||||||
} else if (!(block instanceof DimensionalTrapdoorBlock) && block instanceof TrapdoorBlock) {
|
} else if (!(block instanceof DimensionalTrapdoorBlock) && block instanceof TrapdoorBlock) {
|
||||||
register(identifier, block, DimensionalTrapdoorBlock::new);
|
register(identifier, block, AutoGenDimensionalTrapdoorBlock::new);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void register(Identifier identifier, Block block, Function<AbstractBlock.Settings, ? extends Block> constructor) {
|
private void register(Identifier identifier, Block block, BiFunction<AbstractBlock.Settings, Block, ? extends Block> constructor) {
|
||||||
Identifier gennedId = new Identifier("dimdoors", PREFIX + identifier.getPath());
|
Identifier gennedId = new Identifier("dimdoors", PREFIX + identifier.getPath());
|
||||||
Block newBlock = Registry.register(registry, gennedId, constructor.apply(FabricBlockSettings.copy(block)));
|
Block newBlock = Registry.register(registry, gennedId, constructor.apply(FabricBlockSettings.copy(block), block));
|
||||||
ModBlockEntityTypes.ENTRANCE_RIFT_BLOCKS.add(newBlock);
|
ModBlockEntityTypes.ENTRANCE_RIFT_BLOCKS.add(newBlock);
|
||||||
mappedDoorBlocks.put(gennedId, identifier);
|
mappedDoorBlocks.put(gennedId, identifier);
|
||||||
itemRegistrar.notifyBlockMapped(block, newBlock);
|
itemRegistrar.notifyBlockMapped(block, newBlock);
|
||||||
|
@ -69,4 +72,33 @@ public class DimensionalDoorBlockRegistrar {
|
||||||
public boolean isMapped(Identifier identifier) {
|
public boolean isMapped(Identifier identifier) {
|
||||||
return mappedDoorBlocks.containsKey(identifier);
|
return mappedDoorBlocks.containsKey(identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static class AutoGenDimensionalDoorBlock extends DimensionalDoorBlock {
|
||||||
|
private final Block originalBlock;
|
||||||
|
|
||||||
|
public AutoGenDimensionalDoorBlock(Settings settings, Block originalBlock) {
|
||||||
|
super(settings);
|
||||||
|
this.originalBlock = originalBlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MutableText getName() {
|
||||||
|
return new TranslatableText("dimdoors.autogen_block_prefix").append(originalBlock.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class AutoGenDimensionalTrapdoorBlock extends DimensionalTrapdoorBlock {
|
||||||
|
private final Block originalBlock;
|
||||||
|
|
||||||
|
public AutoGenDimensionalTrapdoorBlock(Settings settings, Block originalBlock) {
|
||||||
|
super(settings);
|
||||||
|
this.originalBlock = originalBlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MutableText getName() {
|
||||||
|
return new TranslatableText("dimdoors.autogen_block_prefix").append(originalBlock.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.DoorBlock;
|
import net.minecraft.block.DoorBlock;
|
||||||
import net.minecraft.block.TrapdoorBlock;
|
import net.minecraft.block.TrapdoorBlock;
|
||||||
|
import net.minecraft.client.resource.language.I18n;
|
||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
@ -109,12 +110,12 @@ public class DimensionalDoorItemRegistrar {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getName(ItemStack stack) {
|
public Text getName(ItemStack stack) {
|
||||||
return new TranslatableText("dimdoors.autogen_item_prefix", originalItem.getName().asString());
|
return new TranslatableText("dimdoors.autogen_item_prefix", I18n.translate(originalItem.getTranslationKey()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getName() {
|
public Text getName() {
|
||||||
return new TranslatableText("dimdoors.autogen_item_prefix", originalItem.getName().asString());
|
return new TranslatableText("dimdoors.autogen_item_prefix", I18n.translate(originalItem.getTranslationKey()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,12 +129,12 @@ public class DimensionalDoorItemRegistrar {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getName(ItemStack stack) {
|
public Text getName(ItemStack stack) {
|
||||||
return new TranslatableText("dimdoors.autogen_item_prefix", originalItem.getName().asString());
|
return new TranslatableText("dimdoors.autogen_item_prefix", I18n.translate(originalItem.getTranslationKey()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Text getName() {
|
public Text getName() {
|
||||||
return new TranslatableText("dimdoors.autogen_item_prefix", originalItem.getName().asString());
|
return new TranslatableText("dimdoors.autogen_item_prefix", I18n.translate(originalItem.getTranslationKey()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"itemGroup.dimdoors.dimensional_doors": "Dimensional Doors",
|
"itemGroup.dimdoors.dimensional_doors": "Dimensional Doors",
|
||||||
|
|
||||||
|
"dimdoors.autogen_block_prefix": "Dimensional %s",
|
||||||
"block.dimdoors.gold_door": "Gold Door",
|
"block.dimdoors.gold_door": "Gold Door",
|
||||||
"block.dimdoors.quartz_door": "Quartz Door",
|
"block.dimdoors.quartz_door": "Quartz Door",
|
||||||
"block.dimdoors.iron_dimensional_door": "Iron Dimensional Door",
|
"block.dimdoors.iron_dimensional_door": "Iron Dimensional Door",
|
||||||
|
|
Loading…
Reference in a new issue