Search in sources :

Example 16 with MBlockPos

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

the class RotationHelper method rotate.

public Schematic rotate(final ISchematic schematic, final EnumFacing axis, final boolean forced) throws RotationException {
    final Vec3i dimensionsRotated = rotateDimensions(axis, schematic.getWidth(), schematic.getHeight(), schematic.getLength());
    final Schematic schematicRotated = new Schematic(schematic.getIcon(), dimensionsRotated.getX(), dimensionsRotated.getY(), dimensionsRotated.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 blockStateRotated = rotateBlock(blockState, axis, forced);
        schematicRotated.setBlockState(rotatePos(pos, axis, dimensionsRotated, tmp), blockStateRotated);
    }
    final List<TileEntity> tileEntities = schematic.getTileEntities();
    for (final TileEntity tileEntity : tileEntities) {
        final BlockPos pos = tileEntity.getPos();
        tileEntity.setPos(new BlockPos(rotatePos(pos, axis, dimensionsRotated, tmp)));
        schematicRotated.setTileEntity(tileEntity.getPos(), tileEntity);
    }
    return schematicRotated;
}
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 17 with MBlockPos

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

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 18 with MBlockPos

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

the class SchematicWorld method replaceBlock.

@SuppressWarnings({ "rawtypes", "unchecked" })
public int replaceBlock(final BlockStateMatcher matcher, final BlockStateReplacer replacer, final Map<IProperty, Comparable> properties) {
    int count = 0;
    for (final MBlockPos pos : BlockPosHelper.getAllInBox(0, 0, 0, getWidth(), getHeight(), getLength())) {
        final IBlockState blockState = this.schematic.getBlockState(pos);
        // TODO: add support for tile entities?
        if (blockState.getBlock().hasTileEntity(blockState)) {
            continue;
        }
        if (matcher.apply(blockState)) {
            final IBlockState replacement = replacer.getReplacement(blockState, properties);
            // TODO: add support for tile entities?
            if (replacement.getBlock().hasTileEntity(replacement)) {
                continue;
            }
            if (this.schematic.setBlockState(pos, replacement)) {
                notifyBlockUpdate(pos.add(this.position), blockState, replacement, 3);
                count++;
            }
        }
    }
    return count;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) MBlockPos(com.github.lunatrius.core.util.math.MBlockPos)

Example 19 with MBlockPos

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

the class CommandSchematicaSave method execute.

@Override
public void execute(final MinecraftServer server, final ICommandSender sender, final String[] args) throws CommandException {
    if (args.length < 7) {
        throw new WrongUsageException(getUsage(sender));
    }
    if (!(sender instanceof EntityPlayer)) {
        throw new CommandException(Names.Command.Save.Message.PLAYERS_ONLY);
    }
    final EntityPlayer player = (EntityPlayer) sender;
    if (Schematica.proxy.isPlayerQuotaExceeded(player)) {
        throw new CommandException(Names.Command.Save.Message.QUOTA_EXCEEDED);
    }
    final MBlockPos from = new MBlockPos();
    final MBlockPos to = new MBlockPos();
    final String filename;
    final String name;
    final String format;
    try {
        from.set(parseCoord(args[0]), parseCoord(args[1]), parseCoord(args[2]));
        to.set(parseCoord(args[3]), parseCoord(args[4]), parseCoord(args[5]));
        name = args[6];
        if (args.length >= 8) {
            format = args[7];
            if (!SchematicFormat.FORMATS.containsKey(format)) {
                throw new CommandException(Names.Command.Save.Message.UNKNOWN_FORMAT, format);
            }
        } else {
            format = null;
        }
        filename = name + SchematicFormat.getExtension(format);
    } catch (final NumberFormatException exception) {
        throw new WrongUsageException(getUsage(sender));
    }
    Reference.logger.debug("Saving schematic from {} to {} to {}", from, to, filename);
    final File schematicDirectory = Schematica.proxy.getPlayerSchematicDirectory(player, true);
    if (schematicDirectory == null) {
        // Chances are that if this is null, we could not retrieve their UUID.
        Reference.logger.warn("Unable to determine the schematic directory for player {}", player);
        throw new CommandException(Names.Command.Save.Message.PLAYER_SCHEMATIC_DIR_UNAVAILABLE);
    }
    if (!schematicDirectory.exists()) {
        if (!schematicDirectory.mkdirs()) {
            Reference.logger.warn("Could not create player schematic directory {}", schematicDirectory.getAbsolutePath());
            throw new CommandException(Names.Command.Save.Message.PLAYER_SCHEMATIC_DIR_UNAVAILABLE);
        }
    }
    try {
        Schematica.proxy.saveSchematic(player, schematicDirectory, filename, player.getEntityWorld(), format, from, to);
        sender.sendMessage(new TextComponentTranslation(Names.Command.Save.Message.SAVE_SUCCESSFUL, name));
    } catch (final Exception e) {
        throw new CommandException(Names.Command.Save.Message.SAVE_FAILED, name);
    }
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) MBlockPos(com.github.lunatrius.core.util.math.MBlockPos) EntityPlayer(net.minecraft.entity.player.EntityPlayer) CommandException(net.minecraft.command.CommandException) File(java.io.File) NumberInvalidException(net.minecraft.command.NumberInvalidException) CommandException(net.minecraft.command.CommandException) WrongUsageException(net.minecraft.command.WrongUsageException)

