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

blockFalling


Stroam
 Share

Recommended Posts

I found the class that gravel and sand both extend called the BlockFalling. I was wondering how to make all blocks able to fall. I've seen a few mods that a add gravity to all blocks in minecraft and wonder how you would go about doing that short of remaking every block in minecraft and adding the BlockFall class to it.

You don't need to point out what's wrong with the programmer. I already know. Now what's wrong with the code?

Link to comment
Share on other sites

Easy way:

There isn't one.

 

Clean way:

Make your own block, which extends BlockFalling, and recreate every vanilla block you want to fall.

 

Hard way:

ASM into the Block class's updateTick function to add a static function call to your code.  Your code then replicates the effects of BlockFalling.

 

Best way:

Don't.  You would need to think long and hard about how you'd go about making a ceiling so the entire world doesn't collapse out of hand as soon as you load it.  Which blocks should fall, which ones shouldn't, what classes are they, and so on.  I've looked at this myself and went, "ok, if I modify [this block] that means I'd have to modify [block, block, and block].  If I do that, then [another list] needs to be modified."  It was a cascade failure on how many alterations I'd have to make and determined it wasn't worth it and kept it at just stone (which I did via "clean" then ASM'd BlockFalling to have a little extra tidbit so it doesn't make towers, but instead pyramids).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Very informative. I too see each point you've listed. I was thinking of not every block falling like sand but to check supporting blocks around it. Just simple checks like cobblestone would check left, right, front back and then down one from each of those locations.  so that arches would still work and have different rules for each material because I don't want trees instantly falling. Bedrock of course would not fall. If I remake all the blocks then cross mod support would be more effort than people would be willing to put in. So ASM does sound like it would be the best way to go. But that is a lot of checks to do without using multithreading. I have not used ASM in two years, and never have done it for minecraft or multithreading. Is it possible to setup multithreading in ASM for minecraft? I am researching this question but any input would be helpful.

You don't need to point out what's wrong with the programmer. I already know. Now what's wrong with the code?

Link to comment
Share on other sites

ASM carefully.  Use new blocks whenever possible (you can use the various worldgen events to examine and replace blocks as needed as well as remove and replace crafting recipes).  Write a static class with helper functions, taking world, blockpos, and any relevant properties so that the code only has to be written once and all support-required blocks use it (support distance can be passed as a paramter based on the block, so if you ASM the call into Blocks.stone, it passes 5, whereas Blocks.wood_plans passes 3, and so on).

 

You will have to figure out how non-same blocks support each other.  Can jungle planks support oak?  Can smooth stone support cobble?  Can monster egg support smooth stone?

 

And the biggest hint:

You will need to always check that support exists 1 layer below.  If cobblestone only checks that it's north neighbor is cobble, then two floating cobble will support each other.  This last block needs to merely have a solid top surface (as it is supporting the block above, and the block above is supporting the adjacent block).

 

Lastly:

You'll need to take shortcuts somewhere.  I'll leave you to figure out which shortcuts you should take, so that you understand them.  But at some point you will have to sacrifice better physics for better performance or ease of coding.

 

And oh yeah:

Avoid try...catch in any code called from onUpdate / updateTick.  You can cheat the compiler by letting the ASM-inserted function throw exceptions.  The compiler never sees that it's being called and so never enforces the try...catch, and as long as the code cannot throw the exception, it can't crash.  That is: "throws" does not exist as part of a function signature.

 

(I had to do this in one spot, because I had to Reflect in a class definition.  But the try...catch around the reflection code slowed the game down massively, but as I had defined the class and its constructor, it could never cause an exception, so I told the class I was ASMing into to handle it....except that it doesn't and the compiler doesn't give a damn).

 

This video is kind of bunk, but it shows off what I did.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

upon further consideration for each block to have a different set of rules and still be compatible with other mods I would have to modify the class of every vanilla block and with no native multithreading support that I know in the minecraft code this would take a considerable amount of work, would not be easy to maintain, and most likely would be riddled with bugs and performance impacts. And as you pointed out you can do this with just a few block which would drastically cut down on the size of the project but would defeat the purpose I was intending. I wanted digging caves larger than 2x2  to require supports so collapses didn't happen, and building large houses with big roofs to again require support structures or certain designs to stop from falling in, and  have floating islands be impossible.

 

