Jump to content

[1.7.10][SOLVED]Rotate tileentity model


TheCreepySheep

Recommended Posts

Hello,

 

I have a tile entity with custom model done in Techne. I have everything else working quite good, but I want to be able to place it in different directions. I have my TESR copy-modifyed from http://www.minecraftforge.net/wiki/Rendering_a_Techne_Model_as_a_Block. But there's that private adjustRotatePivotViaMeta method which, as I understand, rotates it according to metadata. My question is, where do I call said method with adequate args?

Link to comment
Share on other sites

If the lack of replies if related to me not posting my code, here.

TESR:

 

package com.creepysheep.earthmod.block.PostHead;

 

import com.creepysheep.earthmod.utility.LogHelper;

import net.minecraft.block.Block;

import net.minecraft.client.Minecraft;

import net.minecraft.client.renderer.OpenGlHelper;

import net.minecraft.client.renderer.Tessellator;

import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;

import net.minecraft.entity.Entity;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.util.ResourceLocation;

import net.minecraft.world.World;

import org.lwjgl.opengl.GL11;

 

public class PostHeadRenderer extends TileEntitySpecialRenderer {

 

    //The model of your block

    private final ModelPostHead model;

 

    public PostHeadRenderer() {

        this.model = new ModelPostHead();

    }

 

    private void adjustRotatePivotViaMeta(World world, int x, int y, int z) {

        int meta = world.getBlockMetadata(x, y, z);

        GL11.glPushMatrix();

        GL11.glRotatef(meta * (-90), 0.0F, 0.0F, 1.0F);

        GL11.glPopMatrix();

    }

    @Override

    public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) {

        int meta = te.getWorldObj().getBlockMetadata((int)x, (int)y, (int)z);

        World world = Minecraft.getMinecraft().theWorld;

 

        //The PushMatrix tells the renderer to "start" doing something.

        GL11.glPushMatrix();

        //This is setting the initial location.

        GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);

        ResourceLocation textures = (new ResourceLocation("earthmod:textures/models/blockPostHead.png"));

        Minecraft.getMinecraft().renderEngine.bindTexture(textures);

 

        GL11.glPushMatrix();

        GL11.glRotatef(180F, 0F, 0F, 1F);

        LogHelper.info("Block meta: " + meta);

 

        this.model.render((Entity) null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);

        GL11.glPopMatrix();

        GL11.glPopMatrix();

    }

 

    //Set the lighting stuff, so it changes it's brightness properly.

    private void adjustLightFixture(World world, int i, int j, int k, Block block) {

        Tessellator tess = Tessellator.instance;

        //float brightness = block.getBlockBrightness(world, i, j, k);

        //As of MC 1.7+ block.getBlockBrightness() has become block.getLightValue():

        float brightness = block.getLightValue(world, i, j, k);

        int skyLight = world.getLightBrightnessForSkyBlocks(i, j, k, 0);

        int modulousModifier = skyLight % 65536;

        int divModifier = skyLight / 65536;

        tess.setColorOpaque_F(brightness, brightness, brightness);

        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float) modulousModifier, divModifier);

    }

}

 

 

Block:

 

package com.creepysheep.earthmod.block.PostHead;

 

import com.creepysheep.earthmod.creativetab.CreativeTabEarth;

import com.creepysheep.earthmod.init.ModBlocks;

import com.creepysheep.earthmod.reference.Reference;

import com.creepysheep.earthmod.utility.LogHelper;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.block.BlockContainer;

import net.minecraft.block.BlockDirectional;

import net.minecraft.block.material.Material;

import net.minecraft.client.Minecraft;

import net.minecraft.client.renderer.texture.IIconRegister;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.ItemStack;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.util.MathHelper;

import net.minecraft.world.World;

 

public class BlockPostHead extends BlockContainer

{

    public BlockPostHead() {

        super(Material.iron);

        this.setBlockBounds(0.3F, 0F, 0.3F, 0.7F, 0.5F, 0.7F);

        this.setCreativeTab(CreativeTabEarth.EARTH_TAB);

        this.setBlockName("blockPostHead");

    }

    @Override

    public TileEntity createNewTileEntity(World world, int var2) {

        return new EntityPostHead();

    }

 

    //You don't want the normal render type, or it wont render properly.

    @Override

    public int getRenderType() {

        return -1;

    }

 

    //It's not an opaque cube, so you need this.

    @Override

    public boolean isOpaqueCube() {

        return false;

    }

 

    //It's not a normal block, so you need this too.

    public boolean renderAsNormalBlock() {

        return false;

    }

 

    public boolean isCollidable() { return true; }

 

    public int getMobilityFlag()

