-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Fluid Localization Issues in TOP
- Loading branch information
1 parent
2a2f6a1
commit 0a6cd12
Showing
10 changed files
with
207 additions
and
7 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
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
73 changes: 73 additions & 0 deletions
73
src/main/java/com/nomiceu/nomilabs/integration/top/LabsFluidNameElement.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,73 @@ | ||
package com.nomiceu.nomilabs.integration.top; | ||
|
||
import net.minecraftforge.fluids.FluidRegistry; | ||
import net.minecraftforge.fluids.FluidStack; | ||
|
||
import com.nomiceu.nomilabs.NomiLabs; | ||
import com.nomiceu.nomilabs.util.LabsTranslate; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import mcjty.theoneprobe.api.IElement; | ||
import mcjty.theoneprobe.api.TextStyleClass; | ||
import mcjty.theoneprobe.apiimpl.client.ElementTextRender; | ||
import mcjty.theoneprobe.network.NetworkTools; | ||
|
||
public class LabsFluidNameElement implements IElement { | ||
|
||
private final String fluidName; | ||
private final int amount; | ||
private final String translatedName; | ||
|
||
public LabsFluidNameElement(FluidStack fluid) { | ||
this.fluidName = fluid.getFluid().getName(); | ||
this.amount = fluid.amount; | ||
|
||
// Temp Translated Name, for usage if needed | ||
this.translatedName = fluid.getUnlocalizedName(); | ||
} | ||
|
||
public LabsFluidNameElement(ByteBuf byteBuf) { | ||
this.fluidName = NetworkTools.readStringUTF8(byteBuf); | ||
this.amount = byteBuf.readInt(); | ||
this.translatedName = translateFluid(fluidName, amount, "LabsFluidNameElement"); | ||
} | ||
|
||
@Override | ||
public int getWidth() { | ||
return ElementTextRender.getWidth(translatedName); | ||
} | ||
|
||
@Override | ||
public int getHeight() { | ||
return 10; | ||
} | ||
|
||
@Override | ||
public void toBytes(ByteBuf byteBuf) { | ||
NetworkTools.writeStringUTF8(byteBuf, fluidName); | ||
byteBuf.writeInt(amount); | ||
} | ||
|
||
@Override | ||
public void render(int x, int y) { | ||
ElementTextRender.render( | ||
TextStyleClass.NAME + LabsTranslate.translate("nomilabs.gui.top_override.fluid", translatedName), x, y); | ||
} | ||
|
||
@Override | ||
public int getID() { | ||
return LabsTOPManager.FLUID_NAME_ELEMENT; | ||
} | ||
|
||
public static String translateFluid(String fluidName, int amount, String packet) { | ||
var fluid = FluidRegistry.getFluid(fluidName); | ||
|
||
// At least try and translate it if fluid is null | ||
if (fluid == null) { | ||
NomiLabs.LOGGER.error("Received Fluid Info Packet {} with Unknown Fluid {}!", packet, fluidName); | ||
return LabsTranslate.translate(fluidName); | ||
} | ||
|
||
return fluid.getLocalizedName(new FluidStack(fluid, amount)); | ||
} | ||
} |
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
46 changes: 46 additions & 0 deletions
46
src/main/java/com/nomiceu/nomilabs/mixin/theoneprobe/DefaultProbeInfoProviderMixin.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,46 @@ | ||
package com.nomiceu.nomilabs.mixin.theoneprobe; | ||
|
||
import net.minecraftforge.fluids.FluidStack; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import com.nomiceu.nomilabs.integration.top.LabsFluidNameElement; | ||
|
||
import mcjty.theoneprobe.api.IProbeInfo; | ||
import mcjty.theoneprobe.api.TextStyleClass; | ||
import mcjty.theoneprobe.apiimpl.ProbeConfig; | ||
import mcjty.theoneprobe.apiimpl.elements.ElementProgress; | ||
import mcjty.theoneprobe.apiimpl.providers.DefaultProbeInfoProvider; | ||
import mcjty.theoneprobe.config.Config; | ||
|
||
/** | ||
* Fixes Localization of Fluid Names. | ||
*/ | ||
@Mixin(value = DefaultProbeInfoProvider.class, remap = false) | ||
public class DefaultProbeInfoProviderMixin { | ||
|
||
@Inject(method = "addFluidInfo", at = @At("HEAD"), cancellable = true) | ||
private void showTranslatedFluidInfo(IProbeInfo probeInfo, ProbeConfig config, FluidStack fluidStack, | ||
int maxContents, CallbackInfo ci) { | ||
int contents = fluidStack == null ? 0 : fluidStack.amount; | ||
if (fluidStack != null) { | ||
probeInfo.element(new LabsFluidNameElement(fluidStack)); | ||
} | ||
if (config.getTankMode() == 1) { | ||
probeInfo.progress(contents, maxContents, | ||
probeInfo.defaultProgressStyle() | ||
.suffix("mB") | ||
.filledColor(Config.tankbarFilledColor) | ||
.alternateFilledColor(Config.tankbarAlternateFilledColor) | ||
.borderColor(Config.tankbarBorderColor) | ||
.numberFormat(Config.tankFormat)); | ||
} else { | ||
probeInfo.text(TextStyleClass.PROGRESS + ElementProgress.format(contents, Config.tankFormat, "mB")); | ||
} | ||
|
||
ci.cancel(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/nomiceu/nomilabs/mixin/topaddons/AddonForgeMixin.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,39 @@ | ||
package com.nomiceu.nomilabs.mixin.topaddons; | ||
|
||
import net.minecraftforge.fluids.Fluid; | ||
import net.minecraftforge.fluids.FluidRegistry; | ||
import net.minecraftforge.fluids.FluidStack; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
import io.github.drmanganese.topaddons.addons.AddonForge; | ||
|
||
/** | ||
* Fixes Localization of Fluid Names. | ||
*/ | ||
@Mixin(value = AddonForge.class, remap = false) | ||
public class AddonForgeMixin { | ||
|
||
@Redirect(method = "addTankElement(Lmcjty/theoneprobe/api/IProbeInfo;Ljava/lang/Class;Lnet/minecraftforge/fluids/FluidTank;ILmcjty/theoneprobe/api/ProbeMode;Lnet/minecraft/entity/player/EntityPlayer;)Lmcjty/theoneprobe/api/IProbeInfo;", | ||
at = @At(value = "INVOKE", | ||
target = "Lnet/minecraftforge/fluids/FluidStack;getLocalizedName()Ljava/lang/String;")) | ||
private static String useFluidName1(FluidStack instance) { | ||
return FluidRegistry.getFluidName(instance); | ||
} | ||
|
||
@Redirect(method = "addTankElement(Lmcjty/theoneprobe/api/IProbeInfo;Ljava/lang/String;Lnet/minecraftforge/fluids/FluidTankInfo;Lmcjty/theoneprobe/api/ProbeMode;Lnet/minecraft/entity/player/EntityPlayer;)Lmcjty/theoneprobe/api/IProbeInfo;", | ||
at = @At(value = "INVOKE", | ||
target = "Lnet/minecraftforge/fluids/FluidStack;getLocalizedName()Ljava/lang/String;")) | ||
private static String useUnlocalizedName2(FluidStack instance) { | ||
return FluidRegistry.getFluidName(instance); | ||
} | ||
|
||
@Redirect(method = "addProbeInfo", | ||
at = @At(value = "INVOKE", | ||
target = "Lnet/minecraftforge/fluids/Fluid;getLocalizedName(Lnet/minecraftforge/fluids/FluidStack;)Ljava/lang/String;")) | ||
private String useUnlocalizedName3(Fluid instance, FluidStack stack) { | ||
return FluidRegistry.getFluidName(instance); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/nomiceu/nomilabs/mixin/topaddons/ElementTankGaugeMixin.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,32 @@ | ||
package com.nomiceu.nomilabs.mixin.topaddons; | ||
|
||
import org.spongepowered.asm.mixin.*; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import com.nomiceu.nomilabs.integration.top.LabsFluidNameElement; | ||
|
||
import io.github.drmanganese.topaddons.elements.ElementTankGauge; | ||
import io.netty.buffer.ByteBuf; | ||
|
||
/** | ||
* Fixes Localization of Fluid Names. (Client Only) | ||
*/ | ||
@Mixin(value = ElementTankGauge.class, remap = false) | ||
public class ElementTankGaugeMixin { | ||
|
||
@Shadow | ||
@Final | ||
@Mutable | ||
private String fluidName; | ||
|
||
@Shadow | ||
@Final | ||
private int amount; | ||
|
||
@Inject(method = "<init>(Lio/netty/buffer/ByteBuf;)V", at = @At("RETURN")) | ||
private void translateFluidName(ByteBuf buf, CallbackInfo ci) { | ||
fluidName = LabsFluidNameElement.translateFluid(fluidName, amount, "ElementTankGauge"); | ||
} | ||
} |
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