Search in sources :

Example 11 with SkinPart

use of riskyken.armourersWorkshop.common.skin.data.SkinPart in project Armourers-Workshop by RiskyKen.

the class ArmourerWorldHelper method saveSkinFromWorld.

/**
 * Converts blocks in the world into a skin class.
 * @param world The world.
 * @param skinProps The skin properties for this skin.
 * @param skinType The type of skin to save.
 * @param paintData Paint data for this skin.
 * @param xCoord Armourers x location.
 * @param yCoord Armourers y location.
 * @param zCoord Armourers z location.
 * @param directionDirection the armourer is facing.
 * @return
 * @throws InvalidCubeTypeException
 * @throws SkinSaveException
 */
public static Skin saveSkinFromWorld(World world, SkinProperties skinProps, ISkinType skinType, int[] paintData, int xCoord, int yCoord, int zCoord, ForgeDirection direction) throws SkinSaveException {
    ArrayList<SkinPart> parts = new ArrayList<SkinPart>();
    if (skinType == SkinTypeRegistry.skinBlock) {
        ISkinPartType partType = ((SkinBlock) SkinTypeRegistry.skinBlock).partBase;
        if (SkinProperties.PROP_BLOCK_MULTIBLOCK.getValue(skinProps)) {
            partType = ((SkinBlock) SkinTypeRegistry.skinBlock).partMultiblock;
        }
        SkinPart skinPart = saveArmourPart(world, partType, xCoord, yCoord, zCoord, direction, true);
        if (skinPart != null) {
            parts.add(skinPart);
        }
    } else {
        for (int i = 0; i < skinType.getSkinParts().size(); i++) {
            ISkinPartType partType = skinType.getSkinParts().get(i);
            SkinPart skinPart = saveArmourPart(world, partType, xCoord, yCoord, zCoord, direction, true);
            if (skinPart != null) {
                parts.add(skinPart);
            }
        }
    }
    if (paintData != null) {
        paintData = paintData.clone();
    }
    Skin skin = new Skin(skinProps, skinType, paintData, parts);
    // Check if there are any blocks in the build guides.
    if (skin.getParts().size() == 0 && !skin.hasPaintData()) {
        throw new SkinSaveException("Nothing to save.", SkinSaveExceptionType.NO_DATA);
    }
    // Check if the skin has all needed parts.
    for (int i = 0; i < skinType.getSkinParts().size(); i++) {
        ISkinPartType partType = skinType.getSkinParts().get(i);
        if (partType.isPartRequired()) {
            boolean havePart = false;
            for (int j = 0; j < skin.getPartCount(); j++) {
                if (partType == skin.getParts().get(j).getPartType()) {
                    havePart = true;
                    break;
                }
            }
            if (!havePart) {
                throw new SkinSaveException("Skin is missing part " + partType.getPartName(), SkinSaveExceptionType.MISSING_PARTS);
            }
        }
    }
    // Check if the skin is not a seat and a bed.
    if (SkinProperties.PROP_BLOCK_BED.getValue(skinProps) & SkinProperties.PROP_BLOCK_SEAT.getValue(skinProps)) {
        throw new SkinSaveException("Skin can not be a bed and a seat.", SkinSaveExceptionType.BED_AND_SEAT);
    }
    // Check if multiblock is valid.
    if (skinType == SkinTypeRegistry.skinBlock & SkinProperties.PROP_BLOCK_MULTIBLOCK.getValue(skinProps)) {
        SkinPart testPart = saveArmourPart(world, ((SkinBlock) SkinTypeRegistry.skinBlock).partBase, xCoord, yCoord, zCoord, direction, true);
        if (testPart == null) {
            throw new SkinSaveException("Multiblock has no blocks in the yellow area.", SkinSaveExceptionType.INVALID_MULTIBLOCK);
        }
    }
    return skin;
}
Also used : ISkinPartType(riskyken.armourersWorkshop.api.common.skin.type.ISkinPartType) SkinSaveException(riskyken.armourersWorkshop.common.exception.SkinSaveException) SkinBlock(riskyken.armourersWorkshop.common.skin.type.block.SkinBlock) ArrayList(java.util.ArrayList) Skin(riskyken.armourersWorkshop.common.skin.data.Skin) SkinPart(riskyken.armourersWorkshop.common.skin.data.SkinPart)

Example 12 with SkinPart

use of riskyken.armourersWorkshop.common.skin.data.SkinPart in project Armourers-Workshop by RiskyKen.

the class ArmourerWorldHelper method saveArmourPart.

private static SkinPart saveArmourPart(World world, ISkinPartType skinPart, int xCoord, int yCoord, int zCoord, ForgeDirection direction, boolean markerCheck) throws SkinSaveException {
    int cubeCount = getNumberOfCubesInPart(world, xCoord, yCoord, zCoord, skinPart);
    if (cubeCount < 1) {
        return null;
    }
    SkinCubeData cubeData = new SkinCubeData();
    cubeData.setCubeCount(cubeCount);
    ArrayList<CubeMarkerData> markerBlocks = new ArrayList<CubeMarkerData>();
    IRectangle3D buildSpace = skinPart.getBuildingSpace();
    IPoint3D offset = skinPart.getOffset();
    int i = 0;
    for (int ix = 0; ix < buildSpace.getWidth(); ix++) {
        for (int iy = 0; iy < buildSpace.getHeight(); iy++) {
            for (int iz = 0; iz < buildSpace.getDepth(); iz++) {
                int x = xCoord + ix + -offset.getX() + buildSpace.getX();
                int y = yCoord + iy + -offset.getY();
                int z = zCoord + iz + offset.getZ() + buildSpace.getZ();
                int xOrigin = -ix + -buildSpace.getX();
                int yOrigin = -iy + -buildSpace.getY();
                int zOrigin = -iz + -buildSpace.getZ();
                if (!world.isAirBlock(x, y, z)) {
                    Block block = world.getBlock(x, y, z);
                    if (CubeRegistry.INSTANCE.isBuildingBlock(block)) {
                        saveArmourBlockToList(world, x, y, z, xOrigin - 1, yOrigin - 1, -zOrigin, cubeData, i, markerBlocks, direction);
                        i++;
                    }
                }
            }
        }
    }
    if (markerCheck) {
        if (skinPart.getMinimumMarkersNeeded() > markerBlocks.size()) {
            throw new SkinSaveException("Missing marker for part " + skinPart.getPartName(), SkinSaveExceptionType.MARKER_ERROR);
        }
        if (markerBlocks.size() > skinPart.getMaximumMarkersNeeded()) {
            throw new SkinSaveException("Too many markers for part " + skinPart.getPartName(), SkinSaveExceptionType.MARKER_ERROR);
        }
    }
    return new SkinPart(cubeData, skinPart, markerBlocks);
}
Also used : SkinSaveException(riskyken.armourersWorkshop.common.exception.SkinSaveException) SkinCubeData(riskyken.armourersWorkshop.common.skin.data.SkinCubeData) IPoint3D(riskyken.armourersWorkshop.api.common.IPoint3D) CubeMarkerData(riskyken.armourersWorkshop.common.skin.cubes.CubeMarkerData) IRectangle3D(riskyken.armourersWorkshop.api.common.IRectangle3D) ArrayList(java.util.ArrayList) Block(net.minecraft.block.Block) SkinBlock(riskyken.armourersWorkshop.common.skin.type.block.SkinBlock) SkinPart(riskyken.armourersWorkshop.common.skin.data.SkinPart)

Example 13 with SkinPart

use of riskyken.armourersWorkshop.common.skin.data.SkinPart in project Armourers-Workshop by RiskyKen.

the class ArmourerWorldHelper method copySkinCubes.

public static void copySkinCubes(World world, int x, int y, int z, ISkinPartType srcPart, ISkinPartType desPart, boolean mirror) throws SkinSaveException {
    ArrayList<BlockLocation> blList = new ArrayList<BlockLocation>();
    SkinPart skinPart = saveArmourPart(world, srcPart, x, y, z, ForgeDirection.UNKNOWN, false);
    if (skinPart != null) {
        skinPart.setSkinPart(desPart);
        loadSkinPartIntoWorld(world, skinPart, x, y, z, ForgeDirection.UNKNOWN, mirror);
    }
}
Also used : ArrayList(java.util.ArrayList) BlockLocation(riskyken.armourersWorkshop.common.blocks.BlockLocation) SkinPart(riskyken.armourersWorkshop.common.skin.data.SkinPart)

Example 14 with SkinPart

use of riskyken.armourersWorkshop.common.skin.data.SkinPart in project Armourers-Workshop by RiskyKen.

the class TileEntitySkinnable method getBlockBounds.

public static float[] getBlockBounds(Skin skin, int gridX, int gridY, int gridZ, ForgeDirection dir) {
    float[] bounds = new float[6];
    float scale = 0.0625F;
    SkinPart skinPart = skin.getParts().get(0);
    gridX = MathHelper.clamp_int(gridX, 0, 2);
    gridY = MathHelper.clamp_int(gridY, 0, 2);
    gridZ = MathHelper.clamp_int(gridZ, 0, 2);
    Rectangle3D rec = skinPart.getBlockBounds(gridX, gridY, gridZ);
    switch(dir) {
        case NORTH:
            // rec = skinPart.getBlockBounds(gridX, gridY, 2 - gridZ);
            break;
        case EAST:
            rec = skinPart.getBlockBounds(2 - gridZ, gridY, gridX);
            break;
        case SOUTH:
            rec = skinPart.getBlockBounds(2 - gridX, gridY, 2 - gridZ);
            break;
        case WEST:
            rec = skinPart.getBlockBounds(gridZ, gridY, 2 - gridX);
            break;
        default:
            break;
    }
    if (rec != null) {
        int x = 8 + rec.getX();
        int y = 8 - rec.getHeight() - rec.getY();
        int z = 8 - rec.getDepth() - rec.getZ();
        bounds[0] = x * scale;
        bounds[1] = y * scale;
        bounds[2] = z * scale;
        bounds[3] = (x + rec.getWidth()) * scale;
        bounds[4] = (y + rec.getHeight()) * scale;
        bounds[5] = (z + rec.getDepth()) * scale;
        bounds = rotateBlockBounds(bounds, dir);
    } else {
        return null;
    }
    return bounds;
}
Also used : Rectangle3D(riskyken.armourersWorkshop.api.common.skin.Rectangle3D) SkinPart(riskyken.armourersWorkshop.common.skin.data.SkinPart)

