Skip to content

Commit 4412c71

Browse files
authored
top addons fluid compat (GregTechCEu#1996)
1 parent 0603a87 commit 4412c71

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.github.drmanganese.topaddons.reference;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
/**
7+
* Adapted and minimized from <a href="https://github.com/DrManganese/TOPAddons/blob/1.12/src/main/java/io/github/drmanganese/topaddons/reference/Colors.java">Colors.java</a>
8+
*/
9+
public final class Colors {
10+
11+
public static final Map<String, Integer> FLUID_NAME_COLOR_MAP = new HashMap<>();
12+
}

src/main/java/gregtech/api/GTValues.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ public class GTValues {
145145
MODID_VOXELMAP = "voxelmap",
146146
MODID_XAERO_MINIMAP = "xaerominimap",
147147
MODID_HWYLA = "hwyla",
148-
MODID_BAUBLES = "baubles";
148+
MODID_BAUBLES = "baubles",
149+
MODID_TOP_ADDONS = "topaddons";
149150

150151
private static Boolean isClient;
151152

src/main/java/gregtech/api/fluids/MetaFluids.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import gregtech.api.util.GTUtility;
2020
import gregtech.api.util.LocalizationUtils;
2121
import gregtech.common.blocks.MetaBlocks;
22+
import io.github.drmanganese.topaddons.reference.Colors;
2223
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
2324
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
2425
import net.minecraft.client.renderer.texture.TextureMap;
@@ -27,6 +28,7 @@
2728
import net.minecraftforge.fluids.BlockFluidBase;
2829
import net.minecraftforge.fluids.Fluid;
2930
import net.minecraftforge.fluids.FluidRegistry;
31+
import net.minecraftforge.fml.common.Loader;
3032

3133
import javax.annotation.Nonnull;
3234
import javax.annotation.Nullable;
@@ -237,6 +239,7 @@ public static Fluid registerFluid(@Nonnull Material material, @Nonnull FluidType
237239
if (material.hasFluidColor()) {
238240
fluid.setColor(GTUtility.convertRGBtoOpaqueRGBA_MC(material.getMaterialRGB()));
239241
} else {
242+
// set color to 0xFFFFFFFF to preserve fluid texture
240243
fluid.setColor(0xFFFFFFFF);
241244
}
242245

@@ -245,6 +248,8 @@ public static Fluid registerFluid(@Nonnull Material material, @Nonnull FluidType
245248

246249
if (material.hasFlag(MaterialFlags.STICKY)) fluid.setViscosity(2000);
247250

251+
registerFluidModCompat(fluidName, material, fluid);
252+
248253
((MaterialFluid) fluid).registerFluidTooltip();
249254
FluidRegistry.registerFluid(fluid);
250255
fixFluidRegistryName(fluid, material.getModid());
@@ -267,6 +272,12 @@ public static Fluid registerFluid(@Nonnull Material material, @Nonnull FluidType
267272
return fluid;
268273
}
269274

275+
private static void registerFluidModCompat(@Nonnull String fluidName, @Nonnull Material material, @Nonnull Fluid fluid) {
276+
if (!material.hasFluidColor() && Loader.isModLoaded(GTValues.MODID_TOP_ADDONS)) {
277+
Colors.FLUID_NAME_COLOR_MAP.put(fluidName, GTUtility.convertRGBtoARGB(material.getMaterialRGB()));
278+
}
279+
}
280+
270281
/**
271282
* Fixes all registered fluids being under the gregtech modid
272283
*

src/main/java/gregtech/api/util/GTUtility.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ public static int convertRGBtoOpaqueRGBA_MC(int colorValue, int opacity) {
9494
return opacity << 24 | colorValue;
9595
}
9696

97+
public static int convertRGBtoARGB(int colorValue) {
98+
return convertRGBtoARGB(colorValue, 0xFF);
99+
}
100+
101+
public static int convertRGBtoARGB(int colorValue, int opacity) {
102+
// preserve existing opacity if present
103+
if (((colorValue >> 24) & 0xFF) != 0) return colorValue;
104+
return opacity << 24 | colorValue;
105+
}
106+
97107
/**
98108
* Attempts to merge given ItemStack with ItemStacks in slot list supplied
99109
* If it's not possible to merge it fully, it will attempt to insert it into first empty slots

0 commit comments

Comments
 (0)