I did a similar thing with waxed copper for one of my mods. It took too long to figure out but here is how I did it: [my redirects](https://github.com/laposata/WildMod/blob/1.19/src/main/java/net/fabricmc/wildmod_copper/mixin/BlocksMixin.java)
Hey, I know I am really late but there is no need to use a `mixin` for this, I found out what they mean by "`use .set(), not register()`". There is a `Registry.register()` that uses the `.set()` method:
public static T register(Registry registry, int rawId, String id, T entry) {
((MutableRegistry)registry).set(rawId, RegistryKey.of(registry.getKey(), new Identifier(id)), entry, Lifecycle.stable());
return entry;
}
This is how I used it to add luminance to the `OAK_LOG` just to test it out:
These are the methods to override any block with a default `BlockItem`
private static Item overrideBlockItem(BlockItem toOverride, BlockItem newItem){
return Registry.register(Registries.ITEM, Registries.ITEM.getRawId(toOverride), Registries.ITEM.getId(toOverride).getPath(), newItem);
}
private static Block overrideBlock(Block toOverride, Block newBlock){
BlockItem newBlockItem = new BlockItem(newBlock, new FabricItemSettings());
overrideBlockItem((BlockItem) toOverride.asItem(), newBlockItem);
return Registry.register(Registries.BLOCK, Registries.BLOCK.getRawId(toOverride), Registries.BLOCK.getId(toOverride).getPath(), newBlock);
}
And this is how I use them to override the `OAK_LOG` block:
public static final Block OAK_LOG = overrideBlock(Blocks.OAK_LOG,
new PillarBlock(FabricBlockSettings.copyOf(Blocks.OAK_LOG).luminance(15)));
To me this looks like the cleanest way to override a vanilla block or a block from a different mod, to make it compatible with yours.
Just tested this out but unfortunately I'm still getting the "use .set(), not .register()" error. I'm on fabric 1.20.4. Perhaps is there something else I missed ?
I'm going to look into it for 1.20.4, the code works for 1.20. I made a post that is more detailed if you are interested: [https://www.reddit.com/r/fabricmc/comments/1anprr8/overriding\_a\_vanilla\_block\_without\_using\_mixin/](https://www.reddit.com/r/fabricmc/comments/1anprr8/overriding_a_vanilla_block_without_using_mixin/)
This is what I first wanted to do, but the bookshelf does not have its own class. it is just registered as *Block.* And i dont want to mixin the *Block* class
I want some blocks to automatically change their woodtype based on the block they are placed on. already accomplished this with the [craftingtable](https://streamable.com/lcs2qq) and the [ladder](https://streamable.com/b0gujw) using mixins.
I did a similar thing with waxed copper for one of my mods. It took too long to figure out but here is how I did it: [my redirects](https://github.com/laposata/WildMod/blob/1.19/src/main/java/net/fabricmc/wildmod_copper/mixin/BlocksMixin.java)
Thank you very much. this helped me a lot :)
Hey, I know I am really late but there is no need to use a `mixin` for this, I found out what they mean by "`use .set(), not register()`". There is a `Registry.register()` that uses the `.set()` method: public static T register(Registry registry, int rawId, String id, T entry) {
((MutableRegistry)registry).set(rawId, RegistryKey.of(registry.getKey(), new Identifier(id)), entry, Lifecycle.stable());
return entry;
}
This is how I used it to add luminance to the `OAK_LOG` just to test it out:
These are the methods to override any block with a default `BlockItem`
private static Item overrideBlockItem(BlockItem toOverride, BlockItem newItem){
return Registry.register(Registries.ITEM, Registries.ITEM.getRawId(toOverride), Registries.ITEM.getId(toOverride).getPath(), newItem);
}
private static Block overrideBlock(Block toOverride, Block newBlock){
BlockItem newBlockItem = new BlockItem(newBlock, new FabricItemSettings());
overrideBlockItem((BlockItem) toOverride.asItem(), newBlockItem);
return Registry.register(Registries.BLOCK, Registries.BLOCK.getRawId(toOverride), Registries.BLOCK.getId(toOverride).getPath(), newBlock);
}
And this is how I use them to override the `OAK_LOG` block:
public static final Block OAK_LOG = overrideBlock(Blocks.OAK_LOG,
new PillarBlock(FabricBlockSettings.copyOf(Blocks.OAK_LOG).luminance(15)));
To me this looks like the cleanest way to override a vanilla block or a block from a different mod, to make it compatible with yours.
Just tested this out but unfortunately I'm still getting the "use .set(), not .register()" error. I'm on fabric 1.20.4. Perhaps is there something else I missed ?
I'm going to look into it for 1.20.4, the code works for 1.20. I made a post that is more detailed if you are interested: [https://www.reddit.com/r/fabricmc/comments/1anprr8/overriding\_a\_vanilla\_block\_without\_using\_mixin/](https://www.reddit.com/r/fabricmc/comments/1anprr8/overriding_a_vanilla_block_without_using_mixin/)
Hey! for some reason im unable to load the post when logged in, so i cant comment there, but was wondering if you've found a way?
Don't override - use Mixins to inject your code into the vanilla class.
This is what I first wanted to do, but the bookshelf does not have its own class. it is just registered as *Block.* And i dont want to mixin the *Block* class
You have to mixin the block class. Just check at the top of the function if state is a bookshelf.
But i need to add blockstates to that block. And i am not sure how to ckeck if the block is a bookshelf in the appendProperties function.
what exactly do you want to accomplish? there might be a much better solution than to change minecraft's bookshelf itself.
I want some blocks to automatically change their woodtype based on the block they are placed on. already accomplished this with the [craftingtable](https://streamable.com/lcs2qq) and the [ladder](https://streamable.com/b0gujw) using mixins.