IceMetalPunk Posted December 10, 2015 Posted December 10, 2015 I have a tile entity which updates a value in its corresponding block based upon the weather. This value is returned in the isProvidingWeakPower() method. Everything works, except the adjacent redstone requires an additional block update before it updates its state. I'd rather it update the signal strength immediately. I'm trying to use the World.scheduleBlockUpdate() method to trigger a block update and get the redstone signal updated, but it doesn't seem to work. This is what I'm using now, as the TileEntityWeatherDetector.java code: package com.IceMetalPunk.weatherworks; import net.minecraft.block.Block; import net.minecraft.tileentity.TileEntity; public class TileEntityWeatherDetector extends TileEntity { private int outputLevel=0; public void updateEntity() { if (this.worldObj==null) { return; } int temp=this.outputLevel; if (this.worldObj.isThundering()) { this.outputLevel=15; } else if (this.worldObj.isRaining()) { this.outputLevel=7; } else { this.outputLevel=0; } if (this.outputLevel!=temp) { BlockWeatherDetector myBlock=(BlockWeatherDetector)(this.worldObj.getBlock(this.xCoord, this.yCoord, this.zCoord)); myBlock.updateOutput(this.outputLevel); this.worldObj.scheduleBlockUpdate(this.xCoord, this.yCoord, this.zCoord, myBlock, myBlock.tickRate(this.worldObj)); } } } I also tried using two nested for() loops to schedule a block update at all adjacent blocks, and that didn't work, either. I'm sure I'm just misunderstanding how to schedule updates; how can I make the adjacent redstone dust change its signal strength immediately after the block updates its output? Quote Whatever Minecraft needs, it is most likely not yet another tool tier.
IceMetalPunk Posted December 10, 2015 Author Posted December 10, 2015 Things just keep getting weirder with this bug. I left the update scheduling in as above, but I figured I'd also add a direct notification to the surrounding blocks, like this: this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, myBlock); This is definitely getting called, but it didn't help. So for debugging, I put two of these blocks next to each other and put some console output in their onNeighborBlockChange() method. The output never gets logged. Meaning somehow, even with the line of code above, it's still not even calling the onNeighborBlockChange() method. I don't understand how this is possible. Does anyone know? Quote Whatever Minecraft needs, it is most likely not yet another tool tier.
IceMetalPunk Posted December 11, 2015 Author Posted December 11, 2015 After some debugging, I got it working...though I have no idea how. It looks identical to the code I tried before, but now it works when it didn't then. I don't know. For anyone's future reference, this is the working code I'm using: package com.IceMetalPunk.weatherworks; import net.minecraft.block.Block; import net.minecraft.tileentity.TileEntity; public class TileEntityWeatherDetector extends TileEntity { private int outputLevel=0; public void updateEntity() { if (this.worldObj==null || this.worldObj.isRemote) { return; } int temp=this.outputLevel; if (this.worldObj.isThundering()) { this.outputLevel=15; } else if (this.worldObj.isRaining()) { this.outputLevel=7; } else { this.outputLevel=0; } if (this.outputLevel!=temp) { BlockWeatherDetector myBlock=(BlockWeatherDetector)(this.worldObj.getBlock(this.xCoord, this.yCoord, this.zCoord)); myBlock.updateOutput(this.outputLevel); this.worldObj.scheduleBlockUpdate(this.xCoord, this.yCoord, this.zCoord, myBlock, myBlock.tickRate(this.worldObj)); this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, myBlock); } } } Quote Whatever Minecraft needs, it is most likely not yet another tool tier.
larsgerrits Posted December 11, 2015 Posted December 11, 2015 Two things are different: 1) You are now only doing things on the server side 2) You added a call to World#notifyBlocksOfNeighborChange , which is probably what made it work. Quote Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
IceMetalPunk Posted December 11, 2015 Author Posted December 11, 2015 As I said above, I had added the notifyBlocksOfNeighborChange() call before and it still didn't work. I didn't notice I hadn't checked isRemote before...perhaps the combination is what finally fixed it. Though, if I were running it on both the client and server, but still calling the neighbor change notification method, would that cause it to not update its neighbors somehow? Quote Whatever Minecraft needs, it is most likely not yet another tool tier.
Recommended Posts
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.