Example usage for net.minecraftforge.common.util BlockSnapshot getBlockSnapshot

List of usage examples for net.minecraftforge.common.util BlockSnapshot getBlockSnapshot

Introduction

In this page you can find the example usage for net.minecraftforge.common.util BlockSnapshot getBlockSnapshot.

Prototype

public static BlockSnapshot getBlockSnapshot(IWorld world, BlockPos pos, int flag) 

Source Link

Usage

From source file:com.blogspot.jabelarminecraft.magicbeans.utilities.Utilities.java

License:Open Source License

/**
 * Sets the block state at a given location. Flag 1 will cause a block update. Flag 2 will send the change to
 * clients (you almost always want parWorld). Flag 4 prevents the block from being re-rendered, if parWorld is a client
 * world. Flags can be added together.// w  w w .  j ava  2  s  .  c o m
 *  
 * @param parFlags Flag 1 will cause a block update. Flag 2 will send the change to clients (you almost always want
 * parWorld). Flag 4 prevents the block from being re-rendered, if parWorld is a client world. Flags can be added together.
 */
public static boolean setBlockStateFast(World parWorld, BlockPos parBlockPos, IBlockState parIBlockState,
        int parFlags) {
    if (!(parBlockPos.getX() >= -30000000 && parBlockPos.getZ() >= -30000000 && parBlockPos.getX() < 30000000
            && parBlockPos.getZ() < 30000000 && parBlockPos.getY() >= 0 && parBlockPos.getY() < 256)) {
        return false;
    } else if (!parWorld.isRemote && parWorld.getWorldInfo().getTerrainType() == WorldType.DEBUG_WORLD) {
        return false;
    } else {
        Chunk theChunk = parWorld.getChunkFromBlockCoords(parBlockPos);
        //            Block newBlock = parIBlockState.getBlock();

        BlockSnapshot blockSnapshot = null;
        if (parWorld.captureBlockSnapshots && !parWorld.isRemote) {
            blockSnapshot = BlockSnapshot.getBlockSnapshot(parWorld, parBlockPos, parFlags);
            parWorld.capturedBlockSnapshots.add(blockSnapshot);
        }

        IBlockState theIBlockState = setBlockStateInChunkFast(theChunk, parBlockPos, parIBlockState);

        if (theIBlockState == null) {
            if (blockSnapshot != null)
                parWorld.capturedBlockSnapshots.remove(blockSnapshot);
            return false;
        } else {
            //                Block block1 = theIBlockState.getBlock();
            //
            //                if (newBlock.getLightOpacity() != block1.getLightOpacity() || newBlock.getLightValue() != block1.getLightValue())
            //                {
            //                    parWorld.theProfiler.startSection("checkLight");
            parWorld.checkLight(parBlockPos);
            //                    parWorld.theProfiler.endSection();
            //                }

            if (blockSnapshot == null) // Don't notify clients or update physics while capturing blockstates
            {
                parWorld.markAndNotifyBlock(parBlockPos, theChunk, theIBlockState, parIBlockState, parFlags); // Modularize client and physic updates
            }

            return true;
        }
    }
}