Jump to content

[SOLVED!] how to use addSubstitutionAlias ?


trollworkout

Recommended Posts

I tried creating my own block then addSubstitutionAlias but it keeps telling me null pointer exception whenever I try to register the model.

 

Maybe the model does not require registering??

 

Seems like if I copy and paste all the blockstate and model json files over from MC to my game then simply set unlocalized name and registry name same as minecraft it works. Im confused if this is actually working or just trolling me.

 

DO I need to register BOTH block and it's itemblock?

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

Hey thank you for your help. I did that and it seems to appear twice.

Oops I meant to say substitute it, though I don't know if that will work? (Never done any substituting, at least while the system is working).

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

I'm pretty sure you are right because it seems block and item are tied in. You can't just replace one without the other.

 

I just now need to figure out why it appears twice and why is using vanilla blockstate and model  instead of my own.

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

I'm pretty sure you are right because it seems block and item are tied in. You can't just replace one without the other.

 

I just now need to figure out why it appears twice and why is using vanilla blockstate and model  instead of my own.

Did you set the model location with ModelLoader?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

      ModelLoader.setCustomModelResourceLocation(ModItems.CAULDRON, 0, new ModelResourceLocation(ModBlocks.CAULDRON.getRegistryName(), "variants")); 

 

 

like that

 

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

      ModelLoader.setCustomModelResourceLocation(ModItems.CAULDRON, 0, new ModelResourceLocation(ModBlocks.CAULDRON.getRegistryName(), "variants")); 

 

 

like that

Could you post all relevant code or better yet github link?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Here is my project

https://github.com/trollworkout/technorcery/tree/master/src/main/java/com/technorcery

 

my blocks are in ModBlocks

https://github.com/trollworkout/technorcery/blob/master/src/main/java/com/technorcery/common/ModBlocks.java

 

items here

https://github.com/trollworkout/technorcery/blob/master/src/main/java/com/technorcery/common/ModItems.java

 

my models are here

https://github.com/trollworkout/technorcery/blob/master/src/main/java/com/technorcery/client/ModelsHandler.java

 

Essentially I'm doing this in my blocks

 

define my custom cauldron

public static final Block CAULDRON = new Cauldron().setUnlocalizedName("cauldron").setRegistryName("cauldron");

 

then in preInit i register it like this

 

try {

GameRegistry.addSubstitutionAlias("cauldron", GameRegistry.Type.BLOCK, CAULDRON);

} catch (ExistingSubstitutionException e) {

e.printStackTrace();

throw new RuntimeException(e);

}

 

then in models later in pre init() i register like so

      ModelLoader.setCustomModelResourceLocation(ModItems.CAULDRON, 0, new ModelResourceLocation(ModBlocks.CAULDRON.getRegistryName(), "variants")); 

 

 

 

This should replace the block with my block with my own custom model and everything. But it doesn't!

 

Maybe because I still need to GameRegistry.register(CAULDRON) ? Not sure

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

OK so an alias substitution is like registering it so it won't work if I register then alias it.

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

I think the substitution alias thing is still broken since long time ago.

No, CPW, and Lex have both said that it works.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Yeah I dunno keeps giving me null pointer to Item.getItemFromBlock(replacement_block) AFTER I set both up with addSubstituteAlias

 

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

Try moving your blockstate file. To a folder called minecraft (where your modid would be), but in your project. IE assets.minecraft.blockstates, but inside your project. Instead of assets.modid.blockstates. Item.getItemFromBlock doesn't respect substitution aliasing.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Try moving your blockstate file. To a folder called minecraft (where your modid would be), but in your project. IE assets.minecraft.blockstates, but inside your project. Instead of assets.modid.blockstates. Item.getItemFromBlock doesn't respect substitution aliasing.

 

Gotcha Im gonna try that.

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

Seems the reason is failing is this .setRegistryName("cauldron")  and this Item.getItemFromBlock

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

Seems the reason is failing is this .setRegistryName("cauldron")  and this Item.getItemFromBlock

The setRegistryName should be fine, but Item.getItemFromBlock doesn't respect aliasing it only accesses the registry data and not the aliasing data.

 

