-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Placing grass block over grass #12
Comments
What do you think about adding a method to Block that gets called when a block is placed at the top/bottom/left/right of it? |
You'll want to look at the Block class, specifically the onPlace method which is called when a block is placed. From that method you can check the tiles around you. |
But is it the best way to just check if the placed block is a grass block and then check if the block under is also a grass block? (everything in onPlayer) |
Regarding @AppPhil 's last statement, this seems like a function you'd eventually apply to many blocks, so it might be best to write more reusable code for it instead of hard coding each. One possibility could be a This could be used in other cases such as say lava colliding with water. Use this function for each direction, specifying water as the replace type and stone as the new type. Bam, water touching lava is turned into stone with a few simple calls. You could then expand on it if you wanted, adding the ability to play sound when blocks are replaced, or allow blocks to make the replacements happen on random timed intervals instead of instantly. You could have a slowly spreading block, e.g. maybe grass spreading slowly to nearby dirt or a corrupt poison spreading. I'm not fully sure how your block system works yet, but I'm sure the general idea can be implemented. |
Good idea, I don't see a problem with adding this functionality. It would still need to be used within |
When I create a class GrassBlock that extends Block and I use this for the grass block in the BlockManager all the blocks are black under the grass blocks. I don't know why I just got a GrassBlock class looking like this: |
It looks like this: Hope you can help me. |
Very strange. It must be something to do with initializing the block once it's set in the chunk. I will need to look at the Chunk code to see, but I'm pretty sure the bug is originating somewhere in there. Edit: I believe it may be coming from here, but I am not able to test it at the moment. If you comment out the code from line 257-259, it may fix this issue, but it will also break torches that are placed when they are loaded from a saved world. If commenting out those lines fixes the issue, we may need to create a separate |
You're right. Commenting out those lines fixes the issue and it breaks torches that are placed. But I'm not sure what you mean how to fix that. |
Does it break the torches when you place them in the game, when the world is loaded, or both? |
Only when the world is loaded. |
Wait I found out that it happens with the latest version that's here on GitHub so it weren't my changes that did that. |
What do you mean exactly? What part of the problem was happening in the last version? |
I think the light is broken after loading a world. |
Interesting. I will have to take a look, but if I remember accurately it was generating the light correctly. As for the problem on hand however, the code that you commented out was done so that other blocks would have special properties initialized. In this case, the only block that this was applied to was the |
Yes now it works with the latest version from GitHub. I don't know what was wrong there. Sorry for that. |
Great. Once it's all ready be sure to submit a pull request! |
Now I've done what you said but after loading the world the torches only light up one block (their position) and not the blocks near them. |
Can you commit your code to your forked repository so I can take a look at it? |
Here it is: https://github.com/AppPhil/TerraLegion |
Okay so from that commit it looks like you only created the |
Wait. That replacing worked for me. I think I have not commited everything. Oh yes wait I will update... |
Here are the other changes: https://github.com/AppPhil/TerraLegion/commit/7b51790feb3728f790b17fc9090a057b879a7d8c |
Strange that the light still doesn't generate correctly. If you want to do some investigative work you can debug from the point that the |
Are you sure with LightUtils.extinguishLight? Because that's called in the onBreak method. |
Oh my bad, yes I meant the |
While debugging I found out that the process gets stopped here:
In the if-thing the lightValue is 0.95 and posChunk.getLightValue(posChunkX, posChunkY is 1.0 Maybe this does something wrong I don't know:
|
I think it might be not working fine because Chunk.getLightValue() return 1.0 for positions of LightBlocks so the applyLight() method thinks there is already light. But I reallly don't know how to fix that. I tried it for hours today... |
The lighting algorithm is a very hard algorithm to debug because it's recursive. You have to keep track of what |
I found out that the light is only not working after loading a world when it is placed in a topChunk. |
Interesting. The only different thing, light related, that has to do with the top chunk is that the "sun" lighting is applied. So it may have to be with that. One case that would be an issue is when the lighting is applied, it won't cast it if the light on the block is higher than the light trying to be applied. This is the case you found when debugging. The strange thing is, a block shouldn't have any light value when loaded. The light is applied by the "sun" or torches. Let's continue this conversation in #10. |
When you place a grass block over another grass block the lower one doesn't gets to normal dirt. But maybe that is planned like this.
The text was updated successfully, but these errors were encountered: