Skip to content

Instantly share code, notes, and snippets.

@StillManic
Created March 21, 2016 06:41
Show Gist options
  • Save StillManic/3994b129b04f669db961 to your computer and use it in GitHub Desktop.
Save StillManic/3994b129b04f669db961 to your computer and use it in GitHub Desktop.
public static class RenderBus extends Render<EntityBus>
{
private static IBakedModel bakedModel = null;
private static final ResourceLocation loc = new ResourceLocation(TestBus.MODID.toLowerCase() + ":item/olympian1.obj"/* ":item/group_test.obj"*/);
public RenderBus(RenderManager manager)
{
super(manager);
}
public static void init()
{
IResourceManager manager = Minecraft.getMinecraft().getResourceManager();
if (manager instanceof IReloadableResourceManager)
{
((IReloadableResourceManager) manager).registerReloadListener(new IResourceManagerReloadListener()
{
@Override
public void onResourceManagerReload(IResourceManager resourceManager)
{
bakedModel = null;
}
});
}
}
@Override
public void doRender(EntityBus bus, double x, double y, double z, float yaw, float partialTicks)
{
if (bakedModel == null)
{
FMLLog.info("Attempting to load model '%s'", loc.toString());
try
{
IModel model = ModelLoaderRegistry.getModel(loc);
if (model != null && model instanceof OBJModel)
{
FMLLog.info("Successfully obtained model '%s' from registry", loc.toString());
bakedModel = ((OBJModel) model).bake(model.getDefaultState(), Attributes.DEFAULT_BAKED_FORMAT, ModelLoader.defaultTextureGetter());
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
else if (bakedModel != null)
{
bindTexture(TextureMap.locationBlocksTexture);
Tessellator tessellator = Tessellator.getInstance();
VertexBuffer buffer = tessellator.getBuffer();
WorldRenderer buffer = tessellator.getWorldRenderer();
GlStateManager.disableLighting();
GlStateManager.disableRescaleNormal();
GlStateManager.enableDepth();
GlStateManager.depthMask(true);
GlStateManager.enableAlpha();
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.pushMatrix();
GlStateManager.translate(x, y, z);
GlStateManager.rotate(yaw, 0, 1, 0);
GlStateManager.pushMatrix();
GlStateManager.translate(-0.625f, 0, 1);
buffer.begin(GL11.GL_QUADS, Attributes.DEFAULT_BAKED_FORMAT);
// for (BakedQuad quad : bakedModel.getQuads(null, null, 0))
for (BakedQuad quad : bakedModel.getGeneralQuads())
{
LightUtil.renderQuadColor(buffer, quad, 0xFFFFFFFF);
}
tessellator.draw();
GlStateManager.popMatrix();
GlStateManager.popMatrix();
}
}
@Override
public ResourceLocation getEntityTexture(EntityBus bus)
{
return TextureMap.locationBlocksTexture;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment