Search in sources :

Example 6 with MBlockPos

use of com.github.lunatrius.core.util.math.MBlockPos in project defrag by Edouard127.

the class MessageDownloadChunk method copyToSchematic.

private void copyToSchematic(final ISchematic schematic) {
    final MBlockPos pos = new MBlockPos();
    for (int x = 0; x < Constants.SchematicChunk.WIDTH; x++) {
        for (int y = 0; y < Constants.SchematicChunk.HEIGHT; y++) {
            for (int z = 0; z < Constants.SchematicChunk.LENGTH; z++) {
                final short id = this.blocks[x][y][z];
                final byte meta = this.metadata[x][y][z];
                final Block block = Block.REGISTRY.getObjectById(id);
                pos.set(this.baseX + x, this.baseY + y, this.baseZ + z);
                schematic.setBlockState(pos, block.getStateFromMeta(meta));
            }
        }
    }
    for (final TileEntity tileEntity : this.tileEntities) {
        schematic.setTileEntity(tileEntity.getPos(), tileEntity);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) MBlockPos(com.github.lunatrius.core.util.math.MBlockPos) Block(net.minecraft.block.Block)

Example 7 with MBlockPos

use of com.github.lunatrius.core.util.math.MBlockPos in project defrag by Edouard127.

the class ClientProxy method moveSchematicToPlayer.

public static void moveSchematicToPlayer(final SchematicWorld schematic) {
    if (schematic != null) {
        final MBlockPos position = schematic.position;
        position.x = (int) Math.floor(playerPosition.x);
        position.y = (int) Math.floor(playerPosition.y);
        position.z = (int) Math.floor(playerPosition.z);
        switch(rotationRender) {
            case 0:
                position.x -= schematic.getWidth();
                position.z += 1;
                break;
            case 1:
                position.x -= schematic.getWidth();
                position.z -= schematic.getLength();
                break;
            case 2:
                position.x += 1;
                position.z -= schematic.getLength();
                break;
            case 3:
                position.x += 1;
                position.z += 1;
                break;
        }
    }
}
Also used : MBlockPos(com.github.lunatrius.core.util.math.MBlockPos)

Example 8 with MBlockPos

use of com.github.lunatrius.core.util.math.MBlockPos in project defrag by Edouard127.

the class CommonProxy method copyChunkToSchematic.

public void copyChunkToSchematic(final ISchematic schematic, final World world, final int chunkX, final int chunkZ, final int minX, final int maxX, final int minY, final int maxY, final int minZ, final int maxZ) {
    final MBlockPos pos = new MBlockPos();
    final MBlockPos localPos = new MBlockPos();
    final int localMinX = minX < (chunkX << 4) ? 0 : (minX & 15);
    final int localMaxX = maxX > ((chunkX << 4) + 15) ? 15 : (maxX & 15);
    final int localMinZ = minZ < (chunkZ << 4) ? 0 : (minZ & 15);
    final int localMaxZ = maxZ > ((chunkZ << 4) + 15) ? 15 : (maxZ & 15);
    for (int chunkLocalX = localMinX; chunkLocalX <= localMaxX; chunkLocalX++) {
        for (int chunkLocalZ = localMinZ; chunkLocalZ <= localMaxZ; chunkLocalZ++) {
            for (int y = minY; y <= maxY; y++) {
                final int x = chunkLocalX | (chunkX << 4);
                final int z = chunkLocalZ | (chunkZ << 4);
                final int localX = x - minX;
                final int localY = y - minY;
                final int localZ = z - minZ;
                pos.set(x, y, z);
                localPos.set(localX, localY, localZ);
                try {
                    final IBlockState blockState = world.getBlockState(pos);
                    final Block block = blockState.getBlock();
                    final boolean success = schematic.setBlockState(localPos, blockState);
                    if (success && block.hasTileEntity(blockState)) {
                        final TileEntity tileEntity = world.getTileEntity(pos);
                        if (tileEntity != null) {
                            try {
                                final TileEntity reloadedTileEntity = NBTHelper.reloadTileEntity(tileEntity, minX, minY, minZ);
                                schematic.setTileEntity(localPos, reloadedTileEntity);
                            } catch (final NBTConversionException nce) {
                                Reference.logger.error("Error while trying to save tile entity '{}'!", tileEntity, nce);
                                schematic.setBlockState(localPos, Blocks.BEDROCK.getDefaultState());
                            }
                        }
                    }
                } catch (final Exception e) {
                    Reference.logger.error("Something went wrong!", e);
                }
            }
        }
    }
    final int minX1 = localMinX | (chunkX << 4);
    final int minZ1 = localMinZ | (chunkZ << 4);
    final int maxX1 = localMaxX | (chunkX << 4);
    final int maxZ1 = localMaxZ | (chunkZ << 4);
    final AxisAlignedBB bb = new AxisAlignedBB(minX1, minY, minZ1, maxX1 + 1, maxY + 1, maxZ1 + 1);
    final List<Entity> entities = world.getEntitiesWithinAABB(Entity.class, bb);
    for (final Entity entity : entities) {
        try {
            final Entity reloadedEntity = NBTHelper.reloadEntity(entity, minX, minY, minZ);
            schematic.addEntity(reloadedEntity);
        } catch (final NBTConversionException nce) {
            Reference.logger.error("Error while trying to save entity '{}'!", entity, nce);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) MBlockPos(com.github.lunatrius.core.util.math.MBlockPos) Block(net.minecraft.block.Block) NBTConversionException(com.github.lunatrius.schematica.nbt.NBTConversionException) NBTConversionException(com.github.lunatrius.schematica.nbt.NBTConversionException) IOException(java.io.IOException)

Example 9 with MBlockPos

use of com.github.lunatrius.core.util.math.MBlockPos in project Spark-Client by Spark-Client-Development.

the class RenderSchematic method markBlocksForUpdate.

private void markBlocksForUpdate(final int x1, final int y1, final int z1, final int x2, final int y2, final int z2, final boolean needsUpdate) {
    if (this.world == null) {
        return;
    }
    final MBlockPos position = this.world.position;
    this.viewFrustum.markBlocksForUpdate(x1 - position.x, y1 - position.y, z1 - position.z, x2 - position.x, y2 - position.y, z2 - position.z, needsUpdate);
}
Also used : MBlockPos(com.github.lunatrius.core.util.math.MBlockPos)

Example 10 with MBlockPos

use of com.github.lunatrius.core.util.math.MBlockPos in project Spark-Client by Spark-Client-Development.

the class ClientProxy method moveSchematicToPlayer.

public static void moveSchematicToPlayer(final SchematicWorld schematic) {
    if (schematic != null) {
        final MBlockPos position = schematic.position;
        position.x = (int) Math.floor(playerPosition.x);
        position.y = (int) Math.floor(playerPosition.y);
        position.z = (int) Math.floor(playerPosition.z);
        switch(rotationRender) {
            case 0:
                position.x -= schematic.getWidth();
                position.z += 1;
                break;
            case 1:
                position.x -= schematic.getWidth();
                position.z -= schematic.getLength();
                break;
            case 2:
                position.x += 1;
                position.z -= schematic.getLength();
                break;
            case 3:
                position.x += 1;
                position.z += 1;
                break;
        }
    }
}
Also used : MBlockPos(com.github.lunatrius.core.util.math.MBlockPos)

Aggregations

MBlockPos (com.github.lunatrius.core.util.math.MBlockPos)21 IBlockState (net.minecraft.block.state.IBlockState)13 TileEntity (net.minecraft.tileentity.TileEntity)10 Block (net.minecraft.block.Block)9 BlockPos (net.minecraft.util.math.BlockPos)8 ISchematic (com.github.lunatrius.schematica.api.ISchematic)6 Schematic (com.github.lunatrius.schematica.world.storage.Schematic)6 ItemStack (net.minecraft.item.ItemStack)5 Vec3i (net.minecraft.util.math.Vec3i)4 HashMap (java.util.HashMap)3 Entity (net.minecraft.entity.Entity)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 NBTTagList (net.minecraft.nbt.NBTTagList)3 NBTConversionException (com.github.lunatrius.schematica.nbt.NBTConversionException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 BlockLiquid (net.minecraft.block.BlockLiquid)2 BlockSlab (net.minecraft.block.BlockSlab)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2