Jump to content

Help with ReplaceBlocksForBiomeEvent


robustus

Recommended Posts

Hi all, I am somewhat of a novice at java and have been modding for a few months building up to more and more complicated things.  I've been looking into the code to try and find the spot where I would be able to change the stone and blocks below the filler block and have found a Forge hook that I'm not sure how to use.

 

I've found this portion of code in ChunkProviderGenerate

 

 /**
     * Replaces the stone that was placed in with blocks that match the biome
     */
    public void replaceBlocksForBiome(int par1, int par2, byte[] par3ArrayOfByte, BiomeGenBase[] par4ArrayOfBiomeGenBase)
    {
        ChunkProviderEvent.ReplaceBiomeBlocks event = new ChunkProviderEvent.ReplaceBiomeBlocks(this, par1, par2, par3ArrayOfByte, par4ArrayOfBiomeGenBase);
        MinecraftForge.EVENT_BUS.post(event);
        if (event.getResult() == Result.DENY) return;

        byte var5 = 63;
        double var6 = 0.03125D;
        this.stoneNoise = this.noiseGen4.generateNoiseOctaves(this.stoneNoise, par1 * 16, par2 * 16, 0, 16, 16, 1, var6 * 2.0D, var6 * 2.0D, var6 * 2.0D);

        for (int var8 = 0; var8 < 16; ++var8)
        {
            for (int var9 = 0; var9 < 16; ++var9)
            {
                BiomeGenBase var10 = par4ArrayOfBiomeGenBase[var9 + var8 * 16];
                float var11 = var10.getFloatTemperature();
                int var12 = (int)(this.stoneNoise[var8 + var9 * 16] / 3.0D + 3.0D + this.rand.nextDouble() * 0.25D);
                int var13 = -1;
                byte var14 = var10.topBlock;
                byte var15 = var10.fillerBlock;

                for (int var16 = 127; var16 >= 0; --var16)
                {
                    int var17 = (var9 * 16 + var8) * 128 + var16;

                    if (var16 <= 0 + this.rand.nextInt(5))
                    {
                        par3ArrayOfByte[var17] = (byte)Block.bedrock.blockID;
                    }
                    else
                    {
                        byte var18 = par3ArrayOfByte[var17];

                        if (var18 == 0)
                        {
                            var13 = -1;
                        }
                        else if (var18 == Block.stone.blockID)
                        {
                            if (var13 == -1)
                            {
                                if (var12 <= 0)
                                {
                                    var14 = 0;
                                    var15 = (byte)Block.stone.blockID;
                                }
                                else if (var16 >= var5 - 4 && var16 <= var5 + 1)
                                {
                                    var14 = var10.topBlock;
                                    var15 = var10.fillerBlock;
                                }

                                if (var16 < var5 && var14 == 0)
                                {
                                    if (var11 < 0.15F)
                                    {
                                        var14 = (byte)Block.ice.blockID;
                                    }
                                    else
                                    {
                                        var14 = (byte)Block.waterStill.blockID;
                                    }
                                }

                                var13 = var12;

                                if (var16 >= var5 - 1)
                                {
                                    par3ArrayOfByte[var17] = var14;
                                }
                                else
                                {
                                    par3ArrayOfByte[var17] = var15;
                                }
                            }
                            else if (var13 > 0)
                            {
                                --var13;
                                par3ArrayOfByte[var17] = var15;

                                if (var13 == 0 && var15 == Block.sand.blockID)
                                {
                                    var13 = this.rand.nextInt(4);
                                    var15 = (byte)Block.sandStone.blockID;
                                }
                            }
                        }
                    }
                }
            }
        }
    }

 

So to me it looks like the code has a forge event where you can disable to the original replaceblocks code here and insert your own, so I found this code in the ChunkProviderEvent

 

     * This event is fired when a chunks blocks are replaced by a biomes top and
     * filler blocks.
     * 
     * You can set the result to DENY to prevent the default replacement.
     */
    @HasResult
    public static class ReplaceBiomeBlocks extends ChunkProviderEvent 
    {
        public final int chunkX;
        public final int chunkZ;
        public final byte[] blockArray;
        public final BiomeGenBase[] biomeArray;
        
        public ReplaceBiomeBlocks(IChunkProvider chunkProvider, int chunkX, int chunkZ, byte[] blockArray, BiomeGenBase[] biomeArray)
        {
            super(chunkProvider);
            this.chunkX = chunkX;
            this.chunkZ = chunkZ;
            this.blockArray = blockArray;
            this.biomeArray = biomeArray;
        }
       
    }

 

Could anyone explain how I insert a hook that calls my own replaceblocksevent I am kinda at a loss for where to start? Any help would be greatly appreciated.

Link to comment
Share on other sites

Ive been unsuccessful trying to call the replace biome block forge event, but i have been able to create a new world type that uses a custom chunk provider, the only problem now Im running into is the custom biomes in my main mod file are not loading automatically into the custom world type, and when I try to add them via various code I am just getting the game hanging when creating a new world, anyone have any info on how to add custom biomes to custom world types?

Link to comment
Share on other sites

OK I figured out how to add custom biomes to the world type and also to have a custom world type overwrite the default so you can use custom chunk providers or chunk managers on the Default world type.  Basically you need to call the new world type in a PostInit FMLPostInitialization event.  If you want to overwrite Default, name it DEFAULT and number it 0

 

@PostInit
public void postinitConfig(FMLPostInitializationEvent fmlpostinitializationevent)
{
	WorldType DEFAULT = new WorldTypeCustom(0, "Default");	



}

Link to comment
Share on other sites

hope this helps

@PreInit

public void myEventsForBiomes(FMLPreInitializationEvent e){

MinecraftForge.TERRAIN_GEN_BUS.register(this);

}

@ForgeSubscribe

public void my_biomes(BiomeEvent.BlockReplacement e){

if(e.biome.topBlock == Block.grass.blockID){

e.biome.topBlock = (byte)Block.bed.blockID;

}

}

this will change the grass to bed, but u can do other things

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



×
×
  • Create New...

Important Information

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