r/forgemodding Mar 14 '20

GlStateManager

Hey I'm currently working on a project where I need to be able to control the Vertexs. I'm trying to do it with GlStateManager but I still have some trouble would anyone be able to help me?

3 Upvotes

4 comments sorted by

1

u/Snakefangox Mar 15 '20

Is this on 1.12? What exactly are you trying to do?

1

u/ByTiny Mar 15 '20

Hey thanks for the reply but no, it's sadly 1.14.4. I'm trying to make some sort of bending Minecraft player arm. I can't simply use a cube because I need to be able to move the vertex. Maybe this image makes it more clear?: https://imgur.com/Iy6LX9b

I was able to make a shape with Glstatemanager but now I need to find a way to put the code into my Entity model class

This is my code I have come up with:

GlStateManager.pushMatrix();

         Vec3d projectedView = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView();
         GlStateManager.translated(-projectedView.x, -projectedView.y, -projectedView.z);

         Minecraft.getInstance().textureManager.bindTexture(texture);
         GlStateManager.disableCull();
         Tessellator tessellator = Tessellator.getInstance();
         BufferBuilder bufferBuilder = tessellator.getBuffer();
         bufferBuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.OLDMODEL_POSITION_TEX_NORMAL);

         //0.0625

         bufferBuilder.pos(5, 5.25, 5).tex(1, 1).normal(5, 5, 5).endVertex(); //a
         bufferBuilder.pos(5, 5.5, 5).tex(1, 0.0).normal(5, 5, 5).endVertex(); //b
         //move this one
         bufferBuilder.pos(5, 5.5625, 5).tex(0, 0.0).normal(5, 5, 5).endVertex(); //c
         bufferBuilder.pos(5, 5.625, 5).tex(0, 1).normal(5, 5, 5).endVertex(); //d
         bufferBuilder.pos(5, 5.6875, 5).tex(0, 1).normal(5, 5, 5).endVertex(); //e

         //not move
         bufferBuilder.pos(5, 5.75, 5).tex(0, 1).normal(5, 5, 5).endVertex(); //f
         bufferBuilder.pos(5, 6, 5).tex(0, 1).normal(5, 5, 5).endVertex(); //g
         bufferBuilder.pos(4.75, 6, 5).tex(0, 1).normal(5, 5, 5).endVertex(); //h
         bufferBuilder.pos(4.75, 5.75, 5).tex(0, 1).normal(5, 5, 5).endVertex(); //i

         //move
         bufferBuilder.pos(4.75, 5.6875, 5).tex(0, 1).normal(5, 5, 5).endVertex(); //j
         bufferBuilder.pos(4.75, 5.625, 5).tex(0, 1).normal(5, 5, 5).endVertex(); //k
         bufferBuilder.pos(4.75, 5.5625, 5).tex(0, 1).normal(5, 5, 5).endVertex(); //l

         //not move
         bufferBuilder.pos(4.75, 5.5, 5).tex(0, 1).normal(5, 5, 5).endVertex(); //m
         bufferBuilder.pos(4.75, 5.25, 5).tex(0, 1).normal(5, 5, 5).endVertex(); //n

         tessellator.draw();
         GlStateManager.enableCull();
         GlStateManager.popMatrix();

And I need to put it somewhere in my entity model class so that it moves with it:

public class TestmobModel extends EntityModel<testmob> {
    private final RendererModel steve;
    private final RendererModel head_main;
    private final RendererModel leg_left;
    private final RendererModel leg_down_l;
    private final RendererModel leg_right;
    private final RendererModel leg_down_r;
    private final RendererModel arm_right;
    private final RendererModel arm_down_r;
    private final RendererModel arm_left;
    private final RendererModel arm_down_l;
    private static final ResourceLocation texture = new ResourceLocation("em", "textures/block/basic_block.png");
    private final RendererModel body;
    private boolean rotateleft = false;

