search
HomeJavaMinecraft structure overwrites existing blocks 1.20

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
}

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);
    }
}

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!

Statement
This article is reproduced at:stackoverflow. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.