Example 15 with SkinPart

use of riskyken.armourersWorkshop.common.skin.data.SkinPart in project Armourers-Workshop by RiskyKen.

the class SkinSerializer method writeToStream.

public static void writeToStream(Skin skin, DataOutputStream stream) throws IOException {
    // Write the skin file version.
    stream.writeInt(Skin.FILE_VERSION);
    // Write skin header.
    StreamUtils.writeString(stream, Charsets.US_ASCII, TAG_SKIN_HEADER);
    // Write skin props.
    StreamUtils.writeString(stream, Charsets.US_ASCII, TAG_SKIN_PROPS_HEADER);
    skin.getProperties().writeToStream(stream);
    StreamUtils.writeString(stream, Charsets.US_ASCII, TAG_SKIN_PROPS_FOOTER);
    // Write the skin type.
    StreamUtils.writeString(stream, Charsets.US_ASCII, TAG_SKIN_TYPE_HEADER);
    stream.writeUTF(skin.getSkinType().getRegistryName());
    StreamUtils.writeString(stream, Charsets.US_ASCII, TAG_SKIN_TYPE_FOOTER);
    // Write paint data.
    StreamUtils.writeString(stream, Charsets.US_ASCII, TAG_SKIN_PAINT_HEADER);
    if (skin.hasPaintData()) {
        stream.writeBoolean(true);
        for (int i = 0; i < SkinTexture.TEXTURE_SIZE; i++) {
            stream.writeInt(skin.getPaintData()[i]);
        }
    } else {
        stream.writeBoolean(false);
    }
    StreamUtils.writeString(stream, Charsets.US_ASCII, TAG_SKIN_PAINT_FOOTER);
    // Write parts
    stream.writeByte(skin.getParts().size());
    for (int i = 0; i < skin.getParts().size(); i++) {
        SkinPart skinPart = skin.getParts().get(i);
        StreamUtils.writeString(stream, Charsets.US_ASCII, TAG_SKIN_PART_HEADER);
        SkinPartSerializer.saveSkinPart(skinPart, stream);
        StreamUtils.writeString(stream, Charsets.US_ASCII, TAG_SKIN_PART_FOOTER);
    }
    // Write skin footer.
    StreamUtils.writeString(stream, Charsets.US_ASCII, TAG_SKIN_FOOTER);
}
Also used : SkinPart(riskyken.armourersWorkshop.common.skin.data.SkinPart)

Aggregations

SkinPart (riskyken.armourersWorkshop.common.skin.data.SkinPart)26 Skin (riskyken.armourersWorkshop.common.skin.data.Skin)10 EntityPlayer (net.minecraft.entity.player.EntityPlayer)8 ArrayList (java.util.ArrayList)5 IPoint3D (riskyken.armourersWorkshop.api.common.IPoint3D)5 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)3 ISkinPartType (riskyken.armourersWorkshop.api.common.skin.type.ISkinPartType)3 SkinModelTexture (riskyken.armourersWorkshop.client.skin.SkinModelTexture)3 CubeMarkerData (riskyken.armourersWorkshop.common.skin.cubes.CubeMarkerData)3 Color (java.awt.Color)2 IOException (java.io.IOException)2 AbstractClientPlayer (net.minecraft.client.entity.AbstractClientPlayer)2 IRectangle3D (riskyken.armourersWorkshop.api.common.IRectangle3D)2 IEntityEquipment (riskyken.armourersWorkshop.api.common.skin.IEntityEquipment)2 Rectangle3D (riskyken.armourersWorkshop.api.common.skin.Rectangle3D)2 ISkinPartTypeTextured (riskyken.armourersWorkshop.api.common.skin.type.ISkinPartTypeTextured)2 SkinSaveException (riskyken.armourersWorkshop.common.exception.SkinSaveException)2 SkinCubeData (riskyken.armourersWorkshop.common.skin.data.SkinCubeData)2 SkinBlock (riskyken.armourersWorkshop.common.skin.type.block.SkinBlock)2 MovementType (riskyken.armourersWorkshop.common.skin.type.wings.SkinWings.MovementType)2