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.
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
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:
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!