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

    • no, the way he use it's the way to go
    • Minecraft 1.16 requires java 8-15, you currently using java 16, downgrade your java to 8-15 and the problem should be fixed.
    • Hi So Im trying to set up a Server for 1.16.4 now but when I go to launch it doesn't work, Im using the Life in the Village 2 server pack thats already pre-made but it still wont launch no matter what I try. If I can get some help that would be great thanks. D:\Modded Mc\LITV2-Serverpack-1.28a\LITV2-Serverpack-1.28a>java -Xmx4G -jar forge-1.16.5-36.2.4.jar nogui 2021-11-29 13:43:08,050 main WARN Advanced terminal features are not available in this environment [13:43:08] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher running: args [--gameDir, ., --launchTarget, fmlserver, --fml.forgeVersion, 36.2.4, --fml.mcpVersion, 20210115.111550, --fml.mcVersion, 1.16.5, --fml.forgeGroup, net.minecraftforge, nogui] [13:43:08] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher 8.0.9+86+master.3cf110c starting: java version 16.0.2 by Oracle Corporation Exception in thread "main" java.lang.IllegalAccessError: class cpw.mods.modlauncher.SecureJarHandler (in unnamed module @0x4de5031f) cannot access class sun.security.util.ManifestEntryVerifier (in module java.base) because module java.base does not export sun.security.util to unnamed module @0x4de5031f at cpw.mods.modlauncher.SecureJarHandler.lambda$static$1(SecureJarHandler.java:41) at cpw.mods.modlauncher.api.LamdbaExceptionUtils.uncheck(LamdbaExceptionUtils.java:95) at cpw.mods.modlauncher.SecureJarHandler.<clinit>(SecureJarHandler.java:41) at cpw.mods.modlauncher.Launcher.lambda$new$6(Launcher.java:55) at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708) at cpw.mods.modlauncher.api.TypesafeMap.computeIfAbsent(TypesafeMap.java:52) at cpw.mods.modlauncher.api.TypesafeMap.computeIfAbsent(TypesafeMap.java:47) at cpw.mods.modlauncher.Environment.computePropertyIfAbsent(Environment.java:62) at cpw.mods.modlauncher.Launcher.<init>(Launcher.java:55) at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) at net.minecraftforge.server.ServerMain$Runner.runLauncher(ServerMain.java:63) at net.minecraftforge.server.ServerMain$Runner.access$100(ServerMain.java:60) at net.minecraftforge.server.ServerMain.main(ServerMain.java:57) D:\Modded Mc\LITV2-Serverpack-1.28a\LITV2-Serverpack-1.28a>pause Press any key to continue . . .  
    • Still waiting on the issue.
    • Registering in static fields isn't ideal. You have a method that registers your deferred register to the event bus, right? leave your RegistryObject fields as non-final and empty, and set their reference in that method, right after registering the deferred register on the bus.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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