Jump to content

Recommended Posts

Posted

I currently have a scarecrow model which I would like to Render as a block.

The scarecrow is two blocks high.

But it doesn't show it's texture and it also renders like into the ground and not into the air.

 

width=800 height=428http://i252.photobucket.com/albums/hh24/Raycoms/2016-08-19_08.32.55_zpsdytiqsog.png[/img]

public class ModelScarecrowBoth extends ModelBase
{
    //fields
    ModelRenderer Head;
    ModelRenderer Post;
    ModelRenderer LeftArmPeg;
    ModelRenderer RightArmPeg;
    ModelRenderer Torso;
    ModelRenderer RightLegPeg;
    ModelRenderer LeftLegPeg;
    ModelRenderer LeftArm;
    ModelRenderer RightArm;
    ModelRenderer RightLeg;
    ModelRenderer LeftLeg;
    
    public ModelScarecrowBoth()
    {
        textureWidth = 128;
        textureHeight = 64;
        
        Head = new ModelRenderer(this, 0, 0);
        Head.addBox(-8.2F, -35.6F, -4.2F, 8, 8, ;
        Head.setRotationPoint(7F, 24F, -1F);
        Head.setTextureSize(128, 64);
        Head.mirror = true;
        setRotation(Head, 0F, 0.1858931F, -0.1092638F);
        Post = new ModelRenderer(this, 0, 32);
        Post.addBox(-1F, -16F, -1F, 2, 16, 2);
        Post.setRotationPoint(0F, 24F, 0F);
        Post.setTextureSize(128, 64);
        Post.mirror = true;
        setRotation(Post, 0F, 0F, 0F);
        LeftArmPeg = new ModelRenderer(this, 9, 33);
        LeftArmPeg.addBox(23.5F, 1F, -1F, 2, 2, 2);
        LeftArmPeg.setRotationPoint(7F, 24F, 0F);
        LeftArmPeg.setTextureSize(128, 64);
        LeftArmPeg.mirror = true;
        setRotation(LeftArmPeg, 0F, 0F, -1.351339F);
        RightArmPeg = new ModelRenderer(this, 9, 33);
        RightArmPeg.addBox(-28F, 15.8F, -1F, 2, 2, 2);
        RightArmPeg.setRotationPoint(7F, 24F, 0F);
        RightArmPeg.setTextureSize(128, 64);
        RightArmPeg.mirror = true;
        setRotation(RightArmPeg, 0F, 0F, 1.351339F);
        Torso = new ModelRenderer(this, 16, 16);
        Torso.addBox(-10.3F, -27.6F, -2F, 8, 12, 4);
        Torso.setRotationPoint(7F, 24F, 0F);
        Torso.setTextureSize(128, 64);
        Torso.mirror = true;
        setRotation(Torso, 0F, 0F, -0.0349066F);
        RightLegPeg = new ModelRenderer(this, 9, 33);
        RightLegPeg.addBox(-11F, -4F, -1F, 2, 2, 2);
        RightLegPeg.setRotationPoint(7F, 24F, 0F);
        RightLegPeg.setTextureSize(128, 64);
        RightLegPeg.mirror = true;
        setRotation(RightLegPeg, 0F, 0F, 0.0872665F);
        LeftLegPeg = new ModelRenderer(this, 9, 33);
        LeftLegPeg.addBox(-4.5F, -5F, -1F, 2, 2, 2);
        LeftLegPeg.setRotationPoint(7F, 24F, 0F);
        LeftLegPeg.setTextureSize(128, 64);
        LeftLegPeg.mirror = true;
        setRotation(LeftLegPeg, 0F, 0F, -0.0872665F);
        LeftArm = new ModelRenderer(this, 40, 16);
        LeftArm.addBox(22.5F, -10F, -1.99F, 4, 12, 4);
        LeftArm.setRotationPoint(7F, 24F, 0F);
        LeftArm.setTextureSize(128, 64);
        LeftArm.mirror = true;
        setRotation(LeftArm, 0F, 0F, -1.351339F);
        RightArm = new ModelRenderer(this, 40, 16);
        RightArm.addBox(-29F, 4.8F, -1.99F, 4, 12, 4);
        RightArm.setRotationPoint(7F, 24F, 0F);
        RightArm.setTextureSize(128, 64);
        RightArm.mirror = true;
        setRotation(RightArm, 0F, 0F, 1.351339F);
        RightLeg = new ModelRenderer(this, 0, 16);
        RightLeg.addBox(-12F, -15F, -1.99F, 4, 12, 4);
        RightLeg.setRotationPoint(7F, 24F, 0F);
        RightLeg.setTextureSize(128, 64);
        RightLeg.mirror = true;
        setRotation(RightLeg, 0F, 0F, 0.0872665F);
        LeftLeg = new ModelRenderer(this, 0, 16);
        LeftLeg.addBox(-5.5F, -16F, -1.98F, 4, 12, 4);
        LeftLeg.setRotationPoint(7F, 24F, 0F);
        LeftLeg.setTextureSize(128, 64);
        LeftLeg.mirror = true;
        setRotation(LeftLeg, 0F, 0F, -0.0872665F);
    }
    
    public void render(float scaleFactor)
    {
        Head.render(scaleFactor);
        Post.render(scaleFactor);
        LeftArmPeg.render(scaleFactor);
        RightArmPeg.render(scaleFactor);
        Torso.render(scaleFactor);
        RightLegPeg.render(scaleFactor);
        LeftLegPeg.render(scaleFactor);
        LeftArm.render(scaleFactor);
        RightArm.render(scaleFactor);
        RightLeg.render(scaleFactor);
        LeftLeg.render(scaleFactor);
    }
    
    private void setRotation(ModelRenderer model, float x, float y, float z)
    {
        model.rotateAngleX = x;
        model.rotateAngleY = y;
        model.rotateAngleZ = z;
    }
}

 

I also have a tileEntitySpecialRenderer

 

@SideOnly(Side.CLIENT)
public class TileEntityScarecrowRenderer extends TileEntitySpecialRenderer<ScarecrowTileEntity>
{
    private final ModelScarecrowBoth model;