    {

        return 2;

    }

 

    @Override

    public String getUnlocalizedName()

    {

        return String.format("tile.%s%s", Reference.MOD_ID.toLowerCase() + ":", getUnwrappedUnlocalizedName(super.getUnlocalizedName()));

    }

    protected String getUnwrappedUnlocalizedName(String unlocalizedName)

    {

        return unlocalizedName.substring(unlocalizedName.indexOf(".") + 1);

    }

    @Override

    @SideOnly(Side.CLIENT)

    public void registerBlockIcons(IIconRegister iconRegister)

    {

        blockIcon = iconRegister.registerIcon(String.format("%s", getUnwrappedUnlocalizedName(this.getUnlocalizedName())));

    }

    @Override

    public boolean canPlaceBlockAt(World world, int x, int y, int z)

    {

        return world.getBlock(x, y - 1, z).equals(ModBlocks.CPost) && world.getBlock(x, y - 2, z).equals(ModBlocks.CPost);

    }

    @Override

    public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemStack)

    {

        int dir = MathHelper.floor_double((double) ((entity.rotationYaw * 4F) / 360F) + 0.5D) & 3;

        world.setBlockMetadataWithNotify(x, y, z, dir, 3);

        LogHelper.info("Meta set: " + dir);

    }

    @Override

    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_)

    {

        LogHelper.info("Meta: " + world.getBlockMetadata(x, y, z));

        return false;

    }

}

 

 

Link to comment
Share on other sites

I'm confused...

Is this not working at all or I'm doing it wrong?

 

package com.creepysheep.earthmod.block.PostHead;

 

import com.creepysheep.earthmod.utility.LogHelper;

import net.minecraft.block.Block;

import net.minecraft.client.Minecraft;

import net.minecraft.client.renderer.OpenGlHelper;

import net.minecraft.client.renderer.Tessellator;

import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;

import net.minecraft.entity.Entity;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.util.ResourceLocation;

import net.minecraft.world.World;

import org.lwjgl.opengl.GL11;

 

public class PostHeadRenderer extends TileEntitySpecialRenderer {

 

    //The model of your block

    private final ModelPostHead model;

 

    public PostHeadRenderer() {

        this.model = new ModelPostHead();

    }

 

    private void adjustRotatePivotViaMeta(World world, int x, int y, int z) {

        int meta = 2; //world.getBlockMetadata(x, y, z);

        GL11.glPushMatrix();

        GL11.glRotatef(meta * (-90), 0.0F, 0.0F, 1.0F);

        GL11.glPopMatrix();

        LogHelper.info("Block meta: " + meta);

    }

    @Override

    public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) {

        World world = Minecraft.getMinecraft().theWorld;

 

        adjustRotatePivotViaMeta(te.getWorldObj(), (int)x, (int)y, (int)z);

        //The PushMatrix tells the renderer to "start" doing something.

        GL11.glPushMatrix();

        //This is setting the initial location.

        GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);

        ResourceLocation textures = (new ResourceLocation("earthmod:textures/models/blockPostHead.png"));

        Minecraft.getMinecraft().renderEngine.bindTexture(textures);

 

        GL11.glPushMatrix();

        GL11.glRotatef(180F, 0F, 0F, 1F);

        //Returns 0 for some reason

        //LogHelper.info("Block meta: " + meta);

 

 

        this.model.render((Entity) null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);

        GL11.glPopMatrix();

        GL11.glPopMatrix();

    }

 

    //Set the lighting stuff, so it changes it's brightness properly.

    private void adjustLightFixture(World world, int i, int j, int k, Block block) {

        Tessellator tess = Tessellator.instance;

        //float brightness = block.getBlockBrightness(world, i, j, k);

        //As of MC 1.7+ block.getBlockBrightness() has become block.getLightValue():

        float brightness = block.getLightValue(world, i, j, k);

        int skyLight = world.getLightBrightnessForSkyBlocks(i, j, k, 0);

        int modulousModifier = skyLight % 65536;

        int divModifier = skyLight / 65536;

        tess.setColorOpaque_F(brightness, brightness, brightness);

        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float) modulousModifier, divModifier);

    }

}

 

Additional info:

I use te.getWorldObj() to get world for adjust method

Meta always returns 0 even if onBlockActivated in block class return the correct meta.

Link to comment
Share on other sites

Is this class kind of copy-pasta or you don't understand what you write:

The PushMatrix tells the renderer to "start" doing something.

Here starts render section...

Sorry, but i will not answer further questions, if you will not understand how it works. // is not just for fun!

You call it in render section, right before model... i think that param names are self explanatory...

Link to comment
Share on other sites

