Files
MinecraftForge/src/test/java/net/minecraftforge/debug/ModelFluidDebug.java
T
LexManos a26d89c876 First pass of registry rewrite.
Tests do not run yet.
Things of note:
Removed the idea of substitutions, just register multiple items with the same name they will override each other like a normal map.
Decoupled Forge registries from vanilla classes. They now use bouncer classes. MODDERS SHOULD NEVER USE THESE
Introduced more stringent registry locking. As it sits things are only allowed to be registered during the RegistryEvent.Registry phases!
This is to force modders to split up their registrations, and pave the way for calling these functions multiple times during a single MC lifecycle.
ObjectHolder, Missing Mappings, etc... *should* now work for all registry types, nothing should be special cased to Blocks/Items anymore.
Added optional generic dummy factory to registries, to allow registry creators the ability to dummy more then just Blocks.
Re-worked the ItemStack transformer and applied it to ItemBlock and ItemBlockSpecial. Allowing us to cleanup reflective hacks in Block callbacks.
Registry onAdd callback is now only fired on the ACTIVE registry, fixing any issues of temp registries overriding active objects.
2017-06-23 16:59:57 -05:00

202 lines
7.4 KiB
Java

package net.minecraftforge.debug;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.ForgeVersion;
import net.minecraftforge.event.RegistryEvent;
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.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 = ModelFluidDebug.MODID, name = "ForgeDebugModelFluid", version = ModelFluidDebug.VERSION, acceptableRemoteVersions = "*")
public class ModelFluidDebug
{
public static final String MODID = "forgedebugmodelfluid";
public static final String VERSION = "1.0";
public static final boolean ENABLE = true;
private static ModelResourceLocation fluidLocation = new ModelResourceLocation(MODID.toLowerCase() + ":" + TestFluidBlock.name, "fluid");
private static ModelResourceLocation gasLocation = new ModelResourceLocation(MODID.toLowerCase() + ":" + TestFluidBlock.name, "gas");
private static ModelResourceLocation milkLocation = new ModelResourceLocation(MODID.toLowerCase() + ":" + TestFluidBlock.name, "milk");
@ObjectHolder(TestFluidBlock.name)
public static final Block FLUID_BLOCK = null;
@ObjectHolder(TestFluidBlock.name)
public static final Item FLUID_ITEM = null;
@ObjectHolder(TestGasBlock.name)
public static final Block GAS_BLOCK = null;
@ObjectHolder(TestGasBlock.name)
public static final Item GAS_ITEM = null;
@ObjectHolder(MilkFluidBlock.name)
public static final Block MILK_BLOCK = null;
@ObjectHolder(MilkFluidBlock.name)
public static final Item MILK_ITEM = null;
//Used in DynBucketTest/FluidPlacementTest, TODO: Make this a full registry with @ObjectHolder?
public static final Fluid MILK = new Fluid("milk", new ResourceLocation(ForgeVersion.MOD_ID, "blocks/milk_still"), new ResourceLocation(ForgeVersion.MOD_ID, "blocks/milk_flow"));
public static final Fluid FLUID = new TestFluid();
public static final Fluid GAS = new TestGas();
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
if (ENABLE)
{
FluidRegistry.registerFluid(FLUID);
FluidRegistry.registerFluid(GAS);
FluidRegistry.registerFluid(MILK);
}
}
@Mod.EventBusSubscriber(modid = MODID)
public static class Registration
{
@SubscribeEvent
public static void registerBlocks(RegistryEvent.Register<Block> event)
{
if (!ENABLE)
return;
event.getRegistry().registerAll(
new TestFluidBlock(),
new TestGasBlock(),
new MilkFluidBlock()
);
}
@SubscribeEvent
public static void registerItems(RegistryEvent.Register<Item> event)
{
if (!ENABLE)
return;
event.getRegistry().registerAll(
new ItemBlock(FLUID_BLOCK).setRegistryName(FLUID_BLOCK.getRegistryName()),
new ItemBlock(GAS_BLOCK).setRegistryName(GAS_BLOCK.getRegistryName()),
new ItemBlock(MILK_BLOCK).setRegistryName(MILK_BLOCK.getRegistryName())
);
}
@SubscribeEvent
public static void registerModels(ModelRegistryEvent event)
{
if (!ENABLE)
return;
// no need to pass the locations here, since they'll be loaded by the block model logic.
ModelBakery.registerItemVariants(FLUID_ITEM);
ModelBakery.registerItemVariants(GAS_ITEM);
ModelBakery.registerItemVariants(MILK_ITEM);
ModelLoader.setCustomMeshDefinition(FLUID_ITEM, is -> fluidLocation);
ModelLoader.setCustomMeshDefinition(GAS_ITEM, is -> gasLocation);
ModelLoader.setCustomMeshDefinition(MILK_ITEM, is -> milkLocation);
ModelLoader.setCustomStateMapper(FLUID_BLOCK, new StateMapperBase()
{
protected ModelResourceLocation getModelResourceLocation(IBlockState state)
{
return fluidLocation;
}
});
ModelLoader.setCustomStateMapper(GAS_BLOCK, new StateMapperBase()
{
protected ModelResourceLocation getModelResourceLocation(IBlockState state)
{
return gasLocation;
}
});
ModelLoader.setCustomStateMapper(MILK_BLOCK, new StateMapperBase()
{
protected ModelResourceLocation getModelResourceLocation(IBlockState state)
{
return milkLocation;
}
});
}
}
public static final class TestFluid extends Fluid
{
public static final String name = "testfluid";
private TestFluid()
{
super(name, new ResourceLocation("blocks/water_still"), new ResourceLocation("blocks/water_flow"));
}
@Override
public int getColor()
{
return 0xFF00FF00;
}
}
public static final class TestGas extends Fluid
{
public static final String name = "testgas";
private TestGas()
{
super(name, new ResourceLocation("blocks/lava_still"), new ResourceLocation("blocks/lava_flow"));
density = -1000;
isGaseous = true;
}
@Override
public int getColor()
{
return 0xFFFF0000;
}
}
public static final class TestFluidBlock extends BlockFluidClassic
{
public static final String name = "test_fluid_block";
private TestFluidBlock()
{
super(FLUID, Material.WATER);
setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
setUnlocalizedName(MODID + ":" + name);
setRegistryName(new ResourceLocation(MODID, name));
}
}
public static final class MilkFluidBlock extends BlockFluidClassic
{
public static final String name = "milk_fluid_block";
private MilkFluidBlock()
{
super(MILK, Material.WATER);
setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
setUnlocalizedName(MODID + ":" + name);
setRegistryName(new ResourceLocation(MODID, name));
}
}
public static final class TestGasBlock extends BlockFluidClassic
{
public static final String name = "test_gas_block";
private TestGasBlock()
{
super(GAS, Material.LAVA);
setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
setUnlocalizedName(MODID + ":" + name);
setRegistryName(new ResourceLocation(MODID, name));
}
}
}