    public TileEntityScarecrowRenderer() { 
        this.model = new ModelScarecrowBoth();
    }
    
    @Override
    public void renderTileEntityAt(ScarecrowTileEntity te, double posX, double posY, double posZ, float partialTicks, int destroyStage) {
        GlStateManager.pushMatrix(); // store the transformation 
        GlStateManager.translate(posX, posY, posZ); // set viewport to tile entity position to render it
        
        /* ============ Rendering Code goes here ============ */
        EnumFacing facing = te.getWorld().getBlockState(te.getPos()).getValue(BlockHutField.FACING);
        
        this.bindTexture(this.getResourceLocation(te));
        GlStateManager.rotate(180, te.getPos().getX(), te.getPos().getY(), te.getPos().getZ());
        this.model.render(.0625f);
        
        /* ============ Rendering Code stops here =========== */
        
        GlStateManager.popMatrix(); // restore the transformation, so other renderer's are not messed up
    }
    
    private ResourceLocation getResourceLocation(ScarecrowTileEntity tileentity) { 
        String loc;
        
        if(tileentity.getType())
            loc = "/resources/assets/minecolonies/textures/blocks/blockScarecrowPumpkin.png";
        else
            loc = "/resources/assets/minecolonies/textures/blocks/blockScarecrowNormal.png";
        
        return new ResourceLocation(Constants.MOD_ID + ":" + loc);
    }
}

 

I don't have any json files, are they necessary? How do I generate them?

 

 

 

 

Posted

When you call translate add 1 or .5, and in the block class override isOpaqueCube() to false and getRenderType() to -1

You should use the new model system as TESRs should be for dynamic rendering.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

I would recommend checking out MrCrayfish's Model Creator (assuming you're in 1.8+). It does mean you have to remake the model in that software instead, but what it does is generate a json file for you. This means you don't need a TileEntity and you don't get that pink and black box.

IGN: matte006

Played Minecraft since summer 2011.

Modding is my life now.

Please check out my mod :)

https://minecraft.curseforge.com/projects/gadgets-n-goodies-mod?gameCategorySlug=mc-mods&projectID=230028

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello all. I'm currently grappling with the updateShape method in a custom class extending Block.  My code currently looks like this: The conditionals in CheckState are there to switch blockstate properties, which is working fine, as it functions correctly every time in getStateForPlacement.  The problem I'm running into is that when I update a state, the blocks seem to call CheckState with the position of the block which was changed updated last.  If I build a wall I can see the same change propagate across. My question thus is this: is updateShape sending its return to the neighbouring block?  Is each block not independently executing the updateShape method, thus inserting its own current position?  The first statement appears to be true, and the second false (each block is not independently executing the method). I have tried to fix this by saving the block's own position to a variable myPos at inception, and then feeding this in as CheckState(myPos) but this causes a worse outcome, where all blocks take the update of the first modified block, rather than just their neighbour.  This raises more questions than it answers, obviously: how is a different instance's variable propagating here?  I also tried changing it so that CheckState did not take a BlockPos, but had myPos built into the body - same problem. I have previously looked at neighbourUpdate and onNeighbourUpdate, but could not find a way to get this to work at all.  One post on here about updatePostPlacement and other methods has proven itself long superceded.  All other sources on the net seem to be out of date. Many thanks in advance for any help you might offer me, it's been several days now of trying to get this work and several weeks of generally trying to get round this roadblock.  - Sandermall
    • sorry, I might be stupid, but how do I open it? because the only options I have are too X out, copy it, which doesn't work and send crash report, which doesn't show it to me, also, sorry for taking so long.
    • Can you reproduce this with version 55.0.21? A whole lot of plant placement issues were just fixed in this PR.
    • Necro'ing that thread to ask if you found a solution ? I'm encountering the same crash on loading the world. I created the world in Creative to test my MP, went into survival to test combat, died, crashed on respawn and since then crash on loading the world. Deactivating Oculus isn't fixing it either, and I don't have Optifine (Twilight forest is incompatible)
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.