Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.8.9] How to use the substitution alias system?


Choonster
 Share

Recommended Posts

I'm trying to test the substitution alias system by replacing the

minecraft:snow_layer

block with a block that has an extra property and sends a chat message to the player when right clicked. You can see my code here.

 

Unfortunately this doesn't seem to work. The F3 debug info doesn't display the value of the extra property and none of my replacement class's methods are being called (except

Block#createBlockState

, but that's called from the constructor).

 

I added a blockstates JSON that uses the vanilla snow layer models and adds a pillar submodel in the centre, but the submodel isn't displayed in the world or in the inventory.

 

If I uncomment the item alias, it creates a new item instead of replacing the vanilla item. The new item crashes with an

ArrayIndexOutOfBoundsException

when right clicked because it doesn't have an item ID.

 

Has anyone managed to get this system working?

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

I've been trying to get this working as well without success. When I tried, Forge added all blocks, items, biomes, etc. twice to the game causing a failure in the game to load which resulted in the level.dat being reported as missing even in a brand new world and upon loading and ignoring the warning, there is nothing, just a void. Would anybody know why this would happen? You can see my code here where I attempted to make the block snow_layer affected by gravity.

Link to comment
Share on other sites

Some of the change logs have indicated there is some known problems with the substitution alias system. For example it looks like they may have made a fix for this in Build 1.8-11.14.3.1559. The changelog says "Fix substitutions for recipes and oredict recipes. Should mean that substitutions start working properly."

 

But yes others have been reporting problem with substitution alias. For example, even in 1.7.10 this was reported: http://www.minecraftforge.net/forum/index.php?topic=30675.0

 

There is an interesting thread here which I think was related to the implementation of the substitution alias: https://github.com/MinecraftForge/FML/issues/370

 

