Jump to content

Tile Entity Problem


pollitoyeye

Recommended Posts

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

Link to comment
Share on other sites

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

Tried this

public void sendChangeToServer(){
    ByteArrayOutputStream bos = new ByteArrayOutputStream(;
    DataOutputStream outputStream = new DataOutputStream(bos);
    try {
        outputStream.writeInt(flag);
        outputStream.writeChars(visitor1);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
               
    Packet250CustomPayload packet = new Packet250CustomPayload();
    packet.channel = "GenericRandom";
    packet.data = bos.toByteArray();
    packet.length = bos.size();

    PacketDispatcher.sendPacketToServer(packet);
}

but also not working ;(

Link to comment
Share on other sites

You also need a packet handler.

 

https://github.com/Draco18s/Artifacts/tree/master/draco18s/artifacts/network

 

And set up your mod as a network mod:

 

@NetworkMod(clientSideRequired = true, serverSideRequired = false,
        clientPacketHandlerSpec = @SidedPacketHandler(channels = {"GenericRandom"}, packetHandler = PacketHandlerClient.class),
        serverPacketHandlerSpec = @SidedPacketHandler(channels = {"GenericRandom"}, packetHandler = PacketHandlerServer.class))

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

But 1 thing i dont understand, why the variable gets saved but it doesnt recognise thath im the player of the variable even with the same name...?

 

Look over my mod (the display pedestal linked above) as my block works in the exact way that you desire.  Only the owner can open it (if owner is a blank string, then the first person to interact with it is the owner) and only the only can break it (or explosions, I specifically allow it to be destroyed by explosions).

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

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.