Jump to content

Tile Entity not saving coordinates


ColdFox

Recommended Posts

Tile entities use this.posX

 

And unless you post actual code, we are unable to help you.

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

Tile entities use this.posX

 

And unless you post actual code, we are unable to help you.

 

Ok... the code;

BaseDownBlock

 

package mods.MoreBlocksMod;

 

import java.util.List;

 

import net.minecraft.block.Block;

import net.minecraft.block.BlockContainer;

import net.minecraft.block.ITileEntityProvider;

import net.minecraft.block.material.Material;

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

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.item.ItemStack;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.util.Icon;

import net.minecraft.world.IBlockAccess;

import net.minecraft.world.World;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

public class BaseDownBlock extends BlockContainer implements

ITileEntityProvider {

public BaseDownBlock(int id, Material material) {

super(id, material);

this.setCreativeTab(mod_MoreBlocksMod.tabMoreBlocks);

// this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);

}

 

@SideOnly(Side.CLIENT)

private Icon[] icons;

 

@SideOnly(Side.CLIENT)

public void registerIcons(IconRegister par1IconRegister) {

icons = new Icon[mod_MoreBlocksMod.blockTypes.length];

 

for (int i = 0; i < icons.length; i++) {

icons = par1IconRegister.registerIcon("minecraft:"

+ mod_MoreBlocksMod.blockTypes);

}

}

 

public void onBlockDestroyedByPlayer(World par1World, int par2, int par3,

int par4, int par5) {

if (!par1World.isRemote) {

TileEntity te = par1World.getBlockTileEntity(par2, par3, par4);

// ((BaseDownTileEntity)te).blockMetadata

if (te != null)

System.out.println("Metadata: "

+ ((BaseDownTileEntity) te).blockMetadata);

}

}

 

@SideOnly(Side.CLIENT)

public Icon getIcon(int par1, int par2) {

return icons[par2];

}

 

@SideOnly(Side.CLIENT)

public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs,List par3List) {

for (int i = 0; i < mod_MoreBlocksMod.blockTypes.length; ++i) {

par3List.add(new ItemStack(par1, 1, i));

}

}

 

public int damageDropped(int par1) {

return par1;

}

 

public boolean shouldSideBeRendered(IBlockAccess iblockaccess, int i,

int j, int k, int l) {

return false;

}

 

public boolean isOpaqueCube() {

return false;

}

 

@Override

public TileEntity createNewTileEntity(World world) {

return new BaseDownTileEntity();

}

 

}

 

 

BaseDownTileEntity

 

 

package mods.MoreBlocksMod;

import net.minecraft.block.Block;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.network.INetworkManager;

import net.minecraft.network.packet.Packet;

import net.minecraft.network.packet.Packet132TileEntityData;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.world.World;

 

public class BaseDownTileEntity extends TileEntity{

 

  public BaseDownTileEntity setBlockTypeAndMeta(Block block, int meta){

  this.blockType = block;

  this.blockMetadata = meta;

  return this;

  }

 

/**

    * Reads a tile entity from NBT.

    */

  public void readFromNBT(NBTTagCompound par1NBTTagCompound)

  {

      super.readFromNBT(par1NBTTagCompound);

  }

 

  /**

    * Writes a tile entity to NBT.

    */

  public void writeToNBT(NBTTagCompound par1NBTTagCompound)

  {

      super.writeToNBT(par1NBTTagCompound);

  }

}

 

 

 

Link to comment
Share on other sites

You need to register your tile entity for it to be calling readFromNBT and writeToNBT,so it can save the coordinates.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

You need to register your tile entity for it to be calling readFromNBT and writeToNBT,so it can save the coordinates.

I've it on the load method

GameRegistry.registerTileEntity(mods.MoreBlocksMod.BaseDownTileEntity.class, "baseDownTileEntity");

Link to comment
Share on other sites

I also have this class, that I found that it's "reseting" the values of the tile entity

 

 