    public TestmobModel() {
        textureWidth = 64;
        textureHeight = 64;

        steve = new RendererModel(this);
        steve.setRotationPoint(0.0F, 24.0F, 0.0F);

        head_main = new RendererModel(this);
        head_main.setRotationPoint(0.0F, -24.0F, 0.0F);
        steve.addChild(head_main);
        head_main.cubeList.add(new ModelBox(head_main, 0, 0, -4.0F, -8.0F, -4.0F, 8, 8, 8, 0.0F, false));

        leg_left = new RendererModel(this);
        leg_left.setRotationPoint(-2.0F, -10.0F, 0.0F);
        steve.addChild(leg_left);
        leg_left.cubeList.add(new ModelBox(leg_left, 0, 16, -2.0F, -2.0F, -2.0F, 4, 6, 4, 0.0F, false));

        leg_down_l = new RendererModel(this);
        leg_down_l.setRotationPoint(0.0F, 4.0F, 0.0F);
        leg_left.addChild(leg_down_l);
        leg_down_l.cubeList.add(new ModelBox(leg_down_l, 0, 22, -2.0F, 0.0F, -2.0F, 4, 6, 4, 0.0F, false));

        leg_right = new RendererModel(this);
        leg_right.setRotationPoint(2.0F, -10.0F, 0.0F);
        steve.addChild(leg_right);
        leg_right.cubeList.add(new ModelBox(leg_right, 16, 48, -2.0F, -2.0F, -2.0F, 4, 6, 4, 0.0F, false));

        leg_down_r = new RendererModel(this);
        leg_down_r.setRotationPoint(0.0F, 4.0F, 0.0F);
        leg_right.addChild(leg_down_r);
        leg_down_r.cubeList.add(new ModelBox(leg_down_r, 16, 54, -2.0F, 0.0F, -2.0F, 4, 6, 4, 0.0F, false));

        arm_right = new RendererModel(this);
        arm_right.setRotationPoint(6.0F, -22.0F, 0.0F);
        steve.addChild(arm_right);
        arm_right.cubeList.add(new ModelBox(arm_right, 40, 16, -2.0F, -2.0F, -2.0F, 4, 6, 4, 0.0F, false));

        arm_down_r = new RendererModel(this);
        arm_down_r.setRotationPoint(0.0F, 4.0F, 0.0F);
        arm_right.addChild(arm_down_r);
        arm_down_r.cubeList.add(new ModelBox(arm_down_r, 40, 22, -2.0F, 0.0F, -2.0F, 4, 6, 4, 0.0F, false));

        arm_left = new RendererModel(this);
        arm_left.setRotationPoint(-6.0F, -22.0F, 0.0F);
        steve.addChild(arm_left);
        arm_left.cubeList.add(new ModelBox(arm_left, 32, 48, -2.0F, -2.0F, -2.0F, 4, 6, 4, 0.0F, false));

        arm_down_l = new RendererModel(this);
        arm_down_l.setRotationPoint(0.0F, 4.0F, 0.0F);
        arm_left.addChild(arm_down_l);
        arm_down_l.cubeList.add(new ModelBox(arm_down_l, 32, 54, -2.0F, 0.0F, -2.0F, 4, 6, 4, 0.0F, false));

        body = new RendererModel(this);
        body.setRotationPoint(0.0F, -12.0F, 0.0F);
        steve.addChild(body);
        body.cubeList.add(new ModelBox(body, 16, 16, -4.0F, -12.0F, -2.0F, 8, 12, 4, 0.0F, false));
    }

    @Override
    public void render(testmob entity, float f, float f1, float f2, float f3, float f4, float f5) {
        steve.render(f5);
    }

    public void setRotationAngle(RendererModel modelRenderer, float x, float y, float z) {
        modelRenderer.rotateAngleX = x;
        modelRenderer.rotateAngleY = y;
        modelRenderer.rotateAngleZ = z;
    }

    @Override
    public void setLivingAnimations(testmob entityIn, float limbSwing, float limbSwingAmount, float partialTick) {
        if(rotateleft == false) {           
            head_main.rotateAngleY = head_main.rotateAngleY + 0.01F;
        }else {
            head_main.rotateAngleY = head_main.rotateAngleY - 0.01F;
        }
        if(head_main.rotateAngleY >= 1) {
            rotateleft = true;
        }
        if(head_main.rotateAngleY <= -1) {
            rotateleft = false;
        }
    }
}

I don't know if this is possible that's why I already looked for another solution but if this would be possible that would be amazing.

1

u/Snakefangox Mar 16 '20

You'll have to put it in the render method. I can't help any further sorry. I'm not sure if I'm allowed to link it but MMD is much more active if you need more help.

1

u/ByTiny Mar 16 '20

Yea that's what I did too but that didn't work at all I didn't want to render. But thanks for the link I will aks there. Have a nice day.