Search in sources :

Example 1 with Schematic

use of com.github.lunatrius.schematica.world.storage.Schematic in project Spark-Client by Spark-Client-Development.

the class FlipHelper method flip.

public boolean flip(final SchematicWorld world, final EnumFacing axis, final boolean forced) {
    if (world == null) {
        return false;
    }
    try {
        final ISchematic schematic = world.getSchematic();
        final Schematic schematicFlipped = flip(schematic, axis, forced);
        world.setSchematic(schematicFlipped);
        for (final TileEntity tileEntity : world.getTileEntities()) {
            world.initializeTileEntity(tileEntity);
        }
        return true;
    } catch (final FlipException fe) {
        Reference.logger.error(fe.getMessage());
    } catch (final Exception e) {
        Reference.logger.fatal("Something went wrong!", e);
    }
    return false;
}
Also used : ISchematic(com.github.lunatrius.schematica.api.ISchematic) TileEntity(net.minecraft.tileentity.TileEntity) ISchematic(com.github.lunatrius.schematica.api.ISchematic) Schematic(com.github.lunatrius.schematica.world.storage.Schematic)

Example 2 with Schematic

use of com.github.lunatrius.schematica.world.storage.Schematic in project Spark-Client by Spark-Client-Development.

the class FlipHelper method flip.

public Schematic flip(final ISchematic schematic, final EnumFacing axis, final boolean forced) throws FlipException {
    final Vec3i dimensionsFlipped = new Vec3i(schematic.getWidth(), schematic.getHeight(), schematic.getLength());
    final Schematic schematicFlipped = new Schematic(schematic.getIcon(), dimensionsFlipped.getX(), dimensionsFlipped.getY(), dimensionsFlipped.getZ(), schematic.getAuthor());
    final MBlockPos tmp = new MBlockPos();
    for (final MBlockPos pos : BlockPosHelper.getAllInBox(0, 0, 0, schematic.getWidth() - 1, schematic.getHeight() - 1, schematic.getLength() - 1)) {
        final IBlockState blockState = schematic.getBlockState(pos);
        final IBlockState blockStateFlipped = flipBlock(blockState, axis, forced);
        schematicFlipped.setBlockState(flipPos(pos, axis, dimensionsFlipped, tmp), blockStateFlipped);
    }
    final List<TileEntity> tileEntities = schematic.getTileEntities();
    for (final TileEntity tileEntity : tileEntities) {
        final BlockPos pos = tileEntity.getPos();
        tileEntity.setPos(new BlockPos(flipPos(pos, axis, dimensionsFlipped, tmp)));
        schematicFlipped.setTileEntity(tileEntity.getPos(), tileEntity);
    }
    return schematicFlipped;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Vec3i(net.minecraft.util.math.Vec3i) IBlockState(net.minecraft.block.state.IBlockState) MBlockPos(com.github.lunatrius.core.util.math.MBlockPos) BlockPos(net.minecraft.util.math.BlockPos) MBlockPos(com.github.lunatrius.core.util.math.MBlockPos) ISchematic(com.github.lunatrius.schematica.api.ISchematic) Schematic(com.github.lunatrius.schematica.world.storage.Schematic)

Example 3 with Schematic

use of com.github.lunatrius.schematica.world.storage.Schematic in project Spark-Client by Spark-Client-Development.

the class SchematicStructure method readFromNBT.

@Override
public ISchematic readFromNBT(final NBTTagCompound tagCompound) {
    final ItemStack icon = SchematicUtil.getIconFromNBT(tagCompound);
    final Template template = new Template();
    template.read(tagCompound);
    final Schematic schematic = new Schematic(icon, template.size.getX(), template.size.getY(), template.size.getZ(), template.getAuthor());
    for (Template.BlockInfo block : template.blocks) {
        schematic.setBlockState(block.pos, block.blockState);
        if (block.tileentityData != null) {
            try {
                // This position isn't included by default
                block.tileentityData.setInteger("x", block.pos.getX());
                block.tileentityData.setInteger("y", block.pos.getY());
                block.tileentityData.setInteger("z", block.pos.getZ());
                final TileEntity tileEntity = NBTHelper.readTileEntityFromCompound(block.tileentityData);
                if (tileEntity != null) {
                    schematic.setTileEntity(block.pos, tileEntity);
                }
            } catch (final Exception e) {
                Reference.logger.error("TileEntity failed to load properly!", e);
            }
        }
    }
    return schematic;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ItemStack(net.minecraft.item.ItemStack) ISchematic(com.github.lunatrius.schematica.api.ISchematic) Schematic(com.github.lunatrius.schematica.world.storage.Schematic) Template(net.minecraft.world.gen.structure.template.Template)

Example 4 with Schematic

use of com.github.lunatrius.schematica.world.storage.Schematic in project defrag by Edouard127.

the class SchematicAlpha method readFromNBT.

@Override
public Object readFromNBT(final NBTTagCompound tagCompound) {
    final ItemStack icon = SchematicUtil.getIconFromNBT(tagCompound);
    final byte[] localBlocks = tagCompound.getByteArray(Names.NBT.BLOCKS);
    final byte[] localMetadata = tagCompound.getByteArray(Names.NBT.DATA);
    boolean extra = false;
    byte[] extraBlocks = null;
    byte[] extraBlocksNibble = null;
    if (tagCompound.hasKey(Names.NBT.ADD_BLOCKS)) {
        extra = true;
        extraBlocksNibble = tagCompound.getByteArray(Names.NBT.ADD_BLOCKS);
        extraBlocks = new byte[extraBlocksNibble.length * 2];
        for (int i = 0; i < extraBlocksNibble.length; i++) {
            extraBlocks[i * 2 + 0] = (byte) ((extraBlocksNibble[i] >> 4) & 0xF);
            extraBlocks[i * 2 + 1] = (byte) (extraBlocksNibble[i] & 0xF);
        }
    } else if (tagCompound.hasKey(Names.NBT.ADD_BLOCKS_SCHEMATICA)) {
        extra = true;
        extraBlocks = tagCompound.getByteArray(Names.NBT.ADD_BLOCKS_SCHEMATICA);
    }
    final short width = tagCompound.getShort(Names.NBT.WIDTH);
    final short length = tagCompound.getShort(Names.NBT.LENGTH);
    final short height = tagCompound.getShort(Names.NBT.HEIGHT);
    Short id = null;
    final Map<Short, Short> oldToNew = new HashMap<Short, Short>();
    if (tagCompound.hasKey(Names.NBT.MAPPING_SCHEMATICA)) {
        final NBTTagCompound mapping = tagCompound.getCompoundTag(Names.NBT.MAPPING_SCHEMATICA);
        final Set<String> names = mapping.getKeySet();
        for (final String name : names) {
            oldToNew.put(mapping.getShort(name), (short) Block.REGISTRY.getIDForObject(Block.REGISTRY.getObject(new ResourceLocation(name))));
        }
    }
    final MBlockPos pos = new MBlockPos();
    final ISchematic schematic = new Schematic(icon, width, height, length);
    for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
            for (int z = 0; z < length; z++) {
                final int index = x + (y * length + z) * width;
                int blockID = (localBlocks[index] & 0xFF) | (extra ? ((extraBlocks[index] & 0xFF) << 8) : 0);
                final int meta = localMetadata[index] & 0xFF;
                if ((id = oldToNew.get((short) blockID)) != null) {
                    blockID = id;
                }
                final Block block = Block.REGISTRY.getObjectById(blockID);
                pos.set(x, y, z);
                try {
                    final IBlockState blockState = block.getStateFromMeta(meta);
                    schematic.setBlockState(pos, blockState);
                } catch (final Exception e) {
                    Reference.logger.error("Could not set block state at {} to {} with metadata {}", pos, Block.REGISTRY.getNameForObject(block), meta, e);
                }
            }
        }
    }
    final NBTTagList tileEntitiesList = tagCompound.getTagList(Names.NBT.TILE_ENTITIES, Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < tileEntitiesList.tagCount(); i++) {
        try {
            final TileEntity tileEntity = NBTHelper.readTileEntityFromCompound(tileEntitiesList.getCompoundTagAt(i));
            if (tileEntity != null) {
                schematic.setTileEntity(tileEntity.getPos(), tileEntity);
            }
        } catch (final Exception e) {
            Reference.logger.error("TileEntity failed to load properly!", e);
        }
    }
    return schematic;
}
Also used : ISchematic(com.github.lunatrius.schematica.api.ISchematic) IBlockState(net.minecraft.block.state.IBlockState) HashMap(java.util.HashMap) MBlockPos(com.github.lunatrius.core.util.math.MBlockPos) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagList(net.minecraft.nbt.NBTTagList) TileEntity(net.minecraft.tileentity.TileEntity) ResourceLocation(net.minecraft.util.ResourceLocation) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) ISchematic(com.github.lunatrius.schematica.api.ISchematic) Schematic(com.github.lunatrius.schematica.world.storage.Schematic)

Example 5 with Schematic

use of com.github.lunatrius.schematica.world.storage.Schematic in project defrag by Edouard127.

the class SchematicStructure method readFromNBT.

@Override
public Object readFromNBT(final NBTTagCompound tagCompound) {
    final ItemStack icon = SchematicUtil.getIconFromNBT(tagCompound);
    final Template template = new Template();
    template.read(tagCompound);
    final Schematic schematic = new Schematic(icon, template.getSize().getX(), template.getSize().getY(), template.getSize().getZ(), template.getAuthor());
    return null;
}
Also used : ItemStack(net.minecraft.item.ItemStack) ISchematic(com.github.lunatrius.schematica.api.ISchematic) Schematic(com.github.lunatrius.schematica.world.storage.Schematic) Template(net.minecraft.world.gen.structure.template.Template)

Aggregations

ISchematic (com.github.lunatrius.schematica.api.ISchematic)13 Schematic (com.github.lunatrius.schematica.world.storage.Schematic)13 TileEntity (net.minecraft.tileentity.TileEntity)11 MBlockPos (com.github.lunatrius.core.util.math.MBlockPos)6 IBlockState (net.minecraft.block.state.IBlockState)6 ItemStack (net.minecraft.item.ItemStack)4 BlockPos (net.minecraft.util.math.BlockPos)4 Vec3i (net.minecraft.util.math.Vec3i)4 HashMap (java.util.HashMap)2 Block (net.minecraft.block.Block)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 Template (net.minecraft.world.gen.structure.template.Template)2 NBTConversionException (com.github.lunatrius.schematica.nbt.NBTConversionException)1 SchematicContainer (com.github.lunatrius.schematica.world.chunk.SchematicContainer)1 File (java.io.File)1 IOException (java.io.IOException)1