public class ItemRendererInventoryBaseDown implements IItemRenderer{

 

private ModelBaseDownBlock model;

 

public ItemRendererInventoryBaseDown(){

model = new ModelBaseDownBlock();

}

 

public boolean handleRenderType(ItemStack item, ItemRenderType type) {

return true;

}

 

public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item,ItemRendererHelper helper) {

return true;

}

 

public void renderItem(ItemRenderType type, ItemStack item, Object... data) {

TileEntityRenderer.instance.renderTileEntityAt(new BaseDownTileEntity().setBlockTypeAndMeta(mod_MoreBlocksMod.baseDownBlock, item.getItemDamage()), 0.0D, 0.0D, 0.0D, 0.0F);

 

}

 

}

 

 

 

When I don't use it, the values are ok. So now the problem is how to render the custom block model in the inventory.

Link to comment
Share on other sites

I also have this class, that I found that it's "reseting" the values of the tile entity

 

 

public class ItemRendererInventoryBaseDown implements IItemRenderer{

 

private ModelBaseDownBlock model;

 

public ItemRendererInventoryBaseDown(){

model = new ModelBaseDownBlock();

}

 

public boolean handleRenderType(ItemStack item, ItemRenderType type) {

return true;

}

 

public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item,ItemRendererHelper helper) {

return true;

}

 

public void renderItem(ItemRenderType type, ItemStack item, Object... data) {

TileEntityRenderer.instance.renderTileEntityAt(new BaseDownTileEntity().setBlockTypeAndMeta(mod_MoreBlocksMod.baseDownBlock, item.getItemDamage()), 0.0D, 0.0D, 0.0D, 0.0F);

 

}

 

}

 

 

 

When I don't use it, the values are ok. So now the problem is how to render the custom block model in the inventory.

 

Seriously?

 

That doesn't "reset" the values for your tile entity.  That creates a new tile entity with its OWN values.  When you're seeing the values as 0, THAT'S THE ONE IN YOUR INVENTORY.

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

I also have this class, that I found that it's "reseting" the values of the tile entity

 

 

public class ItemRendererInventoryBaseDown implements IItemRenderer{

 

private ModelBaseDownBlock model;

 

public ItemRendererInventoryBaseDown(){

model = new ModelBaseDownBlock();

}

 

public boolean handleRenderType(ItemStack item, ItemRenderType type) {

return true;

}

 

public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item,ItemRendererHelper helper) {

return true;

}

 

public void renderItem(ItemRenderType type, ItemStack item, Object... data) {

TileEntityRenderer.instance.renderTileEntityAt(new BaseDownTileEntity().setBlockTypeAndMeta(mod_MoreBlocksMod.baseDownBlock, item.getItemDamage()), 0.0D, 0.0D, 0.0D, 0.0F);

 

}

 

}

 

 

 

When I don't use it, the values are ok. So now the problem is how to render the custom block model in the inventory.

 

Seriously?

 

That doesn't "reset" the values for your tile entity.  That creates a new tile entity with its OWN values.  When you're seeing the values as 0, THAT'S THE ONE IN YOUR INVENTORY.

 

Ok... my bad :$ I was handling the wrong tile entities, the problem is fixed.

I still need a little help but it's not related with this thread. I need to have more than 16 subtypes of a block, the problem is that I can't use metadata, otherwise it would be done. Right now I'm using metadata, as you can see in the class above. It works fine except when I break a block with a subID >15. What can I do to make it work, so that when the block breaks it will drop the correct block?

Link to comment
Share on other sites

It works fine except when I break a block with a subID >15. What can I do to make it work, so that when the block breaks it will drop the correct block?

 

You need to stop using metadata entirely.  It "breaks" when you use a metadata above 15 because metadata is a byte, so vales greater than 11112 will be truncated.

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

You don't need metadata if you have a TileEntity. Store the subtypes into the TileEntity.

If you don't want the TileEntity, you'll have to switch to a different block id, as metadata is limited to 16 values.

 

can you give me an example of what to do? =/

like how do I save the subtype into the TileEntity and how to do so the "block" knows what subtype drop

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



×
×
  • Create New...

Important Information

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