diff --git a/src/main/java/net/minecraftforge/fluids/Fluid.java b/src/main/java/net/minecraftforge/fluids/Fluid.java index 6ec64eab3..febd50cfd 100644 --- a/src/main/java/net/minecraftforge/fluids/Fluid.java +++ b/src/main/java/net/minecraftforge/fluids/Fluid.java @@ -20,6 +20,8 @@ package net.minecraftforge.fluids; import javax.annotation.Nullable; + +import java.awt.Color; import java.util.Locale; import net.minecraft.block.Block; import net.minecraft.block.material.Material; @@ -125,7 +127,29 @@ public class Fluid * The default value of null should remain for any Fluid without a Block implementation. */ protected Block block = null; + + /** + * Color used by universal bucket and the ModelFluid baked model. + * Note that this int includes the alpha so converting this to RGB with alpha would be + * float r = ((color >> 16) & 0xFF) / 255f; // red + * float g = ((color >> 8) & 0xFF) / 255f; // green + * float b = ((color >> 0) & 0xFF) / 255f; // blue + * float a = ((color >> 24) & 0xFF) / 255f; // alpha + */ + protected int color = 0xFFFFFFFF; + public Fluid(String fluidName, ResourceLocation still, ResourceLocation flowing, Color color) + { + this(fluidName, still, flowing); + this.setColor(color); + } + + public Fluid(String fluidName, ResourceLocation still, ResourceLocation flowing, int color) + { + this(fluidName, still, flowing); + this.setColor(color); + } + public Fluid(String fluidName, ResourceLocation still, ResourceLocation flowing) { this.fluidName = fluidName.toLowerCase(Locale.ENGLISH); @@ -201,6 +225,18 @@ public class Fluid this.emptySound = emptySound; return this; } + + public Fluid setColor(Color color) + { + this.color = color.getRGB(); + return this; + } + + public Fluid setColor(int color) + { + this.color = color; + return this; + } public final String getName() { @@ -311,7 +347,7 @@ public class Fluid public int getColor() { - return 0xFFFFFFFF; + return color; } public ResourceLocation getStill() diff --git a/src/test/java/net/minecraftforge/debug/FluidAdditionalFieldsTest.java b/src/test/java/net/minecraftforge/debug/FluidAdditionalFieldsTest.java new file mode 100644 index 000000000..e870fe009 --- /dev/null +++ b/src/test/java/net/minecraftforge/debug/FluidAdditionalFieldsTest.java @@ -0,0 +1,58 @@ +package net.minecraftforge.debug; + +import java.awt.Color; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.event.RegistryEvent; +import net.minecraftforge.fluids.BlockFluidBase; +import net.minecraftforge.fluids.BlockFluidClassic; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber; +import net.minecraftforge.fml.common.Mod.EventHandler; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder; + +@Mod(modid = FluidAdditionalFieldsTest.MODID, name = "Test Mod", version = "1.0.0", acceptedMinecraftVersions = "*") +@EventBusSubscriber +public class FluidAdditionalFieldsTest +{ + static final boolean ENABLED = false; // <-- enable mod + static final Color COLOR = Color.PINK; // <-- change this to try other colors + + static final String MODID = "fluidadditionalfields"; + static final ResourceLocation RES_LOC = new ResourceLocation(MODID, "slime"); + static + { + if (ENABLED) + { + FluidRegistry.enableUniversalBucket(); + } + } + public static final Fluid SLIME = new Fluid("slime", new ResourceLocation(MODID, "slime_still"), new ResourceLocation(MODID, "slime_flow")).setColor(COLOR); + @ObjectHolder("slime") + public static final BlockFluidBase SLIME_BLOCK = null; + + @EventHandler + public void preInit(FMLPreInitializationEvent event) + { + if (ENABLED) + { + FluidRegistry.registerFluid(SLIME); + FluidRegistry.addBucketForFluid(SLIME); + } + } + + @SubscribeEvent + public static void eventBlockRegistry(final RegistryEvent.Register event) + { + if (ENABLED) + { + event.getRegistry().register((new BlockFluidClassic(SLIME, Material.WATER)).setRegistryName(RES_LOC).setUnlocalizedName(RES_LOC.toString())); + } + } +} diff --git a/src/test/resources/assets/fluidadditionalfields/blockstates/slime.json b/src/test/resources/assets/fluidadditionalfields/blockstates/slime.json new file mode 100644 index 000000000..edce38c3a --- /dev/null +++ b/src/test/resources/assets/fluidadditionalfields/blockstates/slime.json @@ -0,0 +1,38 @@ +{ + "forge_marker": 1, + "defaults": { + "textures": { + "particle": "blocks/slime", + "all": "examplemod:blocks/slime_flow" + }, + "model": "forge:fluid", + "custom": { "fluid": "slime" }, + "uvlock": false + }, + "variants": { + "normal": [{ + + }], + "inventory": [{ + + }], + "level": { + "0": { }, + "1": { }, + "2": { }, + "3": { }, + "4": { }, + "5": { }, + "6": { }, + "7": { }, + "8": { }, + "9": { }, + "10": { }, + "11": { }, + "12": { }, + "13": { }, + "14": { }, + "15": { } + } + } +} \ No newline at end of file diff --git a/src/test/resources/assets/fluidadditionalfields/textures/slime_flow.png b/src/test/resources/assets/fluidadditionalfields/textures/slime_flow.png new file mode 100644 index 000000000..a14140566 Binary files /dev/null and b/src/test/resources/assets/fluidadditionalfields/textures/slime_flow.png differ diff --git a/src/test/resources/assets/fluidadditionalfields/textures/slime_flow.png.mcmeta b/src/test/resources/assets/fluidadditionalfields/textures/slime_flow.png.mcmeta new file mode 100644 index 000000000..058b84f78 --- /dev/null +++ b/src/test/resources/assets/fluidadditionalfields/textures/slime_flow.png.mcmeta @@ -0,0 +1,6 @@ +{ + "animation": { + "frametime": 20 + } +} + diff --git a/src/test/resources/assets/fluidadditionalfields/textures/slime_overlay.png b/src/test/resources/assets/fluidadditionalfields/textures/slime_overlay.png new file mode 100644 index 000000000..2c19ed5da Binary files /dev/null and b/src/test/resources/assets/fluidadditionalfields/textures/slime_overlay.png differ diff --git a/src/test/resources/assets/fluidadditionalfields/textures/slime_still.png b/src/test/resources/assets/fluidadditionalfields/textures/slime_still.png new file mode 100644 index 000000000..9538697b9 Binary files /dev/null and b/src/test/resources/assets/fluidadditionalfields/textures/slime_still.png differ diff --git a/src/test/resources/assets/fluidadditionalfields/textures/slime_still.png.mcmeta b/src/test/resources/assets/fluidadditionalfields/textures/slime_still.png.mcmeta new file mode 100644 index 000000000..090b11d7a --- /dev/null +++ b/src/test/resources/assets/fluidadditionalfields/textures/slime_still.png.mcmeta @@ -0,0 +1,5 @@ +{ + "animation": { + "frametime": 20 + } +}