use of com.github.lunatrius.schematica.api.ISchematic 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;
}
use of com.github.lunatrius.schematica.api.ISchematic 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;
}
use of com.github.lunatrius.schematica.api.ISchematic 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;
}
use of com.github.lunatrius.schematica.api.ISchematic 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;
}
use of com.github.lunatrius.schematica.api.ISchematic in project defrag by Edouard127.
the class RotationHelper method rotate.
public boolean rotate(final SchematicWorld world, final EnumFacing axis, final boolean forced) {
if (world == null) {
return false;
}
try {
final ISchematic schematic = world.getSchematic();
final Schematic schematicRotated = rotate(schematic, axis, forced);
updatePosition(world, axis);
world.setSchematic(schematicRotated);
for (final TileEntity tileEntity : world.getTileEntities()) {
world.initializeTileEntity(tileEntity);
}
return true;
} catch (final RotationException re) {
Reference.logger.error(re.getMessage());
} catch (final Exception e) {
Reference.logger.fatal("Something went wrong!", e);
}
return false;
}
Aggregations