Fix some test mods crashing server caused by model loading (#4225)
This commit is contained in:
parent
7d0a8524aa
commit
e59b979e1b
|
@ -59,6 +59,7 @@ import net.minecraftforge.fml.common.eventhandler.Event.Result;
|
|||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
|
||||
|
@ -94,25 +95,6 @@ public class DynBucketTest
|
|||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void setupModels(ModelRegistryEvent event)
|
||||
{
|
||||
ModelLoader.setBucketModelDefinition(DYN_BOTTLE);
|
||||
|
||||
final ModelResourceLocation bottle = new ModelResourceLocation(new ResourceLocation(ForgeVersion.MOD_ID, "dynbottle"), "inventory");
|
||||
ModelLoader.setCustomMeshDefinition(DYN_BOTTLE, new ItemMeshDefinition()
|
||||
{
|
||||
@Override
|
||||
public ModelResourceLocation getModelLocation(@Nonnull ItemStack stack)
|
||||
{
|
||||
return bottle;
|
||||
}
|
||||
});
|
||||
ModelBakery.registerItemVariants(DYN_BOTTLE, bottle);
|
||||
ModelLoader.setCustomModelResourceLocation(Item.REGISTRY.getObject(simpleTankName), 0, new ModelResourceLocation(simpleTankName, "normal"));
|
||||
ModelLoader.setCustomModelResourceLocation(Item.REGISTRY.getObject(testItemName), 0, new ModelResourceLocation(new ResourceLocation("minecraft", "stick"), "inventory"));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void registrBlocks(RegistryEvent.Register<Block> event)
|
||||
{
|
||||
|
@ -180,6 +162,29 @@ public class DynBucketTest
|
|||
}
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(value = Side.CLIENT, modid = MODID)
|
||||
public static class ClientEventHandler
|
||||
{
|
||||
@SubscribeEvent
|
||||
public static void setupModels(ModelRegistryEvent event)
|
||||
{
|
||||
ModelLoader.setBucketModelDefinition(DYN_BOTTLE);
|
||||
|
||||
final ModelResourceLocation bottle = new ModelResourceLocation(new ResourceLocation(ForgeVersion.MOD_ID, "dynbottle"), "inventory");
|
||||
ModelLoader.setCustomMeshDefinition(DYN_BOTTLE, new ItemMeshDefinition()
|
||||
{
|
||||
@Override
|
||||
public ModelResourceLocation getModelLocation(@Nonnull ItemStack stack)
|
||||
{
|
||||
return bottle;
|
||||
}
|
||||
});
|
||||
ModelBakery.registerItemVariants(DYN_BOTTLE, bottle);
|
||||
ModelLoader.setCustomModelResourceLocation(Item.REGISTRY.getObject(simpleTankName), 0, new ModelResourceLocation(simpleTankName, "normal"));
|
||||
ModelLoader.setCustomModelResourceLocation(Item.REGISTRY.getObject(testItemName), 0, new ModelResourceLocation(new ResourceLocation("minecraft", "stick"), "inventory"));
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestItem extends Item
|
||||
{
|
||||
@Override
|
||||
|
|
|
@ -80,7 +80,11 @@ public class FluidPlacementTest
|
|||
);
|
||||
MinecraftForge.EVENT_BUS.register(FluidContainer.instance);
|
||||
}
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(value = Side.CLIENT, modid = MODID)
|
||||
public static class ClientEventHandler
|
||||
{
|
||||
@SubscribeEvent
|
||||
public static void registerModels(ModelRegistryEvent event)
|
||||
{
|
||||
|
|
|
@ -22,6 +22,7 @@ import net.minecraftforge.fml.common.Mod;
|
|||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
@EventBusSubscriber
|
||||
@Mod (modid = FogColorInsideMaterialTest.MOD_ID, name = "FogColor inside material debug.", version = "1.0", acceptableRemoteVersions = "*")
|
||||
|
@ -60,20 +61,24 @@ public class FogColorInsideMaterialTest
|
|||
event.getRegistry().register(new ItemBlock(FLUID_BLOCK).setRegistryName(testFluidRegistryName));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerModels(ModelRegistryEvent event)
|
||||
@EventBusSubscriber(value = Side.CLIENT, modid = MOD_ID)
|
||||
public static class ClientEventHandler
|
||||
{
|
||||
ModelResourceLocation fluidLocation = new ModelResourceLocation(testFluidRegistryName, "fluid");
|
||||
ModelLoader.registerItemVariants(FLUID_ITEM);
|
||||
ModelLoader.setCustomMeshDefinition(FLUID_ITEM, stack -> fluidLocation);
|
||||
ModelLoader.setCustomStateMapper(FLUID_BLOCK, new StateMapperBase()
|
||||
@SubscribeEvent
|
||||
public static void registerModels(ModelRegistryEvent event)
|
||||
{
|
||||
@Override
|
||||
protected ModelResourceLocation getModelResourceLocation(IBlockState state)
|
||||
ModelResourceLocation fluidLocation = new ModelResourceLocation(testFluidRegistryName, "fluid");
|
||||
ModelLoader.registerItemVariants(FLUID_ITEM);
|
||||
ModelLoader.setCustomMeshDefinition(FLUID_ITEM, stack -> fluidLocation);
|
||||
ModelLoader.setCustomStateMapper(FLUID_BLOCK, new StateMapperBase()
|
||||
{
|
||||
return fluidLocation;
|
||||
}
|
||||
});
|
||||
@Override
|
||||
protected ModelResourceLocation getModelResourceLocation(IBlockState state)
|
||||
{
|
||||
return fluidLocation;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -77,32 +77,36 @@ public class ForgeBlockStatesLoaderDebug
|
|||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void registerModels(ModelRegistryEvent event)
|
||||
@Mod.EventBusSubscriber(value = Side.CLIENT, modid = MODID)
|
||||
public static class ClientEventHandler
|
||||
{
|
||||
//ModelLoader.setCustomStateMapper(blockCustom, new StateMap.Builder().withName(CustomMappedBlock.VARIANT).build());
|
||||
|
||||
ModelLoader.setCustomStateMapper(BLOCKS.custom_wall, new IStateMapper()
|
||||
@SubscribeEvent
|
||||
public void registerModels(ModelRegistryEvent event)
|
||||
{
|
||||
StateMap stateMap = new StateMap.Builder().withName(BlockWall.VARIANT).withSuffix("_wall").build();
|
||||
//ModelLoader.setCustomStateMapper(blockCustom, new StateMap.Builder().withName(CustomMappedBlock.VARIANT).build());
|
||||
|
||||
@Override
|
||||
public Map<IBlockState, ModelResourceLocation> putStateModelLocations(Block block)
|
||||
ModelLoader.setCustomStateMapper(BLOCKS.custom_wall, new IStateMapper()
|
||||
{
|
||||
Map<IBlockState, ModelResourceLocation> map = stateMap.putStateModelLocations(block);
|
||||
Map<IBlockState, ModelResourceLocation> newMap = Maps.newHashMap();
|
||||
StateMap stateMap = new StateMap.Builder().withName(BlockWall.VARIANT).withSuffix("_wall").build();
|
||||
|
||||
for (Entry<IBlockState, ModelResourceLocation> e : map.entrySet())
|
||||
@Override
|
||||
public Map<IBlockState, ModelResourceLocation> putStateModelLocations(Block block)
|
||||
{
|
||||
ModelResourceLocation loc = e.getValue();
|
||||
newMap.put(e.getKey(), new ModelResourceLocation(ASSETS + loc.getResourcePath(), loc.getVariant()));
|
||||
}
|
||||
Map<IBlockState, ModelResourceLocation> map = stateMap.putStateModelLocations(block);
|
||||
Map<IBlockState, ModelResourceLocation> newMap = Maps.newHashMap();
|
||||
|
||||
return newMap;
|
||||
}
|
||||
});
|
||||
ModelLoader.setCustomModelResourceLocation(ITEMS.custom_wall, 0, new ModelResourceLocation(ASSETS + "cobblestone_wall", "inventory"));
|
||||
ModelLoader.setCustomModelResourceLocation(ITEMS.custom_wall, 1, new ModelResourceLocation(ASSETS + "mossy_cobblestone_wall", "inventory"));
|
||||
for (Entry<IBlockState, ModelResourceLocation> e : map.entrySet())
|
||||
{
|
||||
ModelResourceLocation loc = e.getValue();
|
||||
newMap.put(e.getKey(), new ModelResourceLocation(ASSETS + loc.getResourcePath(), loc.getVariant()));
|
||||
}
|
||||
|
||||
return newMap;
|
||||
}
|
||||
});
|
||||
ModelLoader.setCustomModelResourceLocation(ITEMS.custom_wall, 0, new ModelResourceLocation(ASSETS + "cobblestone_wall", "inventory"));
|
||||
ModelLoader.setCustomModelResourceLocation(ITEMS.custom_wall, 1, new ModelResourceLocation(ASSETS + "mossy_cobblestone_wall", "inventory"));
|
||||
}
|
||||
}
|
||||
|
||||
// this block is never actually used, it's only needed for the error message on load to see the variant it maps to
|
||||
|
|
|
@ -32,6 +32,8 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.registries.RegistryBuilder;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
@ -58,6 +60,11 @@ public class ItemTileDebug
|
|||
{
|
||||
event.getRegistry().register(new ItemBlock(TEST_BLOCK).setRegistryName(TEST_BLOCK.getRegistryName()));
|
||||
}
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(value = Side.CLIENT, modid = MODID)
|
||||
public static class BakeEventHandler
|
||||
{
|
||||
@SubscribeEvent
|
||||
public static void registerModels(ModelRegistryEvent event)
|
||||
{
|
||||
|
@ -66,52 +73,41 @@ public class ItemTileDebug
|
|||
Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(MODID, TestBlock.name));
|
||||
ForgeHooksClient.registerTESRItemStack(item, 0, CustomTileEntity.class);
|
||||
ModelLoader.setCustomModelResourceLocation(item, 0, itemLocation);
|
||||
MinecraftForge.EVENT_BUS.register(BakeEventHandler.instance);
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(CustomTileEntity.class, TestTESR.instance);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static class BakeEventHandler
|
||||
{
|
||||
public static final BakeEventHandler instance = new BakeEventHandler();
|
||||
|
||||
private BakeEventHandler()
|
||||
{
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onModelBakeEvent(ModelBakeEvent event)
|
||||
public static void onModelBakeEvent(ModelBakeEvent event)
|
||||
{
|
||||
event.getModelManager().getBlockModelShapes().registerBuiltInBlocks(TEST_BLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestTESR extends TileEntitySpecialRenderer<CustomTileEntity>
|
||||
{
|
||||
private static final TestTESR instance = new TestTESR();
|
||||
|
||||
private TestTESR()
|
||||
public static class TestTESR extends TileEntitySpecialRenderer<CustomTileEntity>
|
||||
{
|
||||
}
|
||||
private static final TestTESR instance = new TestTESR();
|
||||
|
||||
@Override
|
||||
public void render(CustomTileEntity p_180535_1_, double x, double y, double z, float p_180535_8_, int p_180535_9_, float partial)
|
||||
{
|
||||
glPushMatrix();
|
||||
glTranslated(x, y, z);
|
||||
GlStateManager.disableTexture2D();
|
||||
GlStateManager.disableLighting();
|
||||
glColor4f(.2f, 1, .1f, 1);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex3f(0, .5f, 0);
|
||||
glVertex3f(0, .5f, 1);
|
||||
glVertex3f(1, .5f, 1);
|
||||
glVertex3f(1, .5f, 0);
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
GlStateManager.enableTexture2D();
|
||||
GlStateManager.enableLighting();
|
||||
private TestTESR()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(CustomTileEntity p_180535_1_, double x, double y, double z, float p_180535_8_, int p_180535_9_, float partial)
|
||||
{
|
||||
glPushMatrix();
|
||||
glTranslated(x, y, z);
|
||||
GlStateManager.disableTexture2D();
|
||||
GlStateManager.disableLighting();
|
||||
glColor4f(.2f, 1, .1f, 1);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex3f(0, .5f, 0);
|
||||
glVertex3f(0, .5f, 1);
|
||||
glVertex3f(1, .5f, 1);
|
||||
glVertex3f(1, .5f, 0);
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
GlStateManager.enableTexture2D();
|
||||
GlStateManager.enableLighting();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,6 +60,7 @@ import net.minecraftforge.fml.common.registry.EntityRegistry;
|
|||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
@ -196,6 +197,24 @@ public class ModelAnimationDebug
|
|||
}.setRegistryName(TEST_BLOCK.getRegistryName())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract class CommonProxy
|
||||
{
|
||||
@Nullable
|
||||
public IAnimationStateMachine load(ResourceLocation location, ImmutableMap<String, ITimeValue> parameters){ return null; };
|
||||
}
|
||||
|
||||
public static class ServerProxy extends CommonProxy {}
|
||||
|
||||
@Mod.EventBusSubscriber(value = Side.CLIENT, modid = MODID)
|
||||
public static class ClientProxy extends CommonProxy
|
||||
{
|
||||
|
||||
public IAnimationStateMachine load(ResourceLocation location, ImmutableMap<String, ITimeValue> parameters)
|
||||
{
|
||||
return ModelLoaderRegistry.loadASM(location, parameters);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerModels(ModelRegistryEvent event)
|
||||
|
@ -247,24 +266,6 @@ public class ModelAnimationDebug
|
|||
}
|
||||
}
|
||||
|
||||
public static abstract class CommonProxy
|
||||
{
|
||||
@Nullable
|
||||
public IAnimationStateMachine load(ResourceLocation location, ImmutableMap<String, ITimeValue> parameters){ return null; };
|
||||
}
|
||||
|
||||
public static class ServerProxy extends CommonProxy {}
|
||||
|
||||
public static class ClientProxy extends CommonProxy
|
||||
{
|
||||
|
||||
public IAnimationStateMachine load(ResourceLocation location, ImmutableMap<String, ITimeValue> parameters)
|
||||
{
|
||||
return ModelLoaderRegistry.loadASM(location, parameters);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class ItemAnimationHolder implements ICapabilityProvider
|
||||
{
|
||||
private final VariableValue cycleLength = new VariableValue(4);
|
||||
|
|
|
@ -45,6 +45,8 @@ import net.minecraftforge.fml.common.Mod;
|
|||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
|
@ -92,7 +94,11 @@ public class ModelBakeEventDebug
|
|||
{
|
||||
event.getRegistry().register(new ItemBlock(CUSTOM_BLOCK).setRegistryName(CUSTOM_BLOCK.getRegistryName()));
|
||||
}
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(value = Side.CLIENT, modid = MODID)
|
||||
public static class BakeEventHandler
|
||||
{
|
||||
@SubscribeEvent
|
||||
public static void registerModels(ModelRegistryEvent event)
|
||||
{
|
||||
|
@ -105,20 +111,10 @@ public class ModelBakeEventDebug
|
|||
return blockLocation;
|
||||
}
|
||||
});
|
||||
MinecraftForge.EVENT_BUS.register(BakeEventHandler.instance);
|
||||
}
|
||||
}
|
||||
|
||||
public static class BakeEventHandler
|
||||
{
|
||||
public static final BakeEventHandler instance = new BakeEventHandler();
|
||||
|
||||
private BakeEventHandler()
|
||||
{
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onModelBakeEvent(ModelBakeEvent event)
|
||||
public static void onModelBakeEvent(ModelBakeEvent event)
|
||||
{
|
||||
TextureAtlasSprite base = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("minecraft:blocks/slime");
|
||||
TextureAtlasSprite overlay = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("minecraft:blocks/redstone_block");
|
||||
|
@ -126,6 +122,107 @@ public class ModelBakeEventDebug
|
|||
event.getModelRegistry().putObject(blockLocation, customModel);
|
||||
event.getModelRegistry().putObject(itemLocation, customModel);
|
||||
}
|
||||
|
||||
public static class CustomModel implements IBakedModel
|
||||
{
|
||||
private final TextureAtlasSprite base, overlay;
|
||||
//private boolean hasStateSet = false;
|
||||
|
||||
public CustomModel(TextureAtlasSprite base, TextureAtlasSprite overlay)
|
||||
{
|
||||
this.base = base;
|
||||
this.overlay = overlay;
|
||||
}
|
||||
|
||||
// TODO update to builder
|
||||
private int[] vertexToInts(float x, float y, float z, int color, TextureAtlasSprite texture, float u, float v)
|
||||
{
|
||||
return new int[]{
|
||||
Float.floatToRawIntBits(x),
|
||||
Float.floatToRawIntBits(y),
|
||||
Float.floatToRawIntBits(z),
|
||||
color,
|
||||
Float.floatToRawIntBits(texture.getInterpolatedU(u)),
|
||||
Float.floatToRawIntBits(texture.getInterpolatedV(v)),
|
||||
0
|
||||
};
|
||||
}
|
||||
|
||||
private BakedQuad createSidedBakedQuad(float x1, float x2, float z1, float z2, float y, TextureAtlasSprite texture, EnumFacing side)
|
||||
{
|
||||
Vec3d v1 = rotate(new Vec3d(x1 - .5, y - .5, z1 - .5), side).addVector(.5, .5, .5);
|
||||
Vec3d v2 = rotate(new Vec3d(x1 - .5, y - .5, z2 - .5), side).addVector(.5, .5, .5);
|
||||
Vec3d v3 = rotate(new Vec3d(x2 - .5, y - .5, z2 - .5), side).addVector(.5, .5, .5);
|
||||
Vec3d v4 = rotate(new Vec3d(x2 - .5, y - .5, z1 - .5), side).addVector(.5, .5, .5);
|
||||
return new BakedQuad(Ints.concat(
|
||||
vertexToInts((float) v1.x, (float) v1.y, (float) v1.z, -1, texture, 0, 0),
|
||||
vertexToInts((float) v2.x, (float) v2.y, (float) v2.z, -1, texture, 0, 16),
|
||||
vertexToInts((float) v3.x, (float) v3.y, (float) v3.z, -1, texture, 16, 16),
|
||||
vertexToInts((float) v4.x, (float) v4.y, (float) v4.z, -1, texture, 16, 0)
|
||||
), -1, side, texture, true, DefaultVertexFormats.BLOCK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand)
|
||||
{
|
||||
if (side != null)
|
||||
{
|
||||
return ImmutableList.of();
|
||||
}
|
||||
IExtendedBlockState exState = (IExtendedBlockState) state;
|
||||
int len = cubeSize * 5 + 1;
|
||||
List<BakedQuad> ret = new ArrayList<BakedQuad>();
|
||||
for (EnumFacing f : EnumFacing.values())
|
||||
{
|
||||
ret.add(createSidedBakedQuad(0, 1, 0, 1, 1, base, f));
|
||||
if (state != null)
|
||||
{
|
||||
for (int i = 0; i < cubeSize; i++)
|
||||
{
|
||||
for (int j = 0; j < cubeSize; j++)
|
||||
{
|
||||
Integer value = exState.getValue(properties[f.ordinal()]);
|
||||
if (value != null && (value & (1 << (i * cubeSize + j))) != 0)
|
||||
{
|
||||
ret.add(createSidedBakedQuad((float) (1 + i * 5) / len, (float) (5 + i * 5) / len, (float) (1 + j * 5) / len, (float) (5 + j * 5) / len, 1.0001f, overlay, f));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAmbientOcclusion()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltInRenderer()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleTexture()
|
||||
{
|
||||
return this.base;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemOverrideList getOverrides()
|
||||
{
|
||||
return ItemOverrideList.NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomModelBlock extends BlockContainer
|
||||
|
@ -233,107 +330,6 @@ public class ModelBakeEventDebug
|
|||
}
|
||||
}
|
||||
|
||||
public static class CustomModel implements IBakedModel
|
||||
{
|
||||
private final TextureAtlasSprite base, overlay;
|
||||
//private boolean hasStateSet = false;
|
||||
|
||||
public CustomModel(TextureAtlasSprite base, TextureAtlasSprite overlay)
|
||||
{
|
||||
this.base = base;
|
||||
this.overlay = overlay;
|
||||
}
|
||||
|
||||
// TODO update to builder
|
||||
private int[] vertexToInts(float x, float y, float z, int color, TextureAtlasSprite texture, float u, float v)
|
||||
{
|
||||
return new int[]{
|
||||
Float.floatToRawIntBits(x),
|
||||
Float.floatToRawIntBits(y),
|
||||
Float.floatToRawIntBits(z),
|
||||
color,
|
||||
Float.floatToRawIntBits(texture.getInterpolatedU(u)),
|
||||
Float.floatToRawIntBits(texture.getInterpolatedV(v)),
|
||||
0
|
||||
};
|
||||
}
|
||||
|
||||
private BakedQuad createSidedBakedQuad(float x1, float x2, float z1, float z2, float y, TextureAtlasSprite texture, EnumFacing side)
|
||||
{
|
||||
Vec3d v1 = rotate(new Vec3d(x1 - .5, y - .5, z1 - .5), side).addVector(.5, .5, .5);
|
||||
Vec3d v2 = rotate(new Vec3d(x1 - .5, y - .5, z2 - .5), side).addVector(.5, .5, .5);
|
||||
Vec3d v3 = rotate(new Vec3d(x2 - .5, y - .5, z2 - .5), side).addVector(.5, .5, .5);
|
||||
Vec3d v4 = rotate(new Vec3d(x2 - .5, y - .5, z1 - .5), side).addVector(.5, .5, .5);
|
||||
return new BakedQuad(Ints.concat(
|
||||
vertexToInts((float) v1.x, (float) v1.y, (float) v1.z, -1, texture, 0, 0),
|
||||
vertexToInts((float) v2.x, (float) v2.y, (float) v2.z, -1, texture, 0, 16),
|
||||
vertexToInts((float) v3.x, (float) v3.y, (float) v3.z, -1, texture, 16, 16),
|
||||
vertexToInts((float) v4.x, (float) v4.y, (float) v4.z, -1, texture, 16, 0)
|
||||
), -1, side, texture, true, DefaultVertexFormats.BLOCK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand)
|
||||
{
|
||||
if (side != null)
|
||||
{
|
||||
return ImmutableList.of();
|
||||
}
|
||||
IExtendedBlockState exState = (IExtendedBlockState) state;
|
||||
int len = cubeSize * 5 + 1;
|
||||
List<BakedQuad> ret = new ArrayList<BakedQuad>();
|
||||
for (EnumFacing f : EnumFacing.values())
|
||||
{
|
||||
ret.add(createSidedBakedQuad(0, 1, 0, 1, 1, base, f));
|
||||
if (state != null)
|
||||
{
|
||||
for (int i = 0; i < cubeSize; i++)
|
||||
{
|
||||
for (int j = 0; j < cubeSize; j++)
|
||||
{
|
||||
Integer value = exState.getValue(properties[f.ordinal()]);
|
||||
if (value != null && (value & (1 << (i * cubeSize + j))) != 0)
|
||||
{
|
||||
ret.add(createSidedBakedQuad((float) (1 + i * 5) / len, (float) (5 + i * 5) / len, (float) (1 + j * 5) / len, (float) (5 + j * 5) / len, 1.0001f, overlay, f));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAmbientOcclusion()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltInRenderer()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleTexture()
|
||||
{
|
||||
return this.base;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemOverrideList getOverrides()
|
||||
{
|
||||
return ItemOverrideList.NONE;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("SuspiciousNameCombination")
|
||||
private static Vec3d rotate(Vec3d vec, EnumFacing side)
|
||||
{
|
||||
|
|
|
@ -22,6 +22,7 @@ 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;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
@Mod(modid = ModelFluidDebug.MODID, name = "ForgeDebugModelFluid", version = ModelFluidDebug.VERSION, acceptableRemoteVersions = "*")
|
||||
public class ModelFluidDebug
|
||||
|
@ -85,7 +86,11 @@ public class ModelFluidDebug
|
|||
new ItemBlock(MILK_BLOCK).setRegistryName(MILK_BLOCK.getRegistryName())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(value = Side.CLIENT, modid = MODID)
|
||||
public static class ClientEventHandler
|
||||
{
|
||||
@SubscribeEvent
|
||||
public static void registerModels(ModelRegistryEvent event)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue