Jump to content

blockFalling


Stroam

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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