There are a couple interesting points in that discussion. First it is not clear that you should normally register your new block (that might be creating the duplicates). Also, you might need to ensure that the substitution is fully qualified (i.e. vanilla name includes "minecraft:" as modid. However, it seems like there was still acknowledgement that it might now work in the later comments.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

I also remember trying to use substitutions, and whenever I did, the crafting recipe with the substituted block as output was messed up. And probably other problems I can't remember. And I think even after the alleged fix it didn't work.

When I tried to register the block normally it gave an error.

 

Right now I am using a hacky solution by reflecting into the registries and directly replacing everything. Would be nice if I didn't have to do that.

Link to comment
Share on other sites

  • 2 weeks later...

One thing you can do is replace blocks as they are generated -- assuming you're talking a block that gets generated in the world. If you handle the PopulateChunkEvent you can try to iterate through the block positions to check for your block and then replace it. I have an example "Replace All Generated Blocks With Different Block" on this tutorial page: http://jabelarminecraft.blogspot.com/p/minecraft-forge-172-modding-quick-tips.html

 

If you want to make it impossible to place the block in creative mode, you could further remove the block from the creative tabs and add your own to replace it.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

The alias system is the method for 'taking over' someone elses registry entry. Hacky solutions are not advised and are most likely the reason you're getting things that are broken.

According to cpw as long as you register everything correctly and register your alias any @ObjectHolders, ItemStacks, etc.. will be updated to use your object over the one you're overriding.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Patreon: http://www.patreon.com/lexmanos
Paypal: http://paypal.me/LexManos

BitCoin: 1Q8rWvUNMM2T1ZfDaFeeYQyVXtYoeT6tTn

Link to comment
Share on other sites

The alias system is the method for 'taking over' someone elses registry entry. Hacky solutions are not advised and are most likely the reason you're getting things that are broken.

According to cpw as long as you register everything correctly and register your alias any @ObjectHolders, ItemStacks, etc.. will be updated to use your object over the one you're overriding.

 

Could you or cpw advise me if my code (in the OP) is correct?

 

Edit: Fixed typo.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

I wasn't sure if it was a bug or I was just doing something wrong, so I was hoping to find someone who managed to get the system working.

 

I may report it as a bug, since nobody seems to be able to get it working.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

I have stepped through it in the debugger a couple of times. It seems the substitution is being activated, but the

GameData.BLOCKSTATE_TO_ID

map used by

ExtendedBlockStorage

is never updated with the blockstates of the replacement block.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Is ExtendedBlockStorage.get(int x, int y, int z) still returning air due to Block.BLOCK_STATE_IDS.getByValue(#) returning null?

 

It was doing this in 1.8.0 when I attempted to use the alias system, I was told:

it is working, cpws tested it fully. Not sure what the hell you're talking about when it comes to setting the block as you should be able to do that just fine.

BLOCK_STATE_IDS will return proper values for the current world respecting aliases.

 

So at this point we know:

- What worked in 1.7.10 does not work in 1.8.x

- The system does in fact work, we are just using it wrong

- No one but cpw knows how to use it.

- The system is basically useless because no one can figure it out.

 

We need a working sample mod or detailed instructions. :(

 

Link to comment
Share on other sites

Is ExtendedBlockStorage.get(int x, int y, int z) still returning air due to Block.BLOCK_STATE_IDS.getByValue(#) returning null?

 

No, it's returning the ID of the vanilla state.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

No, it's returning the ID of the vanilla state.

 

Ran some tests with this:

    public void onPreInit(FMLPreInitializationEvent event)
    {
        this.testBlock = new TestBlock(); // this extends BlockTallGrass
        ItemBlock testItemBlock = (new ItemColored(this.testBlock, true)).setSubtypeNames(new String[] { "shrub", "grass", "fern" });

        try {
            GameRegistry.addSubstitutionAlias("minecraft:tallgrass", GameRegistry.Type.BLOCK, this.testBlock);
            GameRegistry.addSubstitutionAlias("minecraft:tallgrass", GameRegistry.Type.ITEM, testItemBlock);
        } catch (ExistingSubstitutionException e) {
            e.printStackTrace();
        }
    }

 

Replacing both block and item (doesn't matter what order you replace them in):

- Block renders correctly

- F3 has correct information (in my 1.8.0 tests this was wrong)

- Pick Block doesn't work

- ItemBlock shows up twice in creative tab (normal position, and at end)

- ItemBlock has an id of -1

- ItemBlock has no model

- FML reports it can't find the model files

- Placing Item Block crashes the game (due to having an id of -1)

 

Replacing only the block:

- Block renders correctly

- F3 has correct information (in my 1.8.0 tests this was wrong)

- Pick Block doesn't work

- ItemBlock correctly shows up once on the creative tab

- ItemBlock has the correct id

- ItemBlock has no model

- FML reports it can't find the model files

- Placing Item Block does not crash the game, but places the original (onBlockPlaced on the new block is not called)

 

Replacing only the item:

Same as replacing block and item, but pick block works.

 

I figured this would fail but I tried it anyway.

Cannot register the block to the game registry before registering it to the substitution alias.

"java.lang.IllegalArgumentException: The object substitution is already registered. This won't work"

 

Edit:

I just tried defining the itemblock after the block is registered:

GameRegistry.addSubstitutionAlias("minecraft:tallgrass", GameRegistry.Type.BLOCK, this.testBlock);
ItemBlock testItemBlock = (new ItemColored(Blocks.tallgrass, true)).setSubtypeNames(new String[] { "shrub", "grass", "fern" });
GameRegistry.addSubstitutionAlias("minecraft:tallgrass", GameRegistry.Type.ITEM, testItemBlock);

No change from the other way of replacing the block and item.

Link to comment
Share on other sites

I still can't get this working properly. Lex/cpw (or anyone else), would you be able to provide a basic example of this system to demonstrate how it should be used?

 

My latest code is here (using Forge 1.8.9-11.15.0.1718).

 

Manually adding blockstate IDs to

GameData.BLOCKSTATE_TO_ID

(which I know shouldn't be done) using the vanilla block's ID correctly replaces existing blocks in the world with the new one, but breaks

/setblock

. When the block is first placed from its item, the block model isn't rendered at all until the block receives an update from a neighbour.

 

If I don't add a substitution for the

ItemBlock

, the item uses the vanilla model. If I do, it adds a new item and both items have the missing model.

 

I decided to try replacing a basic

Item

(the stick). The substitution mostly works (the item can be taken out of the creative menu and adds a chat message when right clicked), but the model is broken (it's displaying as the missing model) and crafting it crashes the game with an

ArrayIndexOutOfBoundsException

from

ItemStack#onCrafting

because the item doesn't have an ID.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

  • 2 weeks later...

So I noticed chylex had created a test mod that helped sort out the issues in 1.7 (https://github.com/MinecraftForge/MinecraftForge/pull/2076)

 

I made the minor changes needed to run it on 1.8.9 and it failed.

 

Test: if (!BlockReplacedPlanks.class.isInstance(Blocks.planks)) throw new Exception("Block class type is incorrect: " + Blocks.planks.getClass().getName());

Error: "Test failed: Block class type is incorrect: net.minecraft.block.BlockPlanks"

 

So I decided to skip that test and run again, failed again.

 

Error: "Test failed: null"

Cause: ItemBlock ib = (ItemBlock) Item.getItemFromBlock(Blocks.planks);  < This returns null

 

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

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • I'm new to modding and I want to do this. What class would I put that in?
    • That is a different crash report. Please post the debug.log file from the logs folder.
    • [22Jan.2022 18:41:22.485] [Server thread/ERROR] [net.minecraftforge.eventbus.EventBus/EVENTBUS]: Exception caught during firing event: 'net.minecraft.nbt.CompoundTag net.minecraft.world.level.block.entity.SignBlockEntity.save(net.minecraft.nbt.CompoundTag)'     Index: 4     Listeners:         0: HIGH         1: ASM: class dev.architectury.event.forge.EventHandlerImplCommon event(Lnet/minecraftforge/event/server/ServerStartingEvent;)V         2: NORMAL         3: ASM: cyclopscore onServerStarting(Lnet/minecraftforge/event/server/ServerStartingEvent;)V         4: ASM: chanceCubes.CCubesCore@5b77fda6 serverStart(Lnet/minecraftforge/event/server/ServerStartingEvent;)V         5: ASM: mods.waterstrainer.event.EventServerStarting@2dc1913f onServerStarting(Lnet/minecraftforge/event/server/ServerStartingEvent;)V         6: ASM: com.song.castle_in_the_sky.CastleInTheSky@1f8c253d onServerStarting(Lnet/minecraftforge/event/server/ServerStartingEvent;)V         7: ASM: se.mickelus.tetra.TetraMod@203a3089 serverStarting(Lnet/minecraftforge/event/server/ServerStartingEvent;)V         8: net.minecraftforge.eventbus.EventBus$$Lambda$4325/0x0000000800c57770@71737087         9: ASM: de.teamlapen.vampirism.VampirismMod@1213b1b onServerStart(Lnet/minecraftforge/event/server/ServerStartingEvent;)V         10: net.minecraftforge.eventbus.EventBus$$Lambda$4325/0x0000000800c57770@1a894d2d         11: net.minecraftforge.eventbus.EventBus$$Lambda$4325/0x0000000800c57770@3deb329 java.lang.NoSuchMethodError: 'net.minecraft.nbt.CompoundTag net.minecraft.world.level.block.entity.SignBlockEntity.save(net.minecraft.nbt.CompoundTag)'     at TRANSFORMER/chancecubes@1.18.1-5.0.2.444/chanceCubes.rewards.DefaultRewards.loadDefaultRewards(DefaultRewards.java:124)     at TRANSFORMER/chancecubes@1.18.1-5.0.2.444/chanceCubes.CCubesCore.serverStart(CCubesCore.java:123)     at net.minecraftforge.eventbus.ASMEventHandler_101_CCubesCore_serverStart_ServerStartingEvent.invoke(.dynamic)     at MC-BOOTSTRAP/eventbus@5.0.3/net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85)     at MC-BOOTSTRAP/eventbus@5.0.3/net.minecraftforge.eventbus.EventBus.post(EventBus.java:302)     at MC-BOOTSTRAP/eventbus@5.0.3/net.minecraftforge.eventbus.EventBus.post(EventBus.java:283)     at TRANSFORMER/forge@39.0.56/net.minecraftforge.server.ServerLifecycleHooks.handleServerStarting(ServerLifecycleHooks.java:102)     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)     at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.base/java.lang.reflect.Method.invoke(Method.java:568)     at TRANSFORMER/net.optifine/net.optifine.reflect.Reflector.callBoolean(Reflector.java:702)     at TRANSFORMER/minecraft@1.18.1/net.minecraft.client.server.IntegratedServer.m_7038_(IntegratedServer.java:90)     at TRANSFORMER/minecraft@1.18.1/net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:644)     at TRANSFORMER/minecraft@1.18.1/net.minecraft.server.MinecraftServer.m_177918_(MinecraftServer.java:258)     at java.base/java.lang.Thread.run(Thread.java:833) [22Jan.2022 18:41:22.509] [Server thread/DEBUG] [mixin/]: Mixing MixinChunkSerializer from architectury.mixins.json into net.minecraft.world.level.chunk.storage.ChunkSerializer [22Jan.2022 18:41:28.076] [Server thread/DEBUG] [net.minecraftforge.fml.loading.FileUtils/CORE]: Found existing serverconfig directory : C:\Users\UTW\AppData\Roaming\.minecraft\saves\New World\serverconfig [22Jan.2022 18:41:28.076] [Server thread/DEBUG] [net.minecraftforge.fml.config.ConfigTracker/CONFIG]: Unloading configs type SERVER Sry if its not the right one, im pretty new at Forge
    • I have a modded server that worked before I changed the config for SereneSeasons (made the seasons longer and turned off offline season progression). Now it just gives said error message, even after reverting the changes.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.