Skip to content

Commit

Permalink
Move language handling to NOVA side (#258)
Browse files Browse the repository at this point in the history
* Move language handling to NOVA side

* Undo FakeLanguageManager move + Remove Translatable.languageManager() method
  • Loading branch information
ExE-Boss authored and RX14 committed Feb 24, 2017
1 parent c159963 commit 4872e5f
Show file tree
Hide file tree
Showing 28 changed files with 556 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

package nova.core.wrapper.mc.forge.v17.depmodules;

import nova.core.util.registry.LanguageManager;
import nova.core.language.LanguageManager;
import nova.core.wrapper.mc.forge.v17.util.MCLanguageManager;
import se.jbee.inject.bind.BinderModule;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,56 @@
package nova.core.wrapper.mc.forge.v17.util;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.LanguageRegistry;
import net.minecraft.util.StatCollector;
import nova.core.util.registry.LanguageManager;
import nova.core.event.LanguageEvent;
import nova.core.event.bus.EventBus;
import nova.core.language.LanguageManager;
import nova.core.wrapper.mc.forge.v17.launcher.ForgeLoadable;
import nova.core.wrapper.mc.forge.v17.launcher.NovaMinecraft;
import nova.internal.core.Game;

/**
* @author Calclavia
*/
public class MCLanguageManager extends LanguageManager {
public class MCLanguageManager extends LanguageManager implements ForgeLoadable {

@Override
public void register(String language, String key, String value) {
LanguageRegistry.instance().addStringLocalization(key, language, value);
super.register(language, key, value);
}

public MCLanguageManager() {
NovaMinecraft.registerWrapper(this);
}

@Override
public String getCurrentLanguage() {
return FMLCommonHandler.instance().getCurrentLanguage();
return FMLCommonHandler.instance().getCurrentLanguage().replace('_', '-');
}

@Override
public String translate(String key) {
return StatCollector.translateToLocal(key);
String value = super.translate(key);
if (value.equals(key))
value = StatCollector.translateToLocal(key);
return value;
}

@Override
public void init() {
Game.events().publish(new Init(this));
@SuppressWarnings("deprecation")
public void preInit(FMLPreInitializationEvent evt) {
this.languageMap.forEach((language, map) -> {
String lang = language.replace('-', '_');
map.forEach((key, value) -> LanguageRegistry.instance().addStringLocalization(key, lang, value));
});

Game.events().on(LanguageEvent.RegisterTranslation.class).withPriority(EventBus.PRIORITY_LOW).bind(this::register);
}

@SuppressWarnings("deprecation")
public void register(LanguageEvent.RegisterTranslation evt) {
LanguageRegistry.instance().addStringLocalization(evt.key, evt.language.replace('-', '_'), evt.value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,14 @@ public void load(Data data) {
tileEntity.writeToNBT(Game.natives().toNative(data));
}
}

@Override
public String getLocalizedName() {
return mcBlock.getLocalizedName();
}

@Override
public String getUnlocalizedName() {
return mcBlock.getUnlocalizedName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ public FWBlock(BlockFactory factory) {
this.stepSound = soundTypeStone;
}
this.blockClass = dummy.getClass();
this.setBlockName(dummy.getID());

// Recalculate super constructor things after loading the block properly
this.opaque = isOpaqueCube();
Expand Down Expand Up @@ -402,7 +401,12 @@ public int isProvidingStrongPower(IBlockAccess access, int x, int y, int z, int

@Override
public String getUnlocalizedName() {
return super.getUnlocalizedName().replaceFirst("tile", "block");
return factory.getUnlocalizedName();
}

@Override
public String getLocalizedName() {
return factory.getLocalizedName();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ public net.minecraft.item.ItemStack makeItemStack(int stackSize) {
return result;
}

@Override
public String getLocalizedName() {
return this.item.getItemStackDisplayName(makeItemStack(count()));
}

@Override
public String getUnlocalizedName() {
return this.item.getUnlocalizedName(makeItemStack(count()));
}

@Override
public String toString() {
return getID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public int getMeta() {
return meta;
}

@Override
public String getUnlocalizedName() {
return this.item.getUnlocalizedName();
}

@Override
public Item build(Data data) {
int meta = (Integer) data.getOrDefault("damage", this.meta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public class FWItem extends net.minecraft.item.Item implements ItemWrapperMethod

public FWItem(ItemFactory item) {
this.itemFactory = item;
setUnlocalizedName(item.getID());
setMaxStackSize(item.build().getMaxCount());
}

Expand Down Expand Up @@ -81,4 +80,19 @@ public int getColorFromItemStack(ItemStack p_82790_1_, int p_82790_2_) {
public void registerIcons(IIconRegister ir) {

}

@Override
public String getUnlocalizedName() {
return getItemFactory().getUnlocalizedName();
}

@Override
public String getUnlocalizedName(ItemStack stack) {
return ItemConverter.instance().toNova(stack).getUnlocalizedName();
}

@Override
public String getItemStackDisplayName(ItemStack stack) {
return ItemConverter.instance().toNova(stack).getLocalizedName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,19 @@ public int getColorFromItemStack(ItemStack p_82790_1_, int p_82790_2_) {
public void registerIcons(IIconRegister ir) {

}

@Override
public String getUnlocalizedName() {
return getItemFactory().getUnlocalizedName();
}

@Override
public String getUnlocalizedName(ItemStack stack) {
return ItemConverter.instance().toNova(stack).getUnlocalizedName();
}

@Override
public String getItemStackDisplayName(ItemStack stack) {
return ItemConverter.instance().toNova(stack).getLocalizedName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

package nova.core.wrapper.mc.forge.v18.depmodules;

import nova.core.util.registry.LanguageManager;
import nova.core.language.LanguageManager;
import nova.core.wrapper.mc.forge.v18.util.MCLanguageManager;
import se.jbee.inject.bind.BinderModule;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,55 @@

import net.minecraft.util.StatCollector;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.LanguageRegistry;
import nova.core.util.registry.LanguageManager;
import nova.core.event.LanguageEvent;
import nova.core.event.bus.EventBus;
import nova.core.language.LanguageManager;
import nova.core.wrapper.mc.forge.v18.launcher.ForgeLoadable;
import nova.core.wrapper.mc.forge.v18.launcher.NovaMinecraft;
import nova.internal.core.Game;

/**
* @author Calclavia
*/
public class MCLanguageManager extends LanguageManager {
public class MCLanguageManager extends LanguageManager implements ForgeLoadable {

@Override
public void register(String language, String key, String value) {
LanguageRegistry.instance().addStringLocalization(key, language, value);
super.register(language, key, value);
}

public MCLanguageManager() {
NovaMinecraft.registerWrapper(this);
}

@Override
public String getCurrentLanguage() {
return FMLCommonHandler.instance().getCurrentLanguage();
return FMLCommonHandler.instance().getCurrentLanguage().replace('_', '-');
}

@Override
public String translate(String key) {
return StatCollector.translateToLocal(key);
String value = super.translate(key);
if (value.equals(key))
value = StatCollector.translateToLocal(key);
return value;
}

@Override
public void init() {
Game.events().publish(new Init(this));
@SuppressWarnings("deprecation")
public void preInit(FMLPreInitializationEvent evt) {
this.languageMap.forEach((language, map) -> {
String lang = language.replace('-', '_');
map.forEach((key, value) -> LanguageRegistry.instance().addStringLocalization(key, lang, value));
});

Game.events().on(LanguageEvent.RegisterTranslation.class).withPriority(EventBus.PRIORITY_LOW).bind(this::register);
}

@SuppressWarnings("deprecation")
public void register(LanguageEvent.RegisterTranslation evt) {
LanguageRegistry.instance().addStringLocalization(evt.key, evt.language.replace('-', '_'), evt.value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,14 @@ public void load(Data data) {
tileEntity.writeToNBT(Game.natives().toNative(data));
}
}

@Override
public String getLocalizedName() {
return mcBlock.getLocalizedName();
}

@Override
public String getUnlocalizedName() {
return mcBlock.getUnlocalizedName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public FWBlock(BlockFactory factory) {
this.stepSound = soundTypeStone;
}
this.blockClass = dummy.getClass();
this.setUnlocalizedName(dummy.getID());

// Recalculate super constructor things after loading the block properly
this.fullBlock = isOpaqueCube();
Expand Down Expand Up @@ -366,7 +365,12 @@ public int isProvidingStrongPower(IBlockAccess access, BlockPos pos, IBlockState

@Override
public String getUnlocalizedName() {
return super.getUnlocalizedName().replaceFirst("tile", "block");
return factory.getUnlocalizedName();
}

@Override
public String getLocalizedName() {
return factory.getLocalizedName();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ public ItemStack makeItemStack(int stackSize) {
return result;
}

@Override
public String getLocalizedName() {
return this.item.getItemStackDisplayName(makeItemStack(count()));
}

@Override
public String getUnlocalizedName() {
return this.item.getUnlocalizedName(makeItemStack(count()));
}

@Override
public String toString() {
return getID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public int getMeta() {
return meta;
}

@Override
public String getUnlocalizedName() {
return this.item.getUnlocalizedName();
}

@Override
public Item build(Data data) {
int meta = (Integer) data.getOrDefault("damage", this.meta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public class FWItem extends net.minecraft.item.Item implements ItemWrapperMethod

public FWItem(ItemFactory item) {
this.itemFactory = item;
setUnlocalizedName(item.getID());
setMaxStackSize(item.build().getMaxCount());
}

Expand Down Expand Up @@ -67,4 +66,18 @@ public int getColorFromItemStack(ItemStack p_82790_1_, int p_82790_2_) {
return ItemWrapperMethods.super.getColorFromItemStack(p_82790_1_, p_82790_2_);
}

@Override
public String getUnlocalizedName() {
return getItemFactory().getUnlocalizedName();
}

@Override
public String getUnlocalizedName(ItemStack stack) {
return ItemConverter.instance().toNova(stack).getUnlocalizedName();
}

@Override
public String getItemStackDisplayName(ItemStack stack) {
return ItemConverter.instance().toNova(stack).getLocalizedName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,19 @@ public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPl
public int getColorFromItemStack(ItemStack p_82790_1_, int p_82790_2_) {
return ItemWrapperMethods.super.getColorFromItemStack(p_82790_1_, p_82790_2_);
}

@Override
public String getUnlocalizedName() {
return getItemFactory().getUnlocalizedName();
}

@Override
public String getUnlocalizedName(ItemStack stack) {
return ItemConverter.instance().toNova(stack).getUnlocalizedName();
}

@Override
public String getItemStackDisplayName(ItemStack stack) {
return ItemConverter.instance().toNova(stack).getLocalizedName();
}
}
Loading

0 comments on commit 4872e5f

Please sign in to comment.