Skip to content

Commit

Permalink
Custom Tank Names for Singleblock MTEs
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Jan 3, 2025
1 parent 8e32df2 commit 4a0efc7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
package com.nomiceu.nomilabs.mixin.topaddons;

import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
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.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
import com.nomiceu.nomilabs.util.LabsTranslate;

import gregtech.api.metatileentity.SimpleMachineMetaTileEntity;
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import io.github.drmanganese.topaddons.addons.AddonForge;
import mcjty.theoneprobe.api.IProbeHitData;
import mcjty.theoneprobe.api.IProbeInfo;
import mcjty.theoneprobe.api.ProbeMode;

/**
* Fixes Localization of Fluid Names.
Expand Down Expand Up @@ -45,4 +55,28 @@ private String useUnlocalizedName3(Fluid instance, FluidStack stack) {
private String localizedTank(String constant) {
return LabsTranslate.translate("topaddons.fluid_display.tank.display.default");
}

@Inject(method = "addProbeInfo",
at = @At(value = "INVOKE",
target = "Lnet/minecraftforge/fluids/capability/IFluidTankProperties;getContents()Lnet/minecraftforge/fluids/FluidStack;",
ordinal = 0),
require = 1,
locals = LocalCapture.CAPTURE_FAILEXCEPTION)
private void gtTankNames(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world,
IBlockState blockState, IProbeHitData data, CallbackInfo ci,
@Local int i,
@Local(ordinal = 1) LocalRef<String> tankName) {
TileEntity tile = world.getTileEntity(data.getPos());

if (tile instanceof IGregTechTileEntity gt &&
gt.getMetaTileEntity() instanceof SimpleMachineMetaTileEntity simple) {
int inputAmt = simple.getRecipeMap().getMaxFluidInputs();
int outputAmt = simple.getRecipeMap().getMaxFluidOutputs();

if (i > inputAmt - 1)
tankName.set(LabsTranslate.translate("topaddons.fluid_display.tank.display.output"));
else
tankName.set(LabsTranslate.translate("topaddons.fluid_display.tank.display.input"));
}
}
}
5 changes: 4 additions & 1 deletion src/main/resources/assets/topaddons/lang/en_us.lang
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
topaddons.fluid_display.tank.display.default=Tank
topaddons.fluid_display.tank.display.default=Tank

topaddons.fluid_display.tank.display.input=Input
topaddons.fluid_display.tank.display.output=Output

0 comments on commit 4a0efc7

Please sign in to comment.