Jump to content

[1.7.10] Tile Entity apparently losing data


Aevek

Recommended Posts

I've working in java a fair amount, but am new to working in forge, so I suspect its something obvious that I'm missing here. I am working on a mod that involves a torque system, and I need to store the direction of the torque shaft. I'm doing this by storing an integer that I check in my TESR. I am aware I could do this using forge's direction thingy, but since I need to store more data than is implemented in my code already I'm going to have this issue more in future if I don't resolve it now. All the tutorials and example code seem to do this a similar way so I am genuinely stuck here. Any help would be much appreciated.

 

I am getting my debug statements printing telling me that my variable has been assigned correctly, but by the time the debug in my accessor method fires from being called by my renderer, the variable has reset to 0. Since it is an integer, it could just be that it has reset to null, and this is what I suspect is what is happening. I have posted the complete code of the TileEntity class I'm working on. If you need any additional code to help me please let me know. As you can see the variable is private, and I've searched my other scripts and none of them call my setDirection method. I am really quite truly very stuck. Thanks in advance for any help.

 

public class TorqueShaftTileEntity extends TileEntity implements TorqueObject{
public TorqueShaft block;

private TorqueObject parent;

private int direction; //0 N/S, 1 E/W, 2 U/D

public TorqueShaftTileEntity(){
	super();
	this.block = (TorqueShaft)blockType;
	//direction = 0;
}

public int recalcFacing(World world, int x, int y, int z){
	int tempDir;

	if(world.getBlock(x + 1, y, z) instanceof TorqueObject || (world.getBlock(x + 1, y, z).hasTileEntity(0) && world.getTileEntity(x + 1, y, z) instanceof TorqueObject) ||
			world.getBlock(x - 1, y, z) instanceof TorqueObject || (world.getBlock(x - 1, y, z).hasTileEntity(0) && world.getTileEntity(x - 1, y, z) instanceof TorqueObject)) 
		tempDir = 1;
	else if(world.getBlock(x, y, z + 1) instanceof TorqueObject || (world.getBlock(x, y, z + 1).hasTileEntity(0) && world.getTileEntity(x, y, z + 1) instanceof TorqueObject) ||
			world.getBlock(x, y, z - 1) instanceof TorqueObject || (world.getBlock(x, y, z - 1).hasTileEntity(0) && world.getTileEntity(x, y, z - 1) instanceof TorqueObject)) 
		tempDir = 2;
	else tempDir = 3;

	setDirection(tempDir);
	parent = null;

	return tempDir;
}

public int incrementDirection(){
	if(++direction > 3) direction = 1;
	parent = null;
	return direction;
}

public int getDirection(){
	System.out.println("Sending Direction: " + direction);
	return direction;
}

public void setDirection(int dir){
	System.out.println("Setting Direction: " + dir);
	this.direction = dir;
}

public void checkTorquePaths(World world, int x, int y, int z){
	TorqueObject a = null;
	TorqueObject b = null;

	System.out.println("Direction for torque: " + direction);

	if(direction == 1){
		if(world.getBlock(x + 1, y, z) instanceof TorqueObject) a = (TorqueObject)world.getBlock(x + 1, y, z);
		if(world.getBlock(x - 1, y, z) instanceof TorqueObject) b = (TorqueObject)world.getBlock(x - 1, y, z);
	}

	if(direction == 2){
		if(world.getBlock(x, y, z + 1) instanceof TorqueObject) a = (TorqueObject)world.getBlock(x, y, z + 1);
		if(world.getBlock(x, y, z - 1) instanceof TorqueObject) b = (TorqueObject)world.getBlock(x, y, z - 1);
	}

	if(direction == 3){
		if(world.getBlock(x, y + 1, z) instanceof TorqueObject) a = (TorqueObject)world.getBlock(x, y + 1, z);
		if(world.getBlock(x, y - 1, z) instanceof TorqueObject) b = (TorqueObject)world.getBlock(x, y - 1, z);
	}

	if(a != null && b != null){
		if(a.getSource() == null && b.getSource() == null) this.parent = null;
		else if(a.getSource() != null && b.getSource() == null){
			this.parent = a.getSource();
		}
		else if(a.getSource() == null && b.getSource() != null) {
			this.parent = b.getSource();
		}
		else if(a.getSource() != null && b.getSource() != null){
			block.breakBlock(world, x, y, z, block, 0);
		}
	}
	else if(a != null && a.getSource() != null) this.parent = a.getSource();
	else if(b != null && b.getSource() != null) this.parent = b.getSource();
}

public void onBlockAdded(World world, int x, int y, int z) {
	System.out.println("Placing and rotating torque shaft");
	recalcFacing(world, x, y, z);
	checkTorquePaths(world, x, y, z);
	System.out.println("Direction at end of block add: " + direction);
}

public void onNeighborBlockChange(World world, int x, int y, int z){
	checkTorquePaths(world, x, y, z);
}

public TorqueObject getSource() {
	return parent;
}

public boolean useTorque(float amount) {
	return parent != null && parent.useTorque(amount);
}

public void setSource(TorqueObject other) {
	parent = other;
}

public float getRotSpeed(){
	if(parent != null) return parent.getRotSpeed();
	return 0;
}

public float getRotation(){
	if(parent != null) return parent.getRotation();
	return 0;
}

public void writeToNBT(NBTTagCompound nbt){
	nbt.setInteger("direction", this.direction);
	super.writeToNBT(nbt);
}

public void readFromNBT(NBTTagCompound nbt){
	this.direction = nbt.getInteger("direction");
	super.readFromNBT(nbt);
}
}

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

    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
  • Topics

×
×
  • Create New...

Important Information

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