Yes, this class is copy-pasted.

I have no previous experience with GL. Actually I have very little experience with Java in general.

I know // is not for fun.

I did not understand if "render section" was the whole method or some part of it.

 

And the adjustRotatePivotViaMeta method seems to be not working at all. Even when I set the "meta" manually.

Link to comment
Share on other sites

Okay, so here's your code annotated with //== ==\\ to separate sections

//== MAIN RENDER METHOD==\\
@Override
    public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) {
        int meta = te.getWorldObj().getBlockMetadata((int)x, (int)y, (int)z);
        World world = Minecraft.getMinecraft().theWorld;

//== BEGGINING OF RENDERING ==\\
//== PUSHING NEXT MATRIX FOR WHOLE RENDERER==\\
        //The PushMatrix tells the renderer to "start" doing something.
        GL11.glPushMatrix();
        //This is setting the initial location.
        GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
//== TEXTURING==\\
        ResourceLocation textures = (new ResourceLocation("earthmod:textures/models/blockPostHead.png"));
        Minecraft.getMinecraft().renderEngine.bindTexture(textures);
//== PUSHING NEXT MATRIX FOR MODEL RENDERER==\\
        GL11.glPushMatrix();
//== ANDJUSTING START POSROTSCALE==\\
        GL11.glRotatef(180F, 0F, 0F, 1F);
        LogHelper.info("Block meta: " + meta);

//== MODELLING==\\
        this.model.render((Entity) null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
//== POPPING MATRIX FOR MODEL RENDERER==\\
        GL11.glPopMatrix();
//== POPPING MATRIX FOR WHOLE RENDERER==\\
        GL11.glPopMatrix();
    }

Link to comment
Share on other sites

I have it fixed now. I'm using GL11.glRotatef((meta - 1) * (-90), 0F, 1F, 0F); to rotate the model (I found out that last three params are for indicating on which axis I want to rotate)

 

It's a vector, actually.  You can rotate around an arbitrary vector if you'd like, too:

GL11.glRotatef((meta - 1) * (-90), 0.707F, 0.707F, 0F);

 

But yes, for most purposes you'll be rotating around an axis.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

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

    • I create my mod pack,yesterday my mod pack is fine but i add one mod and error. I'm delete this mmod but minecraft is still stop on CONFIG_LOAD then I tried to delete config and restart it but again. If you can pleace help me. https://imgur.com/ngZBzuv
    • game crashes before even opening (log:https://mclo.gs/M8xvX7c)
    • I have created a custom entity that extends "TamableAnimal", but I am wanting to have it spawn in the ocean. I have it spawning right now, but it spawns way too frequently even with weight set to 1. I am guessing it is because it is rolling in the spawn pool of land animals since TameableAnimal extends Animal and is different than WaterAnimal, and since no land animals spawn in the ocean it just fills every inch up with my custom entity. I have followed basic tutorials for spawning entities with Forge, but I feel like I am missing something about how to change what spawn pool this custom entity ends up in. Is it possible to change that or do I need to refactor it to be based off of WaterAnimal to get those spawn? My biome modifier JSON file: { "type": "forge:add_spawns", "biomes": "#minecraft:is_ocean", "spawners": { "type": "darwinsmysticalmounts:water_wyvern", "weight": 20, "minCount": 1, "maxCount": 1 } } My client event: event.register(ModEntityTypes.WATER_WYVERN.get(), SpawnPlacements.Type.NO_RESTRICTIONS, Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, WaterWyvernEntity::checkWaterWyvernSpawnRules, SpawnPlacementRegisterEvent.Operation.REPLACE); And the actual custom spawn rule that makes it spawn in the water: public static boolean checkWaterWyvernSpawnRules(EntityType<WaterWyvernEntity> pAnimal, LevelAccessor pLevel, MobSpawnType pSpawnType, BlockPos pPos, RandomSource pRandom) { return pPos.getY() > pLevel.getSeaLevel() - 16 && pLevel.getFluidState(pPos.below()).is(FluidTags.WATER); }  
    • Starting today, I am unable to load my modded minecraft world. Forge crash log initially said it was a specific mod called Doggy Talents, which I disabled. Then it blamed JEI, and when that was disabled it blamed another mod so I assume it's something more than a specific mod. Minecraft launcher log claims "Exit Code 1". Nothing had changed since last night when it was working fine Forge Log: https://pastebin.com/S1GiBGVJ Client Log: https://pastebin.com/aLwuGUNL  
    • I am using AMD, yes. I downloaded the website's drivers and am still having the issue. I also used the Cleanup Utility just in case. 
  • Topics

×
×
  • Create New...

Important Information

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