minecraft-dotnet/Substrate

BlockManager.SetBlock doesn't work right

Elenesski opened this issue · 3 comments

Try this code out, the first is just a wrapper class, that I'll expand it out later in my project. The second is an event handler for a button. I put it in a class so that GitHub would format it correctly

I would have expected a nice 40x50x2 cobblestone area with alternating mushrooms, but what I get is well, something else. It's funny, because even the mushrooms appear on top of a staggered cobblestone grid.

This code uses the JULY 2, 2013 release DLL compiled with Visual Studio 2010 Pro.

/* -------------------------------------------------------------------------------------- */

public class MCMap {

    private readonly AnvilWorld _World;
    private readonly BlockManager _BlockManager;

    public MCMap(string aPath) {
        _World = AnvilWorld.Open(aPath);
        _BlockManager = _World.GetBlockManager();
    }

    public void SetBlock( int X, int Y, int Z, int aBlockID , int aData = 0 ) {

        IBlock BLOCK = new AlphaBlock(aBlockID,aData);
        _BlockManager.GetBlock(X,Y,Z);
        try {
            _BlockManager.SetBlock(X,Y,Z,BLOCK);
        } catch {

        }

    }

    public void Save() {
        _World.Save();
    }

}

/* -------------------------------------------------------------------------------------- */

public class MyForm {

    private void simpleButton1_Click( object sender , EventArgs e ) {
        MCMap myMap = new MCMap(@"C:\Users\USER\AppData\Roaming\.minecraft\saves\TEST");
        for ( int Z=-50; Z < 50; Z++) {
            for ( int X=-40; X < 40; X++ ) {
                myMap.SetBlock(X, 131, Z, 4);
                myMap.SetBlock(X, 130, Z, 4);

                if ( Z % 2 == 0 ) {
                    if (X%4 == 0)
                        myMap.SetBlock(X, 132, Z, 39);
                    else if (X%4 == 2)
                        myMap.SetBlock(X, 132, Z, 40);
                }
            }
        }
        myMap.Save();
    }

}

If you change the line "_BlockManager.SetBlock(X,Y,Z,BLOCK);"

to

_BlockManager.SetBlock(X,Y,Z,(AlphaBlock)BLOCK);

Then does your code work as intended?

well, rather than casting, this worked better:

AlphaBlock BLOCK = new AlphaBlock(aBlockID,aData);

Same effect. I just want to make sure the method I think is broken is the one causing your broken behavior. If using AlphaBlock directly fixes your problem, then I know what fix to apply for IBlock.