Added color as field with setter to Fluid class. (#4460)
This commit is contained in:
parent
49596910fc
commit
07c4da8f36
|
@ -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()
|
||||
|
|
|
@ -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<Block> event)
|
||||
{
|
||||
if (ENABLED)
|
||||
{
|
||||
event.getRegistry().register((new BlockFluidClassic(SLIME, Material.WATER)).setRegistryName(RES_LOC).setUnlocalizedName(RES_LOC.toString()));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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": { }
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"animation": {
|
||||
"frametime": 20
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 1000 B |
Binary file not shown.
After Width: | Height: | Size: 7.6 KiB |
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"animation": {
|
||||
"frametime": 20
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue