Jump to content

Recommended Posts

Posted

I have a block I am making, and it has a custom model.  The model is two blocks long, so when you place it, it rotates according to the direction you are facing.  The problem is, when I reload the world, it resets the rotation of the model, but not the rotation of the block itself.  Does anybody know how to fix this?

TileEntityCannon:

 

package ninjapancakes87.civilwar.block.cannon;

import java.util.logging.Level;
import java.util.logging.LogRecord;

import cpw.mods.fml.common.FMLLog;

import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import ninjapancakes87.civilwar.CivilWar;

public class TileEntityCannon extends TileEntity{
public byte rotation;
public Block block;
public TileEntityCannonRenderer TErender;

@Override
    public void readFromNBT(NBTTagCompound nbtTagCompound) {
	super.readFromNBT(nbtTagCompound);
	this.setRotation(nbtTagCompound.getByte("rotation"));
	CivilWar.CwLogger.log(Level.INFO, "Read rotation: " + this.rotation);
}
@Override
    public void writeToNBT(NBTTagCompound nbtTagCompound) {
	super.writeToNBT(nbtTagCompound);
	nbtTagCompound.setByte("rotation", this.getRotation());
	CivilWar.CwLogger.log(Level.INFO, "Write rotation: " + this.rotation);
}
public byte getRotation(){
	return this.rotation;
}
public void setRotation(byte par1){
	this.rotation = par1;
}
}

 

TileEntityCannonRenderer:

 

package ninjapancakes87.civilwar.block.cannon;

import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import ninjapancakes87.civilwar.Extras;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class TileEntityCannonRenderer extends TileEntitySpecialRenderer {
private static final ResourceLocation texture = new ResourceLocation(Extras.sb + "cannon.png");
    /** The cannon model */
    private Cannon model;
    
    public short scale;
    
    /** Instance of renderManager, super one is not visible*/
    protected RenderManager renderManager;

    public TileEntityCannonRenderer()
    {
    	this.model = new Cannon();
    }
    /**
     * Used for rendering the tile entity
     * @param tileentity is the tile entity you are using
     * @param d0 used for translation on the X axis
     * @param d1 used for translation on the Y axis
     * @param d2 used for translation on the Z axis
     * @param f is not used for anything (at least in mine).
     */
@Override
public void renderTileEntityAt(TileEntity tileentity, double d0, double d1, double d2, float f) {
	TileEntityCannon cannonTE = (TileEntityCannon)tileentity;
	GL11.glPushMatrix();
	GL11.glTranslatef((float) d0 + 0.5F, (float) d1 + 1.5F, (float) d2 + 0.5F);
	GL11.glScalef(1.0F, -1F, -1F);
	byte rotation = cannonTE.getRotation();
	if(rotation == 2){
            scale = -90;
        }

        if(rotation == 3){
            scale = 90;
        }

        if(rotation == 4){
            scale = 180;
        }

        if(rotation == 5){
            scale = 0;
        }
        GL11.glRotatef(scale, 0.0F, 1.0F, 0.0F);
	GL11.glRotatef(90, 0, 1.0F, 0);
	this.func_110628_a(texture);
	this.model.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
	GL11.glPopMatrix(); 
}
public void rotate(byte rotation){
	if(rotation == 2){
            scale = -90;
        }

        if(rotation == 3){
            scale = 90;
        }

        if(rotation == 4){
            scale = 180;
        }

        if(rotation == 5){
            scale = 0;
        }
	GL11.glRotatef(scale, 0, 1, 0);
	GL11.glRotatef(90, 0, 1.0F, 0);
}

}

 

Thanks in advance,

ninjapancakes87.

Posted

you need to incorporate metadata, set each possible rotation to a different metadata value and have the model render the proper rotaton based on the blocks metadata value, which will save when you exit and come back into the game.

Posted

I did. I set the metadata of the block and i set a byte rotation, which i write to NBT in the tile entity.  I diid some debug code, and the block stays rotated, but the model doesnt.  Also, it reads fine from NBT, but for some reason it doesnt re-render the model when i reload the world.

Posted
Also, it reads fine from NBT, but for some reason it doesnt re-render the model when i reload the world.

TEST are rendered every frame

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Posted

yeah but what im saying is that TESR are rendered every frame (typicly 60 times per second)

you can see this by printing something during the rendering method

 

can you check that the value is actually messed up in the rendering emthod ?

 

like

 

System.out.println("value of rotation "+cannonTE.getRotation());

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Posted

yeah but what im saying is that TESR are rendered every frame (typicly 60 times per second)

you can see this by printing something during the rendering method

 

can you check that the value is actually messed up in the rendering emthod ?

 

like

 

System.out.println("value of rotation "+cannonTE.getRotation());

*Don't know why I didn't think of that*

For some reason it's not reading right.  It reads the rotation as 0, when originally it was 2.  This weekend I will try having it draw from the metadata.  Did I correctly set the NBT tag in my tile entity?

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



×
×
  • Create New...

Important Information

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