2018-09-13 12:03:28 -04:00
|
|
|
package noppes.npcs.client.model.util;
|
|
|
|
|
|
2023-01-12 21:33:06 -05:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2018-09-13 12:03:28 -04:00
|
|
|
import net.minecraft.client.model.ModelBase;
|
|
|
|
|
import net.minecraft.client.model.ModelRenderer;
|
|
|
|
|
import net.minecraft.client.renderer.GLAllocation;
|
|
|
|
|
import net.minecraft.client.renderer.ItemRenderer;
|
|
|
|
|
import net.minecraft.client.renderer.Tessellator;
|
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
|
|
|
|
|
public class Model2DRenderer extends ModelRenderer {
|
|
|
|
|
|
2023-11-16 15:08:25 -05:00
|
|
|
private boolean compiledModel;
|
|
|
|
|
|
|
|
|
|
private int displayListModel;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
private float x1, x2, y1, y2;
|
|
|
|
|
private int width, height;
|
|
|
|
|
private float rotationOffsetX, rotationOffsetY;
|
2023-11-16 15:08:25 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
private float scaleX = 1, scaleY = 1, thickness = 1;
|
|
|
|
|
|
|
|
|
|
public Model2DRenderer(ModelBase par1ModelBase, float x, float y, int width, int height, float textureWidth, float textureHeight) {
|
|
|
|
|
super(par1ModelBase);
|
|
|
|
|
this.width = width;
|
|
|
|
|
this.height = height;
|
|
|
|
|
this.textureWidth = textureWidth;
|
|
|
|
|
this.textureHeight = textureHeight;
|
2023-11-16 15:08:25 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
x1 = x / textureWidth;
|
|
|
|
|
y1 = y / textureHeight;
|
|
|
|
|
|
|
|
|
|
x2 = (x + width) / textureWidth;
|
|
|
|
|
y2 = (y + height) / textureHeight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Model2DRenderer(ModelBase base, int x, int y, int width, int height) {
|
|
|
|
|
this(base, x, y, width, height, width, height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void render(float par1) {
|
|
|
|
|
if(!showModel || isHidden)
|
|
|
|
|
return;
|
2023-11-16 15:08:25 -05:00
|
|
|
if(!compiledModel)
|
|
|
|
|
compileDisplayListModel(par1);
|
|
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
GL11.glPushMatrix();
|
|
|
|
|
this.postRender(par1);
|
2023-11-16 15:08:25 -05:00
|
|
|
|
|
|
|
|
GL11.glCallList(this.displayListModel);
|
2018-09-13 12:03:28 -04:00
|
|
|
GL11.glPopMatrix();
|
|
|
|
|
}
|
2023-11-16 15:08:25 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
public void setRotationOffset(float x, float y){
|
|
|
|
|
rotationOffsetX = x;
|
|
|
|
|
rotationOffsetY = y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setScale(float scale){
|
|
|
|
|
this.scaleX = scale;
|
|
|
|
|
this.scaleY = scale;
|
|
|
|
|
}
|
|
|
|
|
public void setScale(float x, float y){
|
|
|
|
|
this.scaleX = x;
|
|
|
|
|
this.scaleY = y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setThickness(float thickness) {
|
|
|
|
|
this.thickness = thickness;
|
|
|
|
|
}
|
2023-11-16 15:08:25 -05:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
private void compileDisplayListModel(float par1)
|
|
|
|
|
{
|
|
|
|
|
this.displayListModel = GLAllocation.generateDisplayLists(1);
|
|
|
|
|
GL11.glNewList(this.displayListModel, GL11.GL_COMPILE);
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
GL11.glScalef(scaleX * width / height, scaleY, thickness);
|
2023-11-16 15:08:25 -05:00
|
|
|
GL11.glRotatef(180, 1F, 0F, 0F);
|
|
|
|
|
if(mirror){
|
|
|
|
|
GL11.glTranslatef(0, 0, -1f * par1);
|
|
|
|
|
GL11.glRotatef(180, 0, 1F, 0F);
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
GL11.glTranslated( rotationOffsetX * par1, rotationOffsetY * par1, 0);
|
|
|
|
|
ItemRenderer.renderItemIn2D(Tessellator.instance, x1, y1, x2, y2, width, height, par1);
|
|
|
|
|
|
2023-11-16 15:08:25 -05:00
|
|
|
GL11.glEndList();
|
|
|
|
|
this.compiledModel = true;
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|