As for checks it would be check the 4 paths(N,S,W,E) and as long as one of the paths passed (check out one AND down one, for cobblestone) block would not fall. Each block would have an associated check tree that would return true as long as you reach the end of one of the branches, and if it fell would trigger the checks for all blocks with 1 radius around it which would mean a large island built on one pillar would crash any system if the pillar was destroyed. Also I would not code it to check very far. If you built a tall pillar of cobblestone and put one on the side it would go through the same check as earlier mentioned and would not need to check down the entire pillar.

 

The clean way would be to add boolean isSupport, and method isSupported(), to every block you didn't want to float. I would not want to undertake a project like this without help.

You don't need to point out what's wrong with the programmer. I already know. Now what's wrong with the code?

Link to comment
Share on other sites

You can pull it off.  You just have to decide which battles are worth fighting.

 

Planks and Logs have their own classes (BlockWood and BlockOldLog/BlockLog) as does dirt, stone, grass.  Cobblestone does not.

 

I completely replaced stone and made it drop my own cobblestone block (circumventing the need to ASM cobblestone) and left everything else alone (trees aren't constructed in a manner that is easy to run support rules for, and planks are primarily a player construction block and I was mostly dealing with the "dig out a room" aspect).

 

What blocks are either too expensive or too weird for the player to decide to build the house out of it?  What's too hard to modify and is an allowable loss in realism?  Even at partial support, you'll find people who go "this is awesome" and won't subvert the rules too much because they like the mechanic and getting around it feels like cheating ("pfft, roof of furnaces, lol").

 

This class will also help in your endeavors:

https://github.com/shieldbug1/S1Library/blob/master/src/main/java/com/shieldbug1/lib/asm/ASMHelper.java

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I have seen it was pulled off in the past, and with enough time I could pull it off, it is the time I'm lacking. 90% of my week is taken up with working 40+ hrs on top of college classes. which only gives me 8 to 16 scattered hours during the week to work on it. I would love to see it in action and still work with mods like carpenter's blocks, mariculture, and tinkerConstruct but that's more work than I can devote at this time. Thanks for the class though. I will bookmark it in case I get more time in the future.

You don't need to point out what's wrong with the programmer. I already know. Now what's wrong with the code?

Link to comment
Share on other sites

[me=Draco18s]salute[/me]

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

One thing to be aware of is that some vanilla code compares against the instance of the block (e.g. Blocks.ladder) instead of checking for instanceof (e.g. instanceof BlockLadder). This means that extending a class and replacing the vanilla blocks may not work fully as expected. I suspect that many mods are also coded that way.

 

If you want to really do a wholesale change to most blocks and have them work correctly, you need to actually make the built-in Blocks instance take on the value of your block. Since Blocks instances are static and final, you'll need to use techniques like reflection or ASM.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

I think this way would work, but it could be inappropriate.

1. Subscribe to PopulateChunkEvent.Post and BlockEvent.BreakEvent, PlaceEvent and MultiPlaceEvent.

2. When a chunk/block is populated/changed, remove the block or nearby block and spawn falling entity under some condition. You would have to create your own falling entity.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

I think this way would work, but it could be inappropriate.

1. Subscribe to PopulateChunkEvent.Post and BlockEvent.BreakEvent, PlaceEvent and MultiPlaceEvent.

2. When a chunk/block is populated/changed, remove the block or nearby block and spawn falling entity under some condition. You would have to create your own falling entity.

 

I am trying to accomplish something similar. I think I can see what you mean. What kind of performance impact would this have? Would this be viable to replace every block on the game with custom ones?

QUACK!

Link to comment
Share on other sites

Performance would not be a problem, since you just have to check nearby blocks and make them fall when some changes were made.

What I cannot guarantee is whether the way could cover every circumstances or not.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

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



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.