Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

TileEntity and onNeighborChanged


Cinderous
 Share

Recommended Posts

Dear folks, I have block that is a tile entity, this tile entity utilizes BuildCraft api to configure sides of the block to become compatible as a power receptor. The pipe works fine when its connected to the pipe and that side is configured "ON", and it works fine if I configure it "OFF", but the problem is the actual Pipe that connects to that side doesn't render that is is no longer connected. If I close my server and reopen it, the pipe correctly renders because it knows that side is no longer valid to be connected to.

 

While the server is running, if you want the pipe to show correctly based on the tile entity's state you must destroy the pipe and replace it. The pipe has a method to detect when neighbor blocks change and will connect/disconnect accordingly. The problem is its not the block changing, its the tile entity. Without changing the pipe which will detect the changed block, how can I force my tile entity to tell the server that the block has changed. Does this make sense? If the server knew the block changed, not the tile entity, this would work fine.

Link to comment
Share on other sites

It's a world problem. Not kidding!:P

 

The method which updates the neighbours is in World, and you can call this from within your TileEntity:

worldObj.notifyBlockChange(xCoord, yCoord, zCoord, worldObj.getBlockId(xCoord,yCoord,zCoord);

 

What I would do (if possible) is determining whether it's on or off with the block's metadata. That way, when you change the on/off state, you can automatically notify the neighbors (by using the right flag in worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, meta, flag)).

 

//Edit: Forgot the word Metadata in the method name!

Author of PneumaticCraft, MineChess, Minesweeper Mod and Sokoban Mod. Visit www.minemaarten.com to take a look at them.

Link to comment
Share on other sites

MineMaarten, this worked perfect.

 

My problem now is it seems like the server is having issues or my client is having issues. I don't drop in FPS, but i get these weird "frame skips" like im lagging. I think its because my block is saying tis changed too frequently and its causing a lot of useless checks or something. How can i make it do notifyBlockChange only when the invetory is changed? onInvetoryChanged() seems to do other stuff not related to my problem.

 

Will i just have to add the notifyblock to all the methods that move an itemstack into or out of a slot or is there a simple solution I can put into updateEntity to do this with less code everywhere?

Link to comment
Share on other sites

The invetory change and blockchange notify can be optimized if you help. But asking around the lag is most likely from the initlization/configuration process of getting information from the item and applying it to specific features of the tile entity.

 

I don't need it to be quick, i just dont want it to bog down for a few seconds while it configures everything whenever a item changes. I guess i need to setup a custom tick handler and do each step after so many ticks, right? That should make it smoother...i Think

Link to comment
Share on other sites

it seems like the server is having issues or my client is having issues.

It's probably unrelated to the problem, but only change the block meta or notify only on the server. The server then automatically will update the client.

 

I think its because my block is saying tis changed too frequently and its causing a lot of useless checks or something. How can i make it do notifyBlockChange only when the invetory is changed? onInvetoryChanged() seems to do other stuff not related to my problem.

You might be right here. I guess (not sure!) onInventoryChanged() is being called multiple times when the inventory changed and if every time causes the neighbors to update that can cause a lag spike yes.

 

Will i just have to add the notifyblock to all the methods that move an itemstack into or out of a slot or is there a simple solution I can put into updateEntity to do this with less code everywhere?

I would go for the latter. You don't need a TickHandler first of all, you already have one in your TileEntity (updateEntity()). If speed is not really problem, you can set something up that checks if the on/off state changed every so often and if it has changed update the neighbors:

private int ticksExisted;

public void updateEntity(){
    if(!worldObj.isRemote && ticksExisted % 20 == 0){ //check every second
          if(check if changed){
                  worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, newMeta, 3);
          }
    }
}

Author of PneumaticCraft, MineChess, Minesweeper Mod and Sokoban Mod. Visit www.minemaarten.com to take a look at them.

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
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.

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • I cannot find java 8 320 there
    • I often say to people "Run the jar file manually and post the output here" and they don't know how to do this. So here is a step by step guide for beginners with examples and explanations so that everyone understands it    First you need to know what a cmd, also called command prompt or command line is. The cmd is this black box where you can put commands in that only hackers use if they want to hack something  Here's a picture of the cmd on Windows How to open cmd: On Windows click on the Windows icon, type "cmd" and press enter. On mac press Command-space to launch Spotlight and type "Terminal", then double-click the search result     Now we know how to open cmd, but how do we run the .jar file? First we need to navigate to the drive the jar file is in The we need to navigate to the folder the jar file is in Last we need to tell java to run the jar file Let's start  (And don't forget to press enter between the steps to run the command you entered)     Step 1 To navigate to a drive on windows open the command prompt and type the name of the drive the file is in. If you're on mac you can skip this step Example:     Step 2 Navigate to the file. Type cd and the path in quotation marks. Example:     Step 3 Now we need to tell java to run the file. The command for this is java -jar nameOfTheFile.jar Example:     How does it work? There are many commands that you can type into command prompt. Some are from the cmd itself (drive: and cd) and some from other applications (java). All these commands take options/arguments, these are separated by spaces.     Now you've run the .jar file manually. Mostly you do this to get the error message, so just copy the error message form the cmd with Ctrl+C I hope this guide helped you  If you have any suggestions or questions, please tell me by answering to the topic!
    • you can simply create a new instance and store it in a final field, then override addAdditionalSaveData and readAdditionalSaveData to serialize and deserialize the Inventory
    • How can I use code from a library with other code? Do you usually make it in a similar way to how you make it in Java? (In Forge version 1.18.1-39.0.59)
  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.