Skip to content
Closed
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
@@ -1,12 +1,12 @@
package net.sevenstars.middleearth;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.minecraft.util.Identifier;
import net.sevenstars.api.enums.LangCategory;
import net.sevenstars.api.utils.ModLogger;
import net.sevenstars.middleearth.block.registration.*;
import net.sevenstars.middleearth.commands.CommandRegistryME;
import net.sevenstars.middleearth.config.ClientConfigME;
import net.sevenstars.middleearth.config.ServerConfigME;
import net.sevenstars.middleearth.enchantments.EnchantmentsME;
import net.sevenstars.middleearth.entity.EntitiesME;
Expand Down Expand Up @@ -43,12 +43,12 @@
import net.sevenstars.middleearth.world.spawners.EntitySpawningME;

public class MiddleEarth implements ModInitializer {
public static final String MOD_ID = "middle-earth";
public static final String OLD_MOD_ID = "me";
public static final String MOD_VERSION = "1.0.0-1.21.8-beta";
private static final String MOD_ID = "middle-earth";
private static final String OLD_MOD_ID = "me";
private static final String MOD_VERSION = "1.0.0-1.21.8-beta";
public static final boolean IS_DEBUG = true;
public static final boolean ENABLE_INSTANT_BOOTING = true;
public static final ModLogger LOGGER = new ModLogger(MOD_ID, IS_DEBUG);
public static final ModLogger LOGGER = new ModLogger(getModId(), IS_DEBUG);

@Override
public void onInitialize() {
Expand All @@ -59,8 +59,12 @@ public void onInitialize() {

ServerNetworkHandlerME.register(new ConnectionToClient());
EventRegistryME.register();
ServerConfigME.registerConfigs();
ClientConfigME.registerConfigs();

// register on server start
// *** FABRIC EVENT ***
ServerLifecycleEvents.SERVER_STARTING.register(
server -> ServerConfigME.registerConfigs()
);

AtlasesME.registerAtlas();
RecipesME.registerRecipes();
Expand Down Expand Up @@ -141,51 +145,111 @@ public void onInitialize() {
}
}

// Getter & Setter
public static String getModId() {
return MiddleEarth.MOD_ID;
}

public static String getOldModId() {
return MiddleEarth.OLD_MOD_ID;
}
public static String getModVersion() {
return MiddleEarth.MOD_VERSION;
}

// Logger
public static void logRegistryMsg(String registry) {
LOGGER.logDebugMsg("Registering Mod " + registry + " for " + MOD_ID);
LOGGER.logDebugMsg("Registering Mod " + registry + " for " + getModId());
}

// Identifiers
public static Identifier id(String namespace, String path) {
return IdentifierUtil.build(namespace, path);
}

/**
* MiddleEarth.id(path) = MiddleEarth.id(path)
*/
public static Identifier id(String path){
return IdentifierUtil.build(MOD_ID, path);
return id(getModId(), path);
}

public static Identifier idOld(String path){
return id(getOldModId(), path);
}

public static Identifier idFilePath(String... names){
return IdentifierUtil.build(MOD_ID, stringAggregate('/', names));
return IdentifierUtil.build(getModId(), stringAggregate('/', names));
}

public static Identifier idVanilla(String... names){
return IdentifierUtil.ofVanilla(stringAggregate('/', names));
}

public static Identifier idAggregate(String... names){
return IdentifierUtil.buildAggregate(MOD_ID, names);
return IdentifierUtil.buildAggregate(getModId(), names);
}

public static String stringAggregate(char delimiter, String... names){
return IdentifierUtil.createAggregateValue(delimiter, names);
}

public static Identifier idAggregate(char delimiter, String... names){
return IdentifierUtil.build(MOD_ID, IdentifierUtil.createAggregateValue(delimiter, names));
return IdentifierUtil.build(getModId(), IdentifierUtil.createAggregateValue(delimiter, names));
}

public static Identifier ofId(String stringId){
return IdentifierUtil.getIdentifierFromString(stringId);
}

public static Identifier appendSuffix(Identifier base, String suffix) {
String id = base.toString();
return Identifier.of(id + suffix);
}

public static Identifier appendPrefix(Identifier base, Identifier prefixId) {
if(base == null)
return null;
return base.withPrefixedPath(String.format("%s/", prefixId.getPath()));
}

// Translation Keys
public static String rawTranslationKey(LangCategory category, String value){
return category.Prefix + "." + value;
// for Identifier value
public static String rawTranslationKey(String prefix, Identifier value){
return value.toTranslationKey(prefix);
}

public static String rawTranslationKey(LangCategory category, Identifier value){
return value.toTranslationKey(category.Prefix);
return rawTranslationKey(category.Prefix, value);
}

// for String value
public static String rawTranslationKey(String prefix, String value){
return prefix + "." + value;
if ("".equals(value)) {
return prefix;
}
return prefix + "." + value;
}
public static String rawTranslationKeyWithModId(String prefix, String value){
return rawTranslationKey(prefix + "." + getModId(), value);
}

public static String rawTranslationKey(LangCategory category, String value){
return rawTranslationKey(category.Prefix, value);
}

/**
* <br/>Most common use,
* <br/>to replace the string inside the Text.translatable()
* <br/><br/>
* <br/>Example:
* <br/> Text.translatable("some_category." + MOD_ID + ".something_else")
* <br/> ->
* <br/> Text.translatable(
* <br/> MiddleEarth.rawTranslationKeyWithModId(LangCategory.SOME, "something_else")
* <br/> )
*/
public static String rawTranslationKeyWithModId(LangCategory category, String value){
return rawTranslationKey(category.Prefix + "." + getModId(), value);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.sevenstars.middleearth;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.model.loading.v1.ExtraModelKey;
import net.fabricmc.fabric.api.client.model.loading.v1.ModelLoadingPlugin;
import net.fabricmc.fabric.api.client.model.loading.v1.SimpleUnbakedExtraModel;
Expand All @@ -17,10 +18,13 @@
import net.minecraft.client.render.entity.model.EntityModelLayer;
import net.minecraft.client.render.item.model.special.SpecialModelTypes;
import net.minecraft.client.render.item.property.bool.BooleanProperties;
import net.minecraft.util.Identifier;
import net.minecraft.client.resource.language.I18n;
import net.sevenstars.api.enums.LangCategory;
import net.sevenstars.middleearth.block.registration.*;
import net.sevenstars.middleearth.block.special.bellows.BellowsBlockEntityRenderer;
import net.sevenstars.middleearth.block.special.coffers.*;
import net.sevenstars.middleearth.config.ClientConfigME;
import net.sevenstars.middleearth.config.ServerConfigME;
import net.sevenstars.middleearth.block.special.fire_of_orthanc.FireOfOrthancEntityRenderer;
import net.sevenstars.middleearth.block.special.forge.ForgeEntityRenderer;
import net.sevenstars.middleearth.block.special.plate.PlateEntityRenderer;
Expand Down Expand Up @@ -90,26 +94,38 @@

public class MiddleEarthClient implements ClientModInitializer {

public static final EntityModelLayer CUSTOM_ARMOR_HELMET = new EntityModelLayer(Identifier.of(MiddleEarth.MOD_ID, "armor"), "_1");
public static final EntityModelLayer CUSTOM_ARMOR_CHESTPLATE = new EntityModelLayer(Identifier.of(MiddleEarth.MOD_ID, "armor"), "_2");
public static final EntityModelLayer CUSTOM_ARMOR_LEGGINGS = new EntityModelLayer(Identifier.of(MiddleEarth.MOD_ID, "armor"), "_3");
public static final EntityModelLayer CUSTOM_ARMOR_BOOTS = new EntityModelLayer(Identifier.of(MiddleEarth.MOD_ID, "armor"), "_4");
public static final EntityModelLayer HELMET_ADDON_MODEL_LAYER = new EntityModelLayer(Identifier.of(MiddleEarth.MOD_ID, "armor"), "helmet_addon");
public static final EntityModelLayer BACK_ATTACHMENT_MODEL_LAYER = new EntityModelLayer(Identifier.of(MiddleEarth.MOD_ID, "armor"), "back_attachment");
public static final EntityModelLayer HELMET_ATTACHMENT_MODEL_LAYER = new EntityModelLayer(Identifier.of(MiddleEarth.MOD_ID, "armor"), "helmet_attachment");
public static final EntityModelLayer CUSTOM_ARMOR_HELMET = new EntityModelLayer(MiddleEarth.id("armor"), "_1");
public static final EntityModelLayer CUSTOM_ARMOR_CHESTPLATE = new EntityModelLayer(MiddleEarth.id("armor"), "_2");
public static final EntityModelLayer CUSTOM_ARMOR_LEGGINGS = new EntityModelLayer(MiddleEarth.id("armor"), "_3");
public static final EntityModelLayer CUSTOM_ARMOR_BOOTS = new EntityModelLayer(MiddleEarth.id("armor"), "_4");
public static final EntityModelLayer HELMET_ADDON_MODEL_LAYER = new EntityModelLayer(MiddleEarth.id("armor"), "helmet_addon");
public static final EntityModelLayer BACK_ATTACHMENT_MODEL_LAYER = new EntityModelLayer(MiddleEarth.id("armor"), "back_attachment");
public static final EntityModelLayer HELMET_ATTACHMENT_MODEL_LAYER = new EntityModelLayer(MiddleEarth.id("armor"), "helmet_attachment");

public static final EntityModelLayer HEATER_SHIELD_LAYER = new EntityModelLayer(Identifier.of(MiddleEarth.MOD_ID, "heater_shield"), "main");
public static final EntityModelLayer KITE_SHIELD_LAYER = new EntityModelLayer(Identifier.of(MiddleEarth.MOD_ID, "kite_shield"), "main");
public static final EntityModelLayer ROUND_SHIELD_LAYER = new EntityModelLayer(Identifier.of(MiddleEarth.MOD_ID, "round_shield"), "main");
public static final EntityModelLayer HEATER_SHIELD_LAYER = new EntityModelLayer(MiddleEarth.id("heater_shield"), "main");
public static final EntityModelLayer KITE_SHIELD_LAYER = new EntityModelLayer(MiddleEarth.id("kite_shield"), "main");
public static final EntityModelLayer ROUND_SHIELD_LAYER = new EntityModelLayer(MiddleEarth.id("round_shield"), "main");

public static final EntityModelLayer HELD_BANNER_LAYER = new EntityModelLayer(Identifier.of(MiddleEarth.MOD_ID, "held_banner"), "main");
public static final EntityModelLayer HELD_BANNER_LAYER = new EntityModelLayer(MiddleEarth.id("held_banner"), "main");

private static boolean configsRegistered = false;

@Override
public void onInitializeClient() {
ClientNetworkHandlerME.register(new ConnectionToServer());

KeyInputHandler.register();

// config are only generated AFTER the client language files loaded
// TODO: there might be a better way for this
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (!configsRegistered && I18n.hasTranslation(MiddleEarth.rawTranslationKeyWithModId(LangCategory.CONFIG, "client.section.title"))) {
configsRegistered = true;
ServerConfigME.registerConfigs();
ClientConfigME.registerConfigs();
}
});

EntityModelsME.getModels();
BooleanProperties.ID_MAPPER.put(MiddleEarth.id("sneak_attack"), SneakAttackProperty.CODEC);
BooleanProperties.ID_MAPPER.put(MiddleEarth.id("hot_component"), HotComponentProperty.CODEC);
Expand Down Expand Up @@ -188,11 +204,11 @@ public void onInitializeClient() {
EntityModelLayerRegistry.registerModelLayer(HELD_BANNER_LAYER, HeldBannerEntityModel::getTexturedModelData);


SpecialModelTypes.ID_MAPPER.put(Identifier.of(MiddleEarth.MOD_ID, "held_banner"), HeldBannerModelRenderer.Unbaked.CODEC);
SpecialModelTypes.ID_MAPPER.put(MiddleEarth.id("held_banner"), HeldBannerModelRenderer.Unbaked.CODEC);

SpecialModelTypes.ID_MAPPER.put(Identifier.of(MiddleEarth.MOD_ID, "heater_shield"), HeaterShieldModelRenderer.Unbaked.CODEC);
SpecialModelTypes.ID_MAPPER.put(Identifier.of(MiddleEarth.MOD_ID, "kite_shield"), KiteShieldModelRenderer.Unbaked.CODEC);
SpecialModelTypes.ID_MAPPER.put(Identifier.of(MiddleEarth.MOD_ID, "round_shield"), RoundShieldModelRenderer.Unbaked.CODEC);
SpecialModelTypes.ID_MAPPER.put(MiddleEarth.id("heater_shield"), HeaterShieldModelRenderer.Unbaked.CODEC);
SpecialModelTypes.ID_MAPPER.put(MiddleEarth.id("kite_shield"), KiteShieldModelRenderer.Unbaked.CODEC);
SpecialModelTypes.ID_MAPPER.put(MiddleEarth.id("round_shield"), RoundShieldModelRenderer.Unbaked.CODEC);

for(ArmorModelsME.CustomHelmetModels model : ArmorModelsME.CustomHelmetModels.values()){
ArmorRenderer.register(new HelmetArmorRenderer(model.getModel()), model.getItem());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static void registerBlockEntities() {
private static <T extends BlockEntity> BlockEntityType<T> register(String name,
FabricBlockEntityTypeBuilder.Factory<? extends T> entityFactory,
Block... blocks) {
Identifier id = Identifier.of(MiddleEarth.MOD_ID, name);
Identifier id = MiddleEarth.id(name);
RegistryAliasesME.aliases.add(new RegistryAliasesME.Alias(Registries.BLOCK_ENTITY_TYPE, name));

return Registry.register(Registries.BLOCK_ENTITY_TYPE, id, FabricBlockEntityTypeBuilder.<T>create(entityFactory, blocks).build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -817,21 +817,21 @@ public static Block registerMiscBlock(String name, Function<AbstractBlock.Settin
}

static void registerBlockItem(String name, Block block) {
var item = Registry.register(Registries.ITEM, Identifier.of(MiddleEarth.MOD_ID, name),
var item = Registry.register(Registries.ITEM, MiddleEarth.id(name),
new BlockItem(block, new Item.Settings().registryKey(keyOfItem(name))));
Item.BLOCK_ITEMS.put(block, item);
RegistryAliasesME.aliases.add(new RegistryAliasesME.Alias(Registries.ITEM, name));
}

public static RegistryKey<Block> keyOfBlock(String id) {
return RegistryKey.of(RegistryKeys.BLOCK, Identifier.of(MiddleEarth.MOD_ID, id));
return RegistryKey.of(RegistryKeys.BLOCK, MiddleEarth.id(id));
}

public static RegistryKey<Item> keyOfItem(String id) {
return RegistryKey.of(RegistryKeys.ITEM, Identifier.of(MiddleEarth.MOD_ID, id));
return RegistryKey.of(RegistryKeys.ITEM, MiddleEarth.id(id));
}

public static void registerModBlocks() {
MiddleEarth.LOGGER.logDebugMsg("Registering ModBlocks for " + MiddleEarth.MOD_ID);
MiddleEarth.logRegistryMsg("Blocks");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,6 @@ private static ToIntFunction<BlockState> createLightLevelFromLitBlockState(int l
}

public static void registerModBlocks() {
MiddleEarth.LOGGER.logDebugMsg("Registering ModBlocks for " + MiddleEarth.MOD_ID);
MiddleEarth.logRegistryMsg("Decorative Blocks");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,6 @@ private static OxidizableBlockSetBuilder registerOxidizableBlockSet(OxidizableBl
}

public static void registerModBlockSets() {
MiddleEarth.LOGGER.logDebugMsg("Registering Generic Block Sets for " + MiddleEarth.MOD_ID);
MiddleEarth.logRegistryMsg("Generic Block Sets");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ public static Block registerBlock(String name, Function<AbstractBlock.Settings,
}

static void registerBlockItem(String name, Block block) {
var item = Registry.register(Registries.ITEM, Identifier.of(MiddleEarth.MOD_ID, name),
var item = Registry.register(Registries.ITEM, MiddleEarth.id(name),
new BlockItem(block, new Item.Settings().registryKey(BlockRegistryME.keyOfItem(name))));
Item.BLOCK_ITEMS.put(block, item);

Expand All @@ -676,6 +676,6 @@ static void registerBlockItem(String name, Block block) {
}

public static void registerModBlocks() {
MiddleEarth.LOGGER.logDebugMsg("Registering ModBlocks for " + MiddleEarth.MOD_ID);
MiddleEarth.logRegistryMsg("Nature Blocks");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public static OreRockSet registerOreSet(String rockName, float strength_mult, Li
}

public static void registerModBlockSets() {
MiddleEarth.LOGGER.logDebugMsg("Registering OreSets for " + MiddleEarth.MOD_ID);
MiddleEarth.logRegistryMsg("Ore Block Sets");
}

enum ORES{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,6 @@ private static StoneBlockSetBuilder registerStoneSet(StoneBlockSetBuilder set) {
}

public static void registerModBlockSets() {
MiddleEarth.LOGGER.logDebugMsg("Registering Stone Block Sets for " + MiddleEarth.MOD_ID);
MiddleEarth.logRegistryMsg("Stone Block Sets");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,6 @@ private static WoodBlockSetBuilder registerWoodSet(WoodBlockSetBuilder set) {
}

public static void registerModBlockSets() {
MiddleEarth.LOGGER.logDebugMsg("Registering Wood Block Sets for " + MiddleEarth.MOD_ID);
MiddleEarth.logRegistryMsg("Wood Block Sets");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.sevenstars.api.enums.LangCategory;
import net.sevenstars.middleearth.MiddleEarth;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -39,7 +40,9 @@ public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new BarrelBlockEntity(pos, state){
@Override
protected Text getContainerName() {
return Text.translatable("container.%s.small_crate".formatted(MiddleEarth.MOD_ID));
return Text.translatable(
MiddleEarth.rawTranslationKeyWithModId(LangCategory.CONTAINER, "small_crate")
);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent;
import net.minecraft.world.explosion.Explosion;
import net.sevenstars.api.enums.LangCategory;
import net.sevenstars.middleearth.MiddleEarth;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -300,7 +301,9 @@ protected ActionResult onUse(BlockState state, World world, BlockPos pos, Player
this.playOpenCloseSound(player, world, pos, (Boolean)state.get(OPEN));
world.emitGameEvent(player, this.isOpen(state) ? GameEvent.BLOCK_OPEN : GameEvent.BLOCK_CLOSE, pos);
} else {
player.sendMessage(Text.translatable("alert.%s.large_door.blocked".formatted(MiddleEarth.MOD_ID)), true);
player.sendMessage(Text.translatable(
MiddleEarth.rawTranslationKeyWithModId(LangCategory.ALERT, "large_door.blocked")
), true);
}

return ActionResult.SUCCESS;
Expand Down
Loading