I have the following code, and its supposed that once a person interacts with the blocks nobody more can, all works great but when i close the world and open it again, the person with the same name of the variable cant open it.
package Yourmod;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
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 TileEntityPc extends TileEntity {
String visitor1="none";
int flag = 0;
public void processActivate(EntityPlayer par5EntityPlayer, World world, int par2, int par3, int par4) {
[color=red] if (this.visitor1 == "none") {
this.visitor1=par5EntityPlayer.getEntityName();
}[/color]
//comprueba si el bloque contiguo es la bandera encendida. Ejemplo con dirt
if (world.getBlockId(par2 -1, par3, par4) == Block.glowStone.blockID)
{
[color=red] if (this.visitor1 == par5EntityPlayer.getEntityName()){[/color]
//aqui comprobamos si el jugador tiene la bandera, en este caso lo hago con un diamante.
if( par5EntityPlayer.inventory.getStackInSlot(par5EntityPlayer.inventory.currentItem) != null)
{
String item = par5EntityPlayer.inventory.getStackInSlot(par5EntityPlayer.inventory.currentItem).toString();
String check = new ItemStack(Item.diamond).toString();
if( item.equals(check) )
{
// si tiene el diamante
flag = flag + 1;
par5EntityPlayer.addChatMessage("You stored the flag.");
par5EntityPlayer.addChatMessage("Captured flags: " + flag);
par5EntityPlayer.inventory.consumeInventoryItem(Item.diamond.itemID);
world.notifyBlockChange(xCoord, yCoord, zCoord, 2);
if (flag == 10) {
//Aqui te daria l0 pokeballs
par5EntityPlayer.addChatMessage("You have obtained 10 Pokeballs");
}
if (flag == 50) {
//Aqui te daria el pal pad
par5EntityPlayer.addChatMessage("You have obtained a Pal Pad");
}
if (flag == 100) {
//Aqui te daria 5 caramelos raros
par5EntityPlayer.addChatMessage("You have obtained 5 Rare Candy");
}
if (flag == 200) {
//Aqui te daria el mapa del subsuelo
par5EntityPlayer.addChatMessage("You have obtained The Underground Map");
}
if (flag == 500) {
//Aqui te daria unna masterball
par5EntityPlayer.addChatMessage("You have obtained a Masterball");
}
if (flag == 1000) {
//Aqui te daria el rango platino
par5EntityPlayer.addChatMessage("Congratulations, you have reached the Platinum Flag");
}
}
}
else
{
// si no lo tiene
par5EntityPlayer.addChatMessage("Welcome back " + this.visitor1);
par5EntityPlayer.addChatMessage("Captured flags: " + flag);
world.notifyBlockChange(xCoord, yCoord, zCoord, 2);
if (flag < 10){
par5EntityPlayer.addChatMessage("Next reward: 10 Pokeballs (10 flags)");
} else {
if (flag < 50){
par5EntityPlayer.addChatMessage("Next reward: Pal Pad (50 flags)");
} else {
if (flag < 100){
par5EntityPlayer.addChatMessage("Next reward: 5 Rare Candy (100 flags)");
} else{
if (flag < 200){
par5EntityPlayer.addChatMessage("Next reward: Underground Map (200 flags)");
} else {
if (flag < 500){
par5EntityPlayer.addChatMessage("Next reward: Masterball (500 flags)");
} else{
if (flag < 1000){
par5EntityPlayer.addChatMessage("Next reward: Plantinum Flag (1000 flags)");
} else {
par5EntityPlayer.addChatMessage("Next reward: None");
}
}
}
}
}
}
}
} else{
par5EntityPlayer.addChatMessage("Welcome to the " + this.visitor1 + " PC´s");
par5EntityPlayer.addChatMessage("Captured flags: " + flag);
world.notifyBlockChange(xCoord, yCoord, zCoord, 2);
}
}
else {
par5EntityPlayer.addChatMessage("Systems are disabled");
}
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.visitor1 = nbt.getString("visitor1");
this.flag = nbt.getInteger("flag");
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setString("visitor1", visitor1);
nbt.setInteger("flag", flag);
}
}
Thx for your help