Okay, then you set a breakpoint(Recall earlier threads posts about this) at the method and follow the code to see what happens as it evaluates the if statements.
That should give you information about what's going on here
That can't work, because I can test it only in normal Minecraft, because it should save the player name. MCP/Eclipse changes the player name everytime.
Ok so I changed the username.
If I understood you right, I'll have to put the world.getBlockTileEntity into a if(!world.isRemote), right?
But what's with the other code then?
package RobbiBlechdoseMod.Basis.Block;
import RobbiBlechdoseMod.Basis.Basis;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class BlockFriendBushTileEntity extends TileEntity{
String owner = "None";
int FriendVar = 0;
int first = 0;
public void talk(EntityPlayer player, World world){
if (first == 0)
{
owner = player.username;
first = 1;
}
if(player.username == owner){
//world.playSoundAtEntity(player, "RobbiBlechdoseMod:friendbush", 0.5F, 0.4F);
if(player.getCurrentEquippedItem() != null)
{
ItemStack held = player.getCurrentEquippedItem();
if(held.getItem().itemID == Item.diamond.itemID)
{
player.addChatMessage("Oh... Is that... a diamond? For ... ME? You're a really good friend!"
+ " Thanks!");
player.inventory.consumeInventoryItem(held.itemID);
FriendVar = FriendVar +10;
}
else if(held.getItem().itemID == Item.appleRed.itemID)
{
player.addChatMessage("Now I can grow and become a big and strong Bush! YAAY! You made me happy, my friend!");
player.inventory.consumeInventoryItem(held.itemID);
FriendVar = FriendVar +3;
}
else if(held.getItem().itemID == Item.goldenCarrot.itemID)
{
player.addChatMessage("A golden carrot!");
player.inventory.consumeInventoryItem(held.itemID);
FriendVar = FriendVar +4;
}
else if(held.getItem().itemID == Item.emerald.itemID)
{
player.addChatMessage("You want to trade?");
player.addChatMessage("Here you are!");
player.dropItem(Basis.PCIdle.blockID, 1);
player.inventory.consumeInventoryItem(held.itemID);
}
}
else
{
if(FriendVar < 5){
if(world.isRemote){
player.addChatMessage("Hello "+ player.username + ".");
}
}
if(FriendVar >= 5 && FriendVar < 10){
if(world.isRemote){
player.addChatMessage("Hello my friend "+ player.username + "!");
}
}
else if(FriendVar >= 10 && FriendVar < 20){
if(world.isRemote){
player.addChatMessage("Hello my really good friend "+ player.username + "!");
}
}
else if(FriendVar >=20){
if(world.isRemote){
player.addChatMessage("Hello my really really good friend "+ player.username + "!");
}
}
}
}
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.owner = nbt.getString("owner");
this.FriendVar = nbt.getInteger("FriendVar");
this.first = nbt.getInteger("first");
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setString("owner", owner);
nbt.setInteger("FriendVar", FriendVar);
nbt.setInteger("first", first);
}
}
package RobbiBlechdoseMod.Basis.Block;
import java.util.Random;
import RobbiBlechdoseMod.Basis.Basis;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFlower;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenMinable;
import net.minecraftforge.common.Configuration;
public class BlockFriendBush extends BlockFlower implements ITileEntityProvider
{
public BlockFriendBush(int par1)
{
super(par1, Material.vine);
float f = 0.4F;
this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.8F, 0.5F + f);
this.setCreativeTab(Basis.tabRobbiBlechdoseMod);
}
/**
* Gets passed in the blockID of the block below and supposed to return true if its allowed to grow on the type of
* blockID passed in. Args: blockID
*/
protected boolean canThisPlantGrowOnThisBlockID(int par1)
{
return par1 == Block.sand.blockID;
}
/**
* Returns the ID of the items to drop on destruction.
*/
public int idDropped(int par1, Random par2Random, int par3)
{
return -1;
}
public boolean onBlockActivated(World world, int par2, int par3, int par4, EntityPlayer player, int par6, float f1, float f2, float f3)
{
if(!world.isRemote){
BlockFriendBushTileEntity tile = (BlockFriendBushTileEntity) world.getBlockTileEntity(par2, par3, par4);
tile.talk(player, world);;
}
return true;
}
/**
* Called when the player destroys a block with an item that can harvest it. (i, j, k) are the coordinates of the
* block and l is the block's subtype/damage.
*/
public void harvestBlock(World par1World, EntityPlayer par2EntityPlayer, int par3, int par4, int par5, int par6)
{
if (!par1World.isRemote && par2EntityPlayer.getCurrentEquippedItem() != null && par2EntityPlayer.getCurrentEquippedItem().itemID == Item.shears.itemID)
{
par2EntityPlayer.addStat(StatList.mineBlockStatArray[this.blockID], 1);
this.dropBlockAsItem_do(par1World, par3, par4, par5, new ItemStack(Basis.FriendBush, 1, par6));
}
else
{
super.harvestBlock(par1World, par2EntityPlayer, par3, par4, par5, par6);
}
}
public void registerIcons(IconRegister reg)
{
this.blockIcon = reg.registerIcon("deadbush");
}
public TileEntity createNewTileEntity(World par1World)
{
return new BlockFriendBushTileEntity();
}
}
If I understood you right, I'll have to put the world.getBlockTileEntity into a if(!world.isRemote), right?
Why would you have to do that?
I just said that TE's are on both sides, the NBT is server side only.
Also remember that you will need to make sure that your TileEntity knows how to write and read it's packets.
There are methods you can override for this to make things simpler. Look into tile entity and there should be methods similar to "getPacketData" and "readDataPacket" by implementing those properly your server is able to tell the client how the state of the tile entity object is during runtime when the client loads into the server.
I thought that only because they did it in the tutorial. (Link a few posts above)
But why do I have to override this methods?
I've got a furnace which works fine, and there aren't such methods overriden.
And why won't that what I coded in the last post work?
I would assume the furnace you are speaking of extends TileEntityFurnace or in other ways have methods of communicating the relevant information between the Server and the Client hidden by abstraction?
I assume you mean by "it doesn't work" that it doesn't do whatever you want it to.
Did you try run the debugger on the talk method of the TileEntity and discover any problems?
If not I do recommend that you do so.
Also try to follow the logic of the variable "first" what happens to it during runtime on the server side and what happens on the client side? What happens after the game restarts? How does it's state change?
Breakpoints are quite useful for answering these questions in case you can't tell by reading the code
I didn't ask why it's there. I asked what happens to it on the Server side during the intial creation of the TE, The initilize after restarting the world, when quitting the world and when activating the block.
And the same for the client side.
I'll try now.
Robbi Blechdose
I've did it that it says "Hello my friend" and then I closed the game and opened it again and it only said "Hello".
Robbi Blechdose
That should give you information about what's going on here
Robbi Blechdose
Then it will always be the same.
Robbi Blechdose
Make sure you have "Client" selected on the side.
Have you any idea why it won't work?
Robbi Blechdose
Either you did it to the wrong configuration or you forgot to save.
I didn't mean the configuration. Is it important to check the serverside with world.getBlockTileEntity?
And is it important to check hasTileEntity?
Like in this tutorial:http://www.minecraftforge.net/wiki/How_to_use_NBT_Tag_Compound
Robbi Blechdose
NBT however is only saved server side, as is all data.
Now that the username is unchanging you can proceed to use the debugger and debug your code as I said above.
If I understood you right, I'll have to put the world.getBlockTileEntity into a if(!world.isRemote), right?
But what's with the other code then?
Robbi Blechdose
Robbi Blechdose
Why would you have to do that?
I just said that TE's are on both sides, the NBT is server side only.
Also remember that you will need to make sure that your TileEntity knows how to write and read it's packets.
There are methods you can override for this to make things simpler. Look into tile entity and there should be methods similar to "getPacketData" and "readDataPacket" by implementing those properly your server is able to tell the client how the state of the tile entity object is during runtime when the client loads into the server.
OK...
I thought that only because they did it in the tutorial. (Link a few posts above)
But why do I have to override this methods?
I've got a furnace which works fine, and there aren't such methods overriden.
And why won't that what I coded in the last post work?
Robbi Blechdose
I assume you mean by "it doesn't work" that it doesn't do whatever you want it to.
Did you try run the debugger on the talk method of the TileEntity and discover any problems?
If not I do recommend that you do so.
Also try to follow the logic of the variable "first" what happens to it during runtime on the server side and what happens on the client side? What happens after the game restarts? How does it's state change?
Breakpoints are quite useful for answering these questions in case you can't tell by reading the code
Yes, I mean TileEntityFurnace.
The variable "first" is there because I want to set the owner to the first person who right clicks my Block.
Robbi Blechdose
And the same for the client side.
I've added these methods:
from Glenn and now I can talk with the bush, but if I restart the world, I can't talk with it anymore.
Robbi Blechdose