Jump to content

Recommended Posts

Posted

And I would like to remind you that a dedicated server has a completely separate jar file. Those @SideOnly annotations are what Mojang uses to differentiate what should be compiled where.

 

And although you never stated item-stacks synced nbtdata you did say the reason I didn't have a problem was because it was an itemstack instead of a tile-entity. Furthermore, if single-player is just multi-player with one user why wouldn't my mod still work with multiple users? I already said the server and client stay in sync just fine, but I'll have to test it sometime.

 

@TheMoleTractor and don't forget the tile-entity already has a built in reference to the coordinates, world, and the block. Metadata too.

 

 

Posted

@Mox You know what? I give up :P I am making no sense to myself anymore. Give me a day to figure out what I mean and I might be able to explain it coherently.

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Posted

So as it turns out...I am not sure if this the best way to do but it seems to have worked.

 

I did some enticing research into Packets (I still have some understanding to do...but I'm well on my way) but ultimately found a forge tut (http://www.minecraftforge.net/wiki/Synchronizing_tile_entities for this interested) that mentioned a certain line of code:

world.markBlockForUpdate(x, y, z);

 

Putting this at the end of my updateTick() for growing updates the texture. No need for packets? Humph. Any thoughts?

 

EDIT:

Also, on an end note...I am have horrid lag issues (Java space heaps) in the updateTick() method when I try to search for a certain block in a given radius.

    	for(int i = 0; i <= 5; i++)
    	{
    		for(int j = 0; j <= 5; i++)
    		{
        		if(world.getBlockId(x + i, y, z + j) == Base.blockPhotoStick.blockID)
        			staffFound = true;
        		if(world.getBlockId(x + i, y, z - j) == Base.blockPhotoStick.blockID)
        			staffFound = true;
        		if(world.getBlockId(x - i, y, z + j) == Base.blockPhotoStick.blockID)
        			staffFound = true;
        		if(world.getBlockId(x - i, y, z - j) == Base.blockPhotoStick.blockID)
        			staffFound = true;
    		}
    	}
    	if(!staffFound)
    		return;

 

I am sure this entirely inefficient...

Posted

You're checking 100 blocks every tick?

 

Why not just check in

onNeighborBlockChange

?

 

Furthermore, you ought to break out of the nested for loops as soon as the staff is found, as well.

Posted

You're checking 100 blocks every tick?

 

Why not just check in

onNeighborBlockChange

?

 

Furthermore, you ought to break out of the nested for loops as soon as the staff is found, as well.

 

Yea I knew it seemed unnecessary. Does onNeighborBlockChange() check often? Say if the block/tile entity I am looking for it already there?

 

I'll toss in a while(!staffFound) around it and hope that helps.

Posted

Tossing a

while (!staffFound)

around it would move you from 100 blocks per tick to infinity blocks per tick. Hardly a performant decision.

 

onNeighborBlockChange()

checks whenever a neighbouring block changes, no more, no less.

 

Could you concisely describe what you are trying to achieve?

Posted

Tossing a

while (!staffFound)

around it would move you from 100 blocks per tick to infinity blocks per tick. Hardly a performant decision.

 

onNeighborBlockChange()

checks whenever a neighbouring block changes, no more, no less.

 

Could you concisely describe what you are trying to achieve?

 

Sorry, I'm tired and have not had my coffee yet.

 

Essentially I have a plant that I want to grow if there is a certain block in a certain radius. And only grow if that criteria is met.

 

My specific example is I want to check around my BlockSapphireCrop for a BlockCropStaff in a radius anywhere from 1-5 blocks away.

 

Is onNeighborBlockChange() called when the block is placed? Or only when a neighboring block changes.

Posted

Do the reverse; use

onBlockAdded

on the

BlockCropStaff

that must be within the radius of the

BlockSapphireCrop

.

 

I do want other crops to work with this as well, but I should be able to use an or operator within the onBlockAdded. This would also require a call to the

BlockCropStaff

class from my updateTick() method in

BlockSapphireCrop

, correct?

Posted

Hint: The quote functionality is useful mostly for quoting posts that are not the one just above, or for selectively quoting part of a post :)

 

Also, the best way to go about it depends on the functionality you desire.

 

The instance of the

BlockCropStaff

holds information about the general

BlockCropStaff

. Depending on how many levels of growth your

BlockSapphireCrop

needs to use the metadata for, you could use a single bit as a flag to indicate whether a

BlockCropStaff

is within range. Alternatively, you could use NBT.

 

Pseudopseudocode for the

onBlockAdded

code of

BlockCropStaff

:

 

Array<Block> crops = { MainMod.blockSapphireCrop, MainMod.blockRubyCrop, MainMod.blockAmethystCrop };

for (int x = -5; x <= 5; ++x) {
    for (int z = -5; z <= 5; ++z) {
        Block block = world.getBlock(x, y, z);

        // Assuming all your crops inherit from BlockGemCrops
        if (block instanceof BlockGemCrops) {

            // Assuming the most significant bit of the crop metadata indicates a staff in range
            int metadata = world.getBlockMetadata(x, y, z);
            world.setBlockMetadataWithNotify(x, y, z, metadata | 0x7, 2);
        }
    }
}

Posted

NOTE: Sorry, I am new to the forums. I'll be a little more sparse with quoting.

 

Ok so I got it partially working, I had the staff check for the TileEntitySapphireCrop, if found, it calls a setStaffFound() inside the TileEntity and sends true. On the other end, the BlockSapphireCrop, in the updateTick() I have a call to a getStaffFound() function where the "if staff is found" boolean variable is stored.

 

The BlockStaff has updateTick() with this in it:

public void updateTick(World world, int x, int y, int z, Random rand)
{	
        //Checks for grow-able crops in the area
    	for(int j = -5; j <= 5; j++)
    	{
    		for(int k = -5; k <= 5; k++)
    		{
    			 TileEntity te = world.getBlockTileEntity(x + j, y, z + k);
    			 
    			 if(te != null)
    			 {
    				 if(te instanceof TileEntitySapphireCrop)
    				 {
    					 ((TileEntitySapphireCrop)te).setStaffFound(true);
    				 }
    			 }
    		}
    	}
}

 

It seemed to work some but not others. I know it is checking the correct area (I did a world.setBlock with the same for loops to be sure) but I have a check in the updateTick() of my BlockSapphireCrop that prints a message if the staff is not found and it appears to be not seeing some of the crops.

 

EDIT: So what I think is happening (after a bit more testing) is that the crop is ticking before the staff has ticked and found the crop to notify the tile entity that it should grow. Not a huge problem because it just slows down the initial growth process which is ok.

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.