My testing code...

Block block = null;
	Item item = null;
	try {
		block = new BlockCauldron().setRegistryName(new ResourceLocation("wr", "cauldron"));
		item = new ItemBlockSpecial(block).setRegistryName(new ResourceLocation("wr", "cauldron"));
		GameRegistry.addSubstitutionAlias("minecraft:cauldron", Type.BLOCK, block);
		GameRegistry.addSubstitutionAlias("minecraft:cauldron", Type.ITEM, item);
	} catch (ExistingSubstitutionException e) {
		e.printStackTrace();
	}

	ModelLoader.setCustomModelResourceLocation(item, 1, new ModelResourceLocation(new ResourceLocation(ModReference.MODID, "cauldron"), "inventory"));

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Oh man I'm gonna go to sleep I been up since this morning and last few hours been trying to figure this out with no hope. Im gonna try your code idea first thing in the morning. Thank you so far. All I need is to get this working once.

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

Oh man I'm gonna go to sleep I been up since this morning and last few hours been trying to figure this out with no hope. Im gonna try your code idea first thing in the morning. Thank you so far. All I need is to get this working once.

Use your public static final variables instead of my in method variables and note "wr" is the modid, and the meta of 1 is incorrect use 0. You should really try the...

Try moving your blockstate file. To a folder called minecraft (where your modid would be), but in your project. IE assets.minecraft.blockstates, but inside your project. Instead of assets.modid.blockstates.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

SO I confirm that the item replacement seems to work  somewhat (shows up twice still) but the block replacement does not.

 

Also an odd thing if I set no creative tab  or a creative tab and no unlocalized it won't show up. But if i set both creative and unlocalized i shows up twice.

 

it seems addSubsititutionAlias("cauldorn" or addSubsititutionAlias("minecraft:cauldorn" is same thing

 

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

OK so from my test there seems to be no direct way to change a block. You can only change the block item and the block associated with it but the block itself is not changeable.

 

So if I wanna replace all vanilla Cauldrons that are to be pre-placed in the game I cannot. I can only replace the item you craft and the block associated with it.

 

For ex I made the cauldron places a steam boiler (custom block i made) but I cannot make already existing Cauldron automatically become Seam boilers.

 

 

According to the description it says it replaces all references of one block/item with another. I was wondering WHY you want me to replace both item and block??  I just need to change the block only.

 

Maybe the function works differently than it says. it does not replace one block reference with the other but in fact it simply replaces the output on the  item on the crafting table  thus replacing the block associated with it.

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

Try moving your blockstate file. To a folder called minecraft (where your modid would be), but in your project. IE assets.minecraft.blockstates, but inside your project. Instead of assets.modid.blockstates. Item.getItemFromBlock doesn't respect substitution aliasing.

 

This means the block DID NOT get replaced with my block. Since what you are doing her eis replacing the vanilla block's model. This is a method done in a resource pack. My block sohuld have my own model refs and blockstate and the alias method should (based on description) completely replace a vanilla block for my block including my own model, lang , blockstate etc.  So this should not be necessary if it actually did work.

 

I'm probably doing it badly or is broken (again)

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

OK sorry for the spam.

 

SO I went back to my original idea of replacing block only and this time it worked!

 

Of course already existing preplaced Cauldrons are vanilla but any new ones I manually place change to my block. See no need to replace item. So the function IS working is just I don't know how to use it. The problem now is my block does not have any model and I think that may be due to cauldron having extra properties which need to be ignored.

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Link to comment
Share on other sites

OK so I kinda figured this out  but I am still trying to figure out how to set the model however I am VERY close.

 

I noticed nobody sets the registry name on a block that you wanna use as a substitute so I did the same.

 

I removed setRegistryName

 

Once I did that I could see right away that all blocks of that type got changed to my block (although still no texture). So this does not just replace new blocks but ALL instances of the block or item including anything pre-placed. 

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

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

    • 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;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
    • Update your drivers: https://www.amd.com/en/support/graphics/amd-radeon-r9-series/amd-radeon-r9-200-series/amd-radeon-r9-280x
  • Topics

×
×
  • Create New...

Important Information

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