Home > Java > body text

Minecraft structure overwrites existing blocks 1.20

PHPz
Release: 2024-02-22 13:00:09
forward
747 people have browsed it

The java Q&A topic brought by php editor Youzi will give you detailed answers to the questions about structures covering existing blocks in Minecraft. In the game, how to effectively operate and utilize this function will directly affect the game experience and fun of playing. Through the interpretation and guidance of this article, I hope it can help you better master this technique and achieve better results and experience in the game.

Question content

I've been trying to find online a way to modify existing blocks and their properties in Minecraft Fabric, but all I can find is how to create new blocks. Any versions I've found are lower than 1.20.

I can't actually find a way to override existing block properties at all. Overwriting doesn't work either

Workaround

What you essentially want to do is re-register the block instance of minecraft that is already registered. But there's a reason no one has documented how to do this: You shouldn't.

Reregistering chunks in minecraft can cause strange problems, especially if your mod will be used in a large modpack. This has to do with compatibility with other mods and even Minecraft itself. You better hope to avoid this. There are a dozen other solutions that can change the behavior of specific blocks without causing too many problems. They include but are not limited to:

  • Just add your block to one of minecraft's built-in tags - you don't even need java code, just the json file from the package: https://www.php.cn/link/ff7cc29289db44861ce4b3e5e56fe234 . This could make the stone mineable with a shovel, for example.
  • Use one of the callbacks provided by the fabric api to listen for certain events you want to handle. For example, it can turn grass blocks into dirt when the player clicks on it.
  • Create a so-called "extension block" that can act as a custom state attribute for the block. ie. If you want to give minecraft:stone an age attribute (which may be useful for whatever reason), treat minecraft:stone as age =0 and create a custom block (e.g. modid:ged_stone) using age The zqb attribute expands the age range from 1 to any maximum age.

Another, more general approach is to build the mixin into the block class or appropriate subclass, and do something like the following to target a specific block (in this case, a stone):

block self = (block) (object) this;
if (builtinregistries.block.getkey(self).equals(new resourcelocation("stone"))) {
    // do something only if this block is stone
}
Copy after login

However, if you really, really want to completely replace the block instance, here's a suggestion: Use mixin injection registry.register to replace a specific block instance with a custom block instance:

@Mixin(Registry.class)
public class RegistryMixin {
    @Inject(
        // You may need to specify the correct signature after the method
        // name because there are two `register` methods.
        method="register",
        at=@At("HEAD"),
        cancelable=true
    )
    // Note that this is a generic method, in Mixin you'll have to use
    // Object to replace type parameters
    private static void onRegister(Registry reg, ResourceLocation id, Object value, CallbackInfoReturnable<Object> cir) {
        if (reg != BuiltInRegistries.BLOCK) return;
        if (!id.toString().equals("minecraft:stone")) return;

        // Now that you've filtered out the minecraft:stone block,
        // you can re-register it
        Block myCustomBlock = new Block(.......);
        ((WritableRegistry) reg).register(id, myCustomBlock);
        cir.setReturnValue(myCustomBlock);
    }
}
Copy after login

But again try to avoid this solution. There are dragons here.

Please note that I have not tested any code snippets as I did not have a modified environment on hand at the time of writing this article. It may need adjustment to work. Also, I used mojang's official mapping, if you use yarn mapping, the name may be different. For example, resourcelocation is named identifier in yarn.

I hope this helps. Happy coding!

The above is the detailed content of Minecraft structure overwrites existing blocks 1.20. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template