Jump to content

Recommended Posts

Posted

Hello all. First time modding.

 

I am creating a mod with a whole slew of custom rendered 3D Models. I have having a particularly hard time saving the direction states.

In my code below, I am able to place the blocks and have them face my character, but when one logs out of the world, then logs back in, it has reset its position to face the north.

 

Main Block Class:

public class ComputerPerf extends BlockContainer {

public ComputerPerf(Material material) {
	super(material);

	this.setHardness(2.0F);
	this.setResistance(5.0F);
	this.setBlockBounds(0F, 0F, 0F, 1F, 0.8125F, 1F);

	this.setCreativeTab(Misccraft.misccraftTab);
}

public int getRenderType() {
	return -1;
}

public boolean isOpaqueCube() {
	return false;
}

public boolean renderAsNormalBlock() {
	return false;
}

@Override
public TileEntity createNewTileEntity(World var1, int var2) {
	return new TileEntityComputerPerf();
}

@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityplayer, ItemStack itemstack) {
	if(entityplayer == null) {
		return;
	}

	TileEntityComputerPerf perf = (TileEntityComputerPerf)world.getTileEntity(x,y,z);
	perf.direction = MathHelper.floor_double((double)((entityplayer.rotationYaw*4F)/360F) + 0.5D) & 3;
}
}

 

Renderer:

public class RenderComputerPerf extends TileEntitySpecialRenderer {

private static final ResourceLocation texture = new ResourceLocation(Misccraft.MODID + ":" + "textures/model/ComputerPerf.png");
private ModelComputerPerf model;

public RenderComputerPerf() {
	this.model = new ModelComputerPerf();
}

@Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {
	GL11.glPushMatrix();
	GL11.glTranslatef(((float)x + 0.5F), (float)y + 1.5F, (float)z + 0.5F);
	GL11.glRotatef(180, 0F, 0F, 1F);
	this.bindTexture(texture);

	TileEntityComputerPerf perf = (TileEntityComputerPerf)tileentity;
	int direction = perf.direction;
	GL11.glRotatef(direction * 90, 0.0F, 1.0F, 0.0F);

	GL11.glPushMatrix();
		this.model.renderModel(0.0625F);
	GL11.glPopMatrix();
GL11.glPopMatrix();
}
}

 

TileEntity:

public class TileEntityComputerPerf extends TileEntity {

public int direction;
}

 

ClientProxy:

public class ClientProxy extends CommonProxy {

public void registerRenderModels() {

	TileEntitySpecialRenderer render1 = new RenderComputerPerf();
	ClientRegistry.bindTileEntitySpecialRenderer(TileEntityComputerPerf.class, render1);
	MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(Misccraft.blockComputerPerf), new ItemRenderComputerPerf(render1, new TileEntityComputerPerf()));

}

public void registerTileEntitySpecialRenderer() {

}
}

 

Any help on this would be appreciated. Thanks! :)

 

 

Posted

Hi

 

You need to save the direction data.  You can either use metadata (to save the direction as block information, if you only need 0-15), or you can save it in the TileEntity as "NBT" data.

Your TileEntity will need to implement methods for:

writeToNBT, readFromNBT, getDescriptionPacket, onDataPacket

 

This link might be useful

http://www.minecraftforge.net/forum/index.php/topic,23256.msg117993.html#msg117993

 

http://cazzar.net/tutorials/minecraft/Tile-Entity-Updates-The-Quick-and-Dirty-Method/

 

http://greyminecraftcoder.blogspot.com.au/2013/07/blocks.html

 

-TGG

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.