Example 20 with MBlockPos

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

the class SchematicPrinter method print.

public boolean print(final WorldClient world, final EntityPlayerSP player) {
    final double dX = ClientProxy.playerPosition.x - this.schematic.position.x;
    final double dY = ClientProxy.playerPosition.y - this.schematic.position.y;
    final double dZ = ClientProxy.playerPosition.z - this.schematic.position.z;
    final int x = (int) Math.floor(dX);
    final int y = (int) Math.floor(dY);
    final int z = (int) Math.floor(dZ);
    final int range = ConfigurationHandler.placeDistance;
    final int minX = Math.max(0, x - range);
    final int maxX = Math.min(this.schematic.getWidth() - 1, x + range);
    int minY = Math.max(0, y - range);
    int maxY = Math.min(this.schematic.getHeight() - 1, y + range);
    final int minZ = Math.max(0, z - range);
    final int maxZ = Math.min(this.schematic.getLength() - 1, z + range);
    if (minX > maxX || minY > maxY || minZ > maxZ) {
        return false;
    }
    final int slot = player.inventory.currentItem;
    final boolean isSneaking = player.isSneaking();
    switch(schematic.layerMode) {
        case ALL:
            break;
        case SINGLE_LAYER:
            if (schematic.renderingLayer > maxY) {
                return false;
            }
            maxY = schematic.renderingLayer;
        // $FALL-THROUGH$
        case ALL_BELOW:
            if (schematic.renderingLayer < minY) {
                return false;
            }
            maxY = schematic.renderingLayer;
            break;
    }
    syncSneaking(player, true);
    final double blockReachDistance = this.minecraft.playerController.getBlockReachDistance() - 0.1;
    final double blockReachDistanceSq = blockReachDistance * blockReachDistance;
    for (final MBlockPos pos : BlockPosHelper.getAllInBoxXZY(minX, minY, minZ, maxX, maxY, maxZ)) {
        if (pos.distanceSqToCenter(dX, dY, dZ) > blockReachDistanceSq) {
            continue;
        }
        try {
            if (placeBlock(world, player, pos)) {
                return syncSlotAndSneaking(player, slot, isSneaking, true);
            }
        } catch (final Exception e) {
            Reference.logger.error("Could not place block!", e);
            return syncSlotAndSneaking(player, slot, isSneaking, false);
        }
    }
    return syncSlotAndSneaking(player, slot, isSneaking, true);
}
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