Skip to content

Instantly share code, notes, and snippets.

@Ivorforce
Created February 7, 2015 22:54
Show Gist options
  • Save Ivorforce/50e72627a5beecfab0fd to your computer and use it in GitHub Desktop.
Save Ivorforce/50e72627a5beecfab0fd to your computer and use it in GitHub Desktop.
/*
* Copyright (c) 2014, Lukas Tenbrink.
* http://lukas.axxim.net
*/
package ivorius.pandorasbox.client;
import com.google.common.base.Function;
import ivorius.pandorasbox.PandorasBox;
import ivorius.pandorasbox.client.rendering.effects.PBEffectRenderer;
import ivorius.pandorasbox.client.rendering.effects.PBEffectRenderingRegistry;
import ivorius.pandorasbox.effects.PBEffect;
import ivorius.pandorasbox.entitites.EntityPandorasBox;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.entity.Entity;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.*;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.opengl.GL11;
import javax.annotation.Nullable;
/**
* Created by lukas on 30.03.14.
*/
@SideOnly(Side.CLIENT)
public class RenderPandorasBox extends Render
{
public IModel model;
public RenderPandorasBox(RenderManager renderManager)
{
super(renderManager);
model = ModelLoaderRegistry.getModel(new ResourceLocation(PandorasBox.MODID, "block/pandoras_box.b3d"));
}
@Override
public void doRender(Entity entity, double x, double y, double z, float yaw, float partialTicks)
{
EntityPandorasBox entityPandorasBox = (EntityPandorasBox) entity;
GL11.glPushMatrix();
GL11.glTranslated(x, y + MathHelper.sin((entity.ticksExisted + partialTicks) * 0.04f) * 0.05, z);
GL11.glRotatef(-yaw, 0.0F, 1.0F, 0.0F);
PBEffect effect = entityPandorasBox.getBoxEffect();
if (!effect.isDone(entityPandorasBox, entityPandorasBox.getEffectTicksExisted()) && entityPandorasBox.getDeathTicks() < 0)
{
PBEffectRenderer renderer = PBEffectRenderingRegistry.rendererForEffect(effect);
if (renderer != null)
renderer.renderBox(entityPandorasBox, effect, partialTicks);
}
if (!entity.isInvisible())
{
float boxScale = entityPandorasBox.getCurrentScale();
if (boxScale < 1.0f)
GL11.glScalef(boxScale, boxScale, boxScale);
// GL11.glTranslatef(0.0f, 1.5f, 0.0f);
// GL11.glRotatef(180.0f, 0.0f, 0.0f, 1.0f);
renderModel(model, model.getDefaultState());
}
GL11.glPopMatrix();
}
public void renderModel(IModel model, IModelState state)
{
final TextureMap textureMapBlocks = Minecraft.getMinecraft().getTextureMapBlocks();
VertexFormat vFormat = Attributes.DEFAULT_BAKED_FORMAT;
IFlexibleBakedModel bakedModel = model.bake(state, vFormat, new Function<ResourceLocation, TextureAtlasSprite>()
{
@Nullable
@Override
public TextureAtlasSprite apply(@Nullable ResourceLocation input)
{
if (input == null)
return textureMapBlocks.func_174942_a(TextureMap.field_174945_f);
return textureMapBlocks.func_174942_a(input);
}
});
bindTexture(TextureMap.locationBlocksTexture);
WorldRenderer worldRenderer = Tessellator.getInstance().getWorldRenderer();
worldRenderer.startDrawingQuads();
worldRenderer.setVertexFormat(vFormat);
worldRenderer.markDirty();
for (BakedQuad quad : bakedModel.func_177550_a())
worldRenderer.func_178981_a(quad.func_178209_a());
worldRenderer.draw();
}
@Override
protected ResourceLocation getEntityTexture(Entity var1)
{
return TextureMap.field_174945_f;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment