Jump to content

Recommended Posts

Posted

Im trying to bind a different texture for my render based on variable stored in TileEntity, but the texture doesnt update(even when I place a block next to it, nothing changes). How can I force it to update?

 

Here is my code(some parts are complete mess, especially renderer,  used just for testing).

 

Block

 

  Reveal hidden contents

 

 

Renderer(complete mess here)

 

  Reveal hidden contents

 

 

Every code I try doesnt seem to work. :/

Posted
package net.woodworks.tileentity;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;

public class TileEntityTable extends TileEntity {

private int cloth;
private int rotation;

@Override
public void writeToNBT(NBTTagCompound compound)
{
	super.writeToNBT(compound);
	compound.setInteger("cloth", cloth);
	compound.setInteger("rotation", rotation);
}

@Override
public void readFromNBT(NBTTagCompound compound)
{
	super.readFromNBT(compound);
	cloth=compound.getInteger("cloth");
	rotation=compound.getInteger("rotation");
}



//Getter
public int getState()
{
	return cloth;
}

public int getRotation()
{
	return rotation;
}
//Setter
public void setState(int par1)
{
	cloth = par1;
	System.out.println("Setting state integer:" + par1);
}

public void setRotation(int par1)
{
	rotation = par1;
	System.out.println("Setting rotation integer:" + par1);
}
}

Posted

The cool thing is that vanilla handles 99% of it for you, just add this:

 

        public Packet getDescriptionPacket() {
                NBTTagCompound nbtTag = new NBTTagCompound();
                this.writeToNBT(nbtTag);
                return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
        }

        public void onDataPacket(INetworkManager net, Packet132TileEntityData packet) {
                readFromNBT(packet.data);
        }

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.

Posted
  On 1/15/2014 at 9:41 PM, Draco18s said:

The cool thing is that vanilla handles 99% of it for you, just add this:

 

        public Packet getDescriptionPacket() {
                NBTTagCompound nbtTag = new NBTTagCompound();
                this.writeToNBT(nbtTag);
                return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
        }

        public void onDataPacket(INetworkManager net, Packet132TileEntityData packet) {
                readFromNBT(packet.data);
        }

 

Thank you! However I never made a mod where I would have to sync packets. So I really dont know how this is done. Where should I put this?

Posted
  On 1/15/2014 at 10:33 PM, DanteZg said:

  Quote

The cool thing is that vanilla handles 99% of it for you, just add this:

 

        public Packet getDescriptionPacket() {
                NBTTagCompound nbtTag = new NBTTagCompound();
                this.writeToNBT(nbtTag);
                return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
        }

        public void onDataPacket(INetworkManager net, Packet132TileEntityData packet) {
                readFromNBT(packet.data);
        }

 

Thank you! However I never made a mod where I would have to sync packets. So I really dont know how this is done. Where should I put this?

 

Inside your tile entity class.  That's ALL you need to do in this case.

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.

Posted
  On 1/15/2014 at 10:43 PM, Draco18s said:

  Quote

  Quote

The cool thing is that vanilla handles 99% of it for you, just add this:

 

        public Packet getDescriptionPacket() {
                NBTTagCompound nbtTag = new NBTTagCompound();
                this.writeToNBT(nbtTag);
                return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
        }

        public void onDataPacket(INetworkManager net, Packet132TileEntityData packet) {
                readFromNBT(packet.data);
        }

 

Thank you! However I never made a mod where I would have to sync packets. So I really dont know how this is done. Where should I put this?

 

Inside your tile entity class.  That's ALL you need to do in this case.

 

Thats what I tought, however the still texture doesnt update/change. Even when I manually force a block to update.

Posted

Is the value that controls your texture saved to NBT?

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.

Posted
  On 1/16/2014 at 12:07 AM, Draco18s said:

Is the value that controls your texture saved to NBT?

 

Yes, Its saved, everything else works, except that the textures stay the same. I havent finished all the textures, so when I run the game I get an error missing texture bla bla, it isnt possible that this could be causing this error? Aslo, you have my code above if you are interested in helping me out. Thank you btw.

Posted
  On 1/16/2014 at 12:15 AM, DanteZg said:
Yes, Its saved, everything else works, except that the textures stay the same. I havent finished all the textures, so when I run the game I get an error missing texture bla bla, it isnt possible that this could be causing this error? Aslo, you have my code above if you are interested in helping me out. Thank you btw.

 

If you're changing from one missing texture to another...

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.

Posted

OK I have noticed that when I'm in singleplayer and after I quit and then rejoin the textures get updated. When I'm testing the server I get this error:

 

---- Minecraft Crash Report ----
// I just don't know what went wrong 

Time: 1/16/14 9:30 PM
Description: Ticking memory connection

java.lang.NullPointerException
at net.woodworks.blocks.BlockTable.onBlockActivated(BlockTable.java:166)
at net.minecraft.item.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:421)
at net.minecraft.network.NetServerHandler.handlePlace(NetServerHandler.java:556)
at net.minecraft.network.packet.Packet15Place.processPacket(Packet15Place.java:79)
at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89)
at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141)
at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54)
at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:691)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:587)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:129)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:484)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)

 

  On 1/16/2014 at 4:06 AM, Draco18s said:

  Quote
Yes, Its saved, everything else works, except that the textures stay the same. I havent finished all the textures, so when I run the game I get an error missing texture bla bla, it isnt possible that this could be causing this error? Aslo, you have my code above if you are interested in helping me out. Thank you btw.

 

If you're changing from one missing texture to another...

 

I'm not :)

Posted

Okay I have figured out what have I done wrong and I have fixed that NullPointException, now the same thing happens on the server, when I setState to integer, the texture doesnt change until I log out and log in again. Please help me, this is the last thing holding me from releasing my mod.

Posted

Mmm~

Client-server disparity.

Solved by packets.

 

You're sure you have this in your TE?

 

        public Packet getDescriptionPacket() {
                NBTTagCompound nbtTag = new NBTTagCompound();
                this.writeToNBT(nbtTag);
                return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
        }

        public void onDataPacket(INetworkManager net, Packet132TileEntityData packet) {
                readFromNBT(packet.data);
        }

 

And that right after you change the value you call world.notifyBlockChange()?

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.

Posted
  On 1/17/2014 at 6:41 PM, Draco18s said:

Mmm~

Client-server disparity.

Solved by packets.

 

You're sure you have this in your TE?

 

        public Packet getDescriptionPacket() {
                NBTTagCompound nbtTag = new NBTTagCompound();
                this.writeToNBT(nbtTag);
                return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
        }

        public void onDataPacket(INetworkManager net, Packet132TileEntityData packet) {
                readFromNBT(packet.data);
        }

 

And that right after you change the value you call world.notifyBlockChange()?

 

I have fixed that error with packets. Yeah here is my code:

	@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
{
	if(!world.isRemote){
		TileEntityTable par1tileEntity = (TileEntityTable)world.getBlockTileEntity(x, y, z);
			if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == net.woodworks.common.WoodworksCommonProxy.itemModCloth && par1tileEntity.getState() == 0)
			{
				int par1ItemDamage = player.getCurrentEquippedItem().getItemDamage();
				par1tileEntity.setState(par1ItemDamage + 1);
				world.notifyBlockChange(x, y, z, this.blockID);
				player.inventory.decrStackSize(player.inventory.currentItem, 1);
				player.worldObj.playSoundAtEntity(player, "dig.cloth", 1.0F, 1.0F);
				return true;
			}
			else if(player.getCurrentEquippedItem().getItem() != net.woodworks.common.WoodworksCommonProxy.itemModCloth && par1tileEntity.getState() != 0){
				int par1ItemDamage = par1tileEntity.getState();
				dropItemStack(new ItemStack(net.woodworks.common.WoodworksCommonProxy.itemModCloth, 1, par1ItemDamage-1), world, x, y, z);
				par1tileEntity.setState(0);
				world.notifyBlockChange(x, y, z, this.blockID);
				player.worldObj.playSoundAtEntity(player, "dig.cloth", 1.0F, 1.0F);
				return true;
			}
			else if(player.getCurrentEquippedItem().getItem() == net.woodworks.common.WoodworksCommonProxy.itemModCloth && par1tileEntity.getState() != 0){
				int par1ItemDamage = player.getCurrentEquippedItem().getItemDamage();
				int par1State = par1tileEntity.getState();
				if(par1ItemDamage != par1State-1){
				player.inventory.decrStackSize(player.inventory.currentItem, 1);
				dropItemStack(new ItemStack(net.woodworks.common.WoodworksCommonProxy.itemModCloth, 1, par1State-1), world, x, y, z);
				par1tileEntity.setState(par1ItemDamage + 1);
				world.notifyBlockChange(x, y, z, this.blockID);
				player.worldObj.playSoundAtEntity(player, "dig.cloth", 1.0F, 1.0F);
				return true;
				}
			}
			else if(par1tileEntity.getState() == 1 && player.getCurrentEquippedItem().getItem() == Item.dyePowder){
				int par1ItemDamage = player.getCurrentEquippedItem().getItemDamage();
				player.inventory.decrStackSize(player.inventory.currentItem, 1);
				par1tileEntity.setState(par1ItemDamage +1);
				world.notifyBlockChange(x, y, z, this.blockID);
				player.worldObj.playSoundAtEntity(player, "dig.cloth", 1.0F, 1.0F);
				return true;
			}
	}
	return true;

}	

 

However the textures only change after you rejoin the world.

 

EDIT: I threw a bunch of this rerender methods(check to new code) and now it rerenders after clicking right click 2 times with the same item. Any ideas now? :D

 

	public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
{
	if(!world.isRemote){
		TileEntityTable par1tileEntity = (TileEntityTable)world.getBlockTileEntity(x, y, z);
			if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == net.woodworks.common.WoodworksCommonProxy.itemModCloth && par1tileEntity.getState() == 0)
			{
				int par1ItemDamage = player.getCurrentEquippedItem().getItemDamage();
				par1tileEntity.setState(par1ItemDamage + 1);
				world.notifyBlockChange(x, y, z, this.blockID);
				player.worldObj.markBlockForRenderUpdate(x, y, z);
				player.inventory.decrStackSize(player.inventory.currentItem, 1);
				player.worldObj.playSoundAtEntity(player, "dig.cloth", 1.0F, 1.0F);
				return true;
			}
			else if(player.getCurrentEquippedItem().getItem() != net.woodworks.common.WoodworksCommonProxy.itemModCloth && par1tileEntity.getState() != 0){
				int par1ItemDamage = par1tileEntity.getState();
				dropItemStack(new ItemStack(net.woodworks.common.WoodworksCommonProxy.itemModCloth, 1, par1ItemDamage-1), world, x, y, z);
				par1tileEntity.setState(0);
				world.notifyBlockChange(x, y, z, this.blockID);
				player.worldObj.markBlockForRenderUpdate(x, y, z);
				player.worldObj.playSoundAtEntity(player, "dig.cloth", 1.0F, 1.0F);
				return true;
			}
			else if(player.getCurrentEquippedItem().getItem() == net.woodworks.common.WoodworksCommonProxy.itemModCloth && par1tileEntity.getState() != 0){
				int par1ItemDamage = player.getCurrentEquippedItem().getItemDamage();
				int par1State = par1tileEntity.getState();
				if(par1ItemDamage != par1State-1){
				player.inventory.decrStackSize(player.inventory.currentItem, 1);
				dropItemStack(new ItemStack(net.woodworks.common.WoodworksCommonProxy.itemModCloth, 1, par1State-1), world, x, y, z);
				par1tileEntity.setState(par1ItemDamage + 1);
				world.notifyBlockChange(x, y, z, this.blockID);
				player.worldObj.markBlockForRenderUpdate(x, y, z);
				player.worldObj.playSoundAtEntity(player, "dig.cloth", 1.0F, 1.0F);
				return true;
				}
			}
			else if(par1tileEntity.getState() == 1 && player.getCurrentEquippedItem().getItem() == Item.dyePowder){
				int par1ItemDamage = player.getCurrentEquippedItem().getItemDamage();
				player.inventory.decrStackSize(player.inventory.currentItem, 1);
				par1tileEntity.setState(par1ItemDamage +1);
				world.notifyBlockChange(x, y, z, this.blockID);
				player.worldObj.markBlockForRenderUpdate(x, y, z);
				player.worldObj.playSoundAtEntity(player, "dig.cloth", 1.0F, 1.0F);
				return true;
			}
	}
	world.markBlockForUpdate(x,y,z);
	world.notifyBlockChange(x, y, z, this.blockID);
	player.worldObj.markBlockForRenderUpdate(x, y, z);
	Minecraft.getMinecraft().renderGlobal.markBlockForRenderUpdate(x, y, z);
	return true;

}	

 

EDIT2: Got it to work! I will post my final code later tonight (I need to rewrite some things) so everyone with this problem can use it! Thank you for your help Draco!

 

EDIT3: Server crashes now!

 

EDIT4: Code works but it needs some serious rewriting, I'll be back in a few.

Posted

That code does not help solve the problem as there are NO references to packets in that function.

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.

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.