Commit fc333910 authored by mrAppleXZ's avatar mrAppleXZ 💾

Stone Crusher rope, TESRs refactoring

parent 8d0fb5de
......@@ -31,11 +31,9 @@ public class TESRCodeStorage extends PXLFastTESR<TileCodeStorage>
return;
GlStateManager.pushMatrix();
resetTrans(te);
GlStateManager.translate(0.5f, 0, 0.5f);
GlStateManager.rotate(PXLMC.getHorizontalRotation(st.getValue(HorizontalFacingController.FACING_H)), 0, 1, 0);
GlStateManager.translate(-0.5f, 0, -0.5f);
setTrans(te);
long rnd = MathHelper.getPositionRandom(te.getPos());
......@@ -49,7 +47,6 @@ public class TESRCodeStorage extends PXLFastTESR<TileCodeStorage>
String state = te.anim.getElement("head").getState();
if(!state.equals("closed"))
{
resetTrans(te);
GlStateManager.translate(0.5f, 0, 0.5f);
GlStateManager.translate(0, 0.703f, 0.4457f);
......@@ -74,7 +71,6 @@ public class TESRCodeStorage extends PXLFastTESR<TileCodeStorage>
GlStateManager.translate(0, -0.703f, -0.4457f);
GlStateManager.translate(-0.5f, 0, -0.5f);
setTrans(te);
}
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
PXLModelRenderer.renderModelTESR(te.getWorld(), TOP.get(), st.getBlock().getExtendedState(st, te.getWorld(), te.getPos()), te.getPos(), buffer, false, rnd);
......
......@@ -22,7 +22,6 @@ public class TESRMagibench extends PXLFastTESR<TileMagibench>
@Override
public void render(TileMagibench te, double x, double y, double z, float partialTicks, int destroyStage, float alpha, BufferBuilder buffer, Tessellator tes)
{
resetTrans(te);
//todo add floating items support
MagibenchRegistry.Tier t = PurMag.INSTANCE.getMagibenchRegistry().getTier(te.getTier());
int index = 0;
......@@ -56,6 +55,5 @@ public class TESRMagibench extends PXLFastTESR<TileMagibench>
}
}
GlStateManager.popMatrix();
setTrans(te);
}
}
......@@ -30,7 +30,6 @@ public class TESRMicroscope extends PXLFastTESR<TileMicroscope>
if (!stack.isEmpty())
{
GlStateManager.pushMatrix();
resetTrans(te);
GlStateManager.translate(0.5f, 0, 0.5f);
GlStateManager.rotate(PXLMC.getHorizontalRotation(state.getValue(HorizontalFacingController.FACING_H)), 0, 1, 0);
GlStateManager.rotate(180, 0, 1, 0);
......
package ru.pearx.purmag.client.tesrs;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.ResourceLocation;
......@@ -9,11 +11,13 @@ import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.opengl.GL11;
import ru.pearx.lib.Color;
import ru.pearx.lib.Colors;
import ru.pearx.lib.math.MathUtils;
import ru.pearx.libmc.PXLMC;
import ru.pearx.libmc.client.ModelSupplied;
import ru.pearx.libmc.client.PXLFastTESR;
import ru.pearx.libmc.client.TESRMultiblock;
import ru.pearx.libmc.client.gui.controls.common.BlockArrayShowcase;
import ru.pearx.libmc.client.models.PXLModelRenderer;
import ru.pearx.purmag.common.Utils;
import ru.pearx.purmag.common.tiles.TileStoneCrusher;
......@@ -34,65 +38,116 @@ public class TESRStoneCrusher extends TESRMultiblock<TileStoneCrusher>
public void render(TileStoneCrusher te, double x, double y, double z, float partialTicks, int destroyStage, float alpha, BufferBuilder buffer, Tessellator tes)
{
GlStateManager.pushMatrix();
resetTrans(te);
GlStateManager.translate(0.5f, 0, 0.5f);
GlStateManager.rotate(PXLMC.getHorizontalRotation(te.getRotation()), 0, 1, 0);
GlStateManager.translate(-0.5f, 0, -0.5f);
setTrans(te);
int deg = (int)(System.currentTimeMillis() / 2 % 360);
//main part
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
PXLModelRenderer.renderModelTESR(te.getWorld(), MDL_MAIN.get(), te.getWorld().getBlockState(te.getPos()), te.getPos(), buffer, false, MathHelper.getPositionRandom(te.getPos()));
tes.draw();
//lever
GlStateManager.pushMatrix();
resetTrans(te);
GlStateManager.translate(-0.23964f, -0.034445f, -0.211711f);
GlStateManager.rotate(-deg, 0, 0, 1);
GlStateManager.rotate(-29, 0, 0, 1);
GlStateManager.translate(0.23964f, 0.034445f, 0.211711f);
setTrans(te);
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
PXLModelRenderer.renderModelTESR(te.getWorld(), MDL_LEVER.get(), te.getWorld().getBlockState(te.getPos()), te.getPos(), buffer, false, MathHelper.getPositionRandom(te.getPos()));
tes.draw();
GlStateManager.popMatrix();
long timeDelta = te.getWorld().getTotalWorldTime() - te.getPreviousSpin();
float deltaCooldown = (float) timeDelta / te.getCooldownBetweenSpins();
{
long timeDelta = te.getWorld().getTotalWorldTime() - te.getPreviousSpin();
float rot = timeDelta > te.getCooldownBetweenSpins() ? te.getSpins() * 90 : (te.getSpins() - 1) * 90 + timeDelta * (90f / te.getCooldownBetweenSpins());
float rot = te.getSpins() * 90 + (timeDelta > te.getCooldownBetweenSpins() ? 0 : -90 + 90 * deltaCooldown);
//handle
GlStateManager.pushMatrix();
resetTrans(te);
GlStateManager.translate(0.5, 0.5, 0);
GlStateManager.rotate(rot, 0, 0, 1);
GlStateManager.translate(-0.5, -0.5, 0);
setTrans(te);
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
PXLModelRenderer.renderModelTESR(te.getWorld(), MDL_HANDLE.get(), te.getWorld().getBlockState(te.getPos()), te.getPos(), buffer, false, MathHelper.getPositionRandom(te.getPos()));
tes.draw();
GlStateManager.popMatrix();
//coil
GlStateManager.pushMatrix();
resetTrans(te);
GlStateManager.translate(0.5, 0.5, -0.5);
GlStateManager.rotate(rot, 0, 0, 1);
GlStateManager.translate(-0.5, -0.5, 0.5);
setTrans(te);
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
PXLModelRenderer.renderModelTESR(te.getWorld(), MDL_COIL.get(), te.getWorld().getBlockState(te.getPos()), te.getPos(), buffer, false, MathHelper.getPositionRandom(te.getPos()));
tes.draw();
GlStateManager.popMatrix();
}
GlStateManager.pushMatrix();
float anvilY = (float)te.getSpins() / te.getMaxSpins();
boolean onGround = te.getSpins() <= 0;
float anvilXMod = onGround ? 0 : MathHelper.sin(MathUtils.toRadians((System.currentTimeMillis() / 10) % 360)) * 0.2f * (1 - anvilY);
GlStateManager.translate(1 + anvilXMod, anvilY, 0);
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModel(te.getWorld(), MDL_ANVIL.get(), te.getWorld().getBlockState(te.getPos()), te.getPos(), buffer, false, MathHelper.getPositionRandom(te.getPos()));
tes.draw();
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
tes.draw();
GlStateManager.popMatrix();
{
float os = 1f / te.getMaxSpins();
boolean onGround = te.getSpins() <= 0;
float anvilX = 1;
float anvilY = te.getSpins() * os + (timeDelta > te.getCooldownBetweenSpins() ? 0 : -os + os * deltaCooldown);
if (!onGround)
{
float sin = MathHelper.sin(MathUtils.toRadians((System.currentTimeMillis() / 8) % 360));
anvilX += sin * 0.2f * (1 - anvilY);
anvilY += Math.abs(sin) * 0.05f * (1 - anvilY);
}
//anvil
GlStateManager.pushMatrix();
GlStateManager.translate(anvilX, anvilY, 0);
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
setTrans(buffer, te);
Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModel(te.getWorld(), MDL_ANVIL.get(), te.getWorld().getBlockState(te.getPos()), te.getPos(), buffer, false, MathHelper.getPositionRandom(te.getPos()));
buffer.setTranslation(0, 0, 0);
tes.draw();
GlStateManager.popMatrix();
{
//rope
float width = 0.05f;
Color c = Colors.BROWN_800;
int r = c.getRed();
int g = c.getGreen();
int b = c.getBlue();
int a = c.getAlpha();
float x0 = 1.5f + width / 2, x1 = 1.5f - width / 2, x2 = anvilX + 0.5f - width / 2, x3 = anvilX + 0.5f + width / 2;
float y0 = 2.74f, y1 = anvilY + 1f;
float z0 = 0.5f - width / 2, z1 = 0.5f + width / 2;
GlStateManager.disableTexture2D();
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
buffer.pos(x0, y0, z0).color(r, g, b, a).endVertex();
buffer.pos(x1, y0, z0).color(r, g, b, a).endVertex();
buffer.pos(x2, y1, z0).color(r, g, b, a).endVertex();
buffer.pos(x3, y1, z0).color(r, g, b, a).endVertex();
buffer.pos(x0, y0, z1).color(r, g, b, a).endVertex();
buffer.pos(x1, y0, z1).color(r, g, b, a).endVertex();
buffer.pos(x2, y1, z1).color(r, g, b, a).endVertex();
buffer.pos(x3, y1, z1).color(r, g, b, a).endVertex();
buffer.pos(x0, y0, z0).color(r, g, b, a).endVertex();
buffer.pos(x0, y0, z1).color(r, g, b, a).endVertex();
buffer.pos(x2, y1, z1).color(r, g, b, a).endVertex();
buffer.pos(x2, y1, z0).color(r, g, b, a).endVertex();
buffer.pos(x1, y0, z0).color(r, g, b, a).endVertex();
buffer.pos(x1, y0, z1).color(r, g, b, a).endVertex();
buffer.pos(x3, y1, z1).color(r, g, b, a).endVertex();
buffer.pos(x3, y1, z0).color(r, g, b, a).endVertex();
buffer.pos(x0, y0, z0).color(r, g, b, a).endVertex();
buffer.pos(x0, y0, z1).color(r, g, b, a).endVertex();
buffer.pos(x1, y0, z1).color(r, g, b, a).endVertex();
buffer.pos(x1, y0, z0).color(r, g, b, a).endVertex();
tes.draw();
GlStateManager.enableTexture2D();
}
}
GlStateManager.popMatrix();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment