Created
February 7, 2015 22:52
-
-
Save Ivorforce/373f4a9c547312ca38b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (c) 2014, Lukas Tenbrink. | |
* http://lukas.axxim.net | |
*/ | |
package ivorius.pandorasbox.client; | |
import com.google.common.base.Function; | |
import com.google.common.base.Functions; | |
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.model.ModelBase; | |
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.DefaultVertexFormats; | |
import net.minecraft.client.renderer.vertex.VertexFormat; | |
import net.minecraft.entity.Entity; | |
import net.minecraft.entity.projectile.EntityArrow; | |
import net.minecraft.util.MathHelper; | |
import net.minecraft.util.ResourceLocation; | |
import net.minecraftforge.client.model.*; | |
import net.minecraftforge.client.model.b3d.B3DModel; | |
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 ResourceLocation texture; | |
public RenderPandorasBox(RenderManager renderManager) | |
{ | |
super(renderManager); | |
model = ModelLoaderRegistry.getModel(new ResourceLocation(PandorasBox.MODID, "block/pandoras_box.b3d")); | |
texture = new ResourceLocation(PandorasBox.MODID, PandorasBox.filePathTextures + "pbTexture.png"); | |
} | |
@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 texture; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment