Jump to content

Recommended Posts

Posted

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

Posted

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

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 ;(

Posted

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.

Posted

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.

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

    • i managed to fix it by reinstalling the modpack and re-add all the extra mods I've had previously.
    • Ah, it appears I spoke too soon, I still need a little help here. I now have the forceloading working reliably.  However, I've realized it's not always the first tick that loads the entity.  I've seen it take anywhere from 2-20ish to actually go through, in which time my debugging has revealed that the chunk is loaded, but during which time calling  serverLevelIn.getEntity(uuidIn) returns a null result.  I suspect this has to do with queuing and how entities are loaded into the game.  While not optimal, it's acceptable, and I don't think there's a whole ton I can do to avoid it. However, my concern is that occasionally teleporting an entity in this manner causes a lag spike.  It's not every time and gives the appearance of being correlated with when other chunks are loading in.  It's also not typically a long spike, but can last a second or two, which is less than ideal.  The gist of how I'm summoning is here (although I've omitted some parts that weren't relevant.  The lag occurs before the actual summon so I'm pretty confident it's the loading, and not the actual summon call). ChunkPos chunkPos = new ChunkPos(entityPosIn); if (serverLevelIn.areEntitiesLoaded(chunkPos.toLong())) { boolean isSummoned = // The method I'm using for actual summoning is called here. Apart from a few checks, the bulk of it is shown later on. if (isSummoned) { // Code that runs here just notifies the player of the summon, clears it from the queue, and removes the forceload } } else { // I continue forcing the chunk until the summon succeeds, to make sure it isn't inadvertently cleared ForgeChunkManager.forceChunk(serverLevelIn, MODID, summonPosIn, chunkPos.x, chunkPos.z, true, true); } The summon code itself uses serverLevelIn.getEntity(uuidIn) to retrieve the entity, and moves it as such.  It is then moved thusly: if (entity.isAlive()) { entity.moveTo(posIn.getX(), posIn.getY(), posIn.getZ()); serverLevelIn.playSound(null, entity, SoundEvents.ENDERMAN_TELEPORT, SoundSource.NEUTRAL, 1.0F, 1.0F); return true; } I originally was calling .getEntity() more frequently and didn't have the check for whether or not entities were loaded in place to prevent unnecessary code calls, but even with those safety measures in place, the lag still persists.  Could this just be an issue with 1.18's lack of optimization in certain areas?  Is there anything I can do to mitigate it?  Is there a performance boosting mod I could recommend alongside my own to reduce the chunk loading lag? At the end of the day, it does work, and I'm putting measures in place to prevent players from abusing the system to cause lag (i.e. each player can only have one queued summon at a time-- trying to summon another replaces the first call).  It's also not an unacceptable level of lag, IMO, given the infrequency of such calls, and the fact that I'm providing the option to toggle off the feature if server admins don't want it used.  However, no amount of lag is ideal, so if possible I'd love to find a more elegant solution-- or at least a mod recommendation to help improve it. Thanks!
    • When i start my forge server its on but when i try to join its come a error Internal Exception: java.lang.OutOfMemoryError: Requested array size exceeds VM limit Server infos: Linux Minecraft version 1.20.1 -Xmx11G -Xms8G
    • Also add the latest.log from your logs-folder
  • Topics

×
×
  • Create New...

Important Information

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