Search in sources :

Example 1 with CubeMarkerData

use of riskyken.armourersWorkshop.common.skin.cubes.CubeMarkerData 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 2 with CubeMarkerData

use of riskyken.armourersWorkshop.common.skin.cubes.CubeMarkerData in project Armourers-Workshop by RiskyKen.

the class RenderItemBowSkin method renderItem.

@Override
public void renderItem(ItemRenderType type, ItemStack stack, Object... data) {
    if (canRenderModel(stack) & type != ItemRenderType.INVENTORY) {
        if (type != ItemRenderType.ENTITY) {
            GL11.glPopMatrix();
        // GL11.glPopMatrix();
        // GL11.glRotatef(-135, 0, 1, 0);
        // GL11.glRotatef(-10, 0, 0, 1);
        }
        GL11.glPushMatrix();
        AbstractClientPlayer player = null;
        int useCount = 0;
        boolean hasArrow = false;
        if (data.length >= 2) {
            if (data[1] instanceof AbstractClientPlayer & data[0] instanceof RenderBlocks) {
                RenderBlocks renderBlocks = (RenderBlocks) data[0];
                player = (AbstractClientPlayer) data[1];
                useCount = player.getItemInUseDuration();
                hasArrow = player.inventory.hasItem(Items.arrow);
                IEntityEquipment entityEquipment = SkinModelRenderer.INSTANCE.getPlayerCustomEquipmentData(player);
                if (!hasArrow) {
                    if (player.capabilities.isCreativeMode) {
                        hasArrow = true;
                    }
                }
            }
        }
        float scale = 0.0625F;
        float angle = (float) (((double) System.currentTimeMillis() / 5) % 360F);
        switch(type) {
            case EQUIPPED:
                GL11.glScalef(1F, -1F, 1F);
                GL11.glScalef(1.6F, 1.6F, 1.6F);
                GL11.glRotatef(-135, 0, 1, 0);
                GL11.glRotatef(10, 0, 0, 1);
                GL11.glRotatef(-20, 1, 0, 0);
                GL11.glRotatef(90, 0, 1, 0);
                GL11.glTranslatef(0F * scale, -6F * scale, 1F * scale);
                break;
            case ENTITY:
                GL11.glRotatef(180, 0, 0, 1);
                GL11.glTranslatef(0F, -10F * scale, 0F);
                break;
            case EQUIPPED_FIRST_PERSON:
                GL11.glScalef(1.6F, 1.6F, 1.6F);
                GL11.glRotatef(-135, 0, 1, 0);
                GL11.glRotatef(180, 0, 0, 1);
                GL11.glRotatef(-90, 0, 1, 0);
                // Back tilt
                GL11.glRotatef(-17, 1, 0, 0);
                GL11.glRotatef(2, 0, 0, 1);
                GL11.glTranslatef(0F * scale, -2F * scale, 1F * scale);
                if (useCount > 0) {
                    GL11.glTranslatef(-5 * scale, 3 * scale, 1 * scale);
                    GL11.glRotatef(-6, 1, 0, 0);
                    GL11.glRotatef(-16, 0, 1, 0);
                    GL11.glRotatef(2, 0, 0, 1);
                }
                break;
            default:
                break;
        }
        GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
        GL11.glEnable(GL11.GL_CULL_FACE);
        ModRenderHelper.enableAlphaBlend();
        ModelSkinBow model = SkinModelRenderer.INSTANCE.customBow;
        model.frame = getAnimationFrame(useCount);
        SkinPointer skinPointer = SkinNBTHelper.getSkinPointerFromStack(stack);
        Skin skin = ClientSkinCache.INSTANCE.getSkin(skinPointer);
        model.render(player, skin, false, skinPointer.getSkinDye(), null, false, 0, false);
        if (hasArrow & useCount > 0) {
            GL11.glTranslatef(1 * scale, 1 * scale, -12 * scale);
            int tarPart = getAnimationFrame(useCount);
            if (skin.getParts().get(tarPart).getMarkerBlocks().size() > 0) {
                CubeMarkerData cmd = skin.getParts().get(tarPart).getMarkerBlocks().get(0);
                ForgeDirection dir = ForgeDirection.getOrientation(cmd.meta - 1);
                GL11.glTranslatef((-dir.offsetX + cmd.x) * scale, (-dir.offsetY + cmd.y) * scale, (dir.offsetZ + cmd.z) * scale);
                // Shift the arrow a little to stop z fighting.
                GL11.glTranslatef(-0.01F * scale, 0.01F * scale, -0.01F * scale);
                SkinPart skinPartArrow = skin.getPart("armourers:bow.arrow");
                if (skinPartArrow != null) {
                    SkinPartRenderer.INSTANCE.renderPart(skinPartArrow, scale, skinPointer.getSkinDye(), null, false);
                } else {
                    ModelArrow.MODEL.render(scale, false);
                }
            }
        }
        GL11.glPopAttrib();
        GL11.glPopMatrix();
        if (type != ItemRenderType.ENTITY) {
            // GL11.glPushMatrix();
            GL11.glPushMatrix();
        }
    } else {
        if (itemRenderer != null) {
            itemRenderer.renderItem(type, stack, data);
        } else {
            renderNomalIcon(stack);
        }
    }
}
Also used : AbstractClientPlayer(net.minecraft.client.entity.AbstractClientPlayer) RenderBlocks(net.minecraft.client.renderer.RenderBlocks) SkinPointer(riskyken.armourersWorkshop.common.skin.data.SkinPointer) CubeMarkerData(riskyken.armourersWorkshop.common.skin.cubes.CubeMarkerData) IEntityEquipment(riskyken.armourersWorkshop.api.common.skin.IEntityEquipment) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ModelSkinBow(riskyken.armourersWorkshop.client.model.skin.ModelSkinBow) Skin(riskyken.armourersWorkshop.common.skin.data.Skin) SkinPart(riskyken.armourersWorkshop.common.skin.data.SkinPart)

Example 3 with CubeMarkerData

use of riskyken.armourersWorkshop.common.skin.cubes.CubeMarkerData in project Armourers-Workshop by RiskyKen.

the class SkinPartSerializer method loadSkinPart.

public static SkinPart loadSkinPart(DataInputStream stream, int version) throws IOException, InvalidCubeTypeException {
    ISkinPartType skinPart = null;
    SkinCubeData cubeData = null;
    ArrayList<CubeMarkerData> markerBlocks = null;
    if (version < 6) {
        skinPart = SkinTypeRegistry.INSTANCE.getSkinPartFromLegacyId(stream.readByte());
        if (skinPart == null) {
            ModLogger.log(Level.ERROR, "Skin part was null");
            throw new IOException("Skin part was null");
        }
    } else {
        String regName = null;
        if (version > 12) {
            regName = StreamUtils.readString(stream, Charsets.US_ASCII);
        } else {
            regName = stream.readUTF();
        }
        if (regName.equals("armourers:skirt.base")) {
            regName = "armourers:legs.skirt";
        }
        if (regName.equals("armourers:bow.base")) {
            regName = "armourers:bow.frame1";
        }
        if (regName.equals("armourers:arrow.base")) {
            regName = "armourers:bow.arrow";
        }
        skinPart = SkinTypeRegistry.INSTANCE.getSkinPartFromRegistryName(regName);
        if (skinPart == null) {
            ModLogger.log(Level.ERROR, "Skin part was null - reg name: " + regName + " version: " + version);
            throw new IOException("Skin part was null - reg name: " + regName + " version: " + version);
        }
    }
    cubeData = new SkinCubeData();
    cubeData.readFromStream(stream, version, skinPart);
    markerBlocks = new ArrayList<CubeMarkerData>();
    if (version > 8) {
        int markerCount = stream.readInt();
        for (int i = 0; i < markerCount; i++) {
            markerBlocks.add(new CubeMarkerData(stream, version));
        }
    }
    return new SkinPart(cubeData, skinPart, markerBlocks);
}
Also used : ISkinPartType(riskyken.armourersWorkshop.api.common.skin.type.ISkinPartType) SkinCubeData(riskyken.armourersWorkshop.common.skin.data.SkinCubeData) CubeMarkerData(riskyken.armourersWorkshop.common.skin.cubes.CubeMarkerData) IOException(java.io.IOException) SkinPart(riskyken.armourersWorkshop.common.skin.data.SkinPart)

Example 4 with CubeMarkerData

use of riskyken.armourersWorkshop.common.skin.cubes.CubeMarkerData in project Armourers-Workshop by RiskyKen.

the class ArmourerWorldHelper method saveArmourBlockToList.

private static void saveArmourBlockToList(World world, int x, int y, int z, int ix, int iy, int iz, SkinCubeData cubeData, int index, ArrayList<CubeMarkerData> markerBlocks, ForgeDirection direction) {
    Block block = world.getBlock(x, y, z);
    if (!CubeRegistry.INSTANCE.isBuildingBlock(block)) {
        return;
    }
    int meta = world.getBlockMetadata(x, y, z);
    ICubeColour c = BlockUtils.getColourFromTileEntity(world, x, y, z);
    byte cubeType = CubeRegistry.INSTANCE.getCubeFromBlock(block).getId();
    cubeData.setCubeId(index, cubeType);
    cubeData.setCubeLocation(index, (byte) ix, (byte) iy, (byte) iz);
    for (int i = 0; i < 6; i++) {
        cubeData.setCubeColour(index, i, c.getRed(i), c.getGreen(i), c.getBlue(i));
        cubeData.setCubePaintType(index, i, c.getPaintType(i));
    }
    if (meta > 0) {
        markerBlocks.add(new CubeMarkerData((byte) ix, (byte) iy, (byte) iz, (byte) meta));
    }
}
Also used : CubeMarkerData(riskyken.armourersWorkshop.common.skin.cubes.CubeMarkerData) ICubeColour(riskyken.armourersWorkshop.api.common.skin.cubes.ICubeColour) Block(net.minecraft.block.Block) SkinBlock(riskyken.armourersWorkshop.common.skin.type.block.SkinBlock)

Example 5 with CubeMarkerData

use of riskyken.armourersWorkshop.common.skin.cubes.CubeMarkerData in project Armourers-Workshop by RiskyKen.

the class ArmourerWorldHelper method loadSkinPartIntoWorld.

private static void loadSkinPartIntoWorld(World world, SkinPart partData, int xCoord, int yCoord, int zCoord, ForgeDirection direction, boolean mirror) {
    ISkinPartType skinPart = partData.getPartType();
    IRectangle3D buildSpace = skinPart.getBuildingSpace();
    IPoint3D offset = skinPart.getOffset();
    SkinCubeData cubeData = partData.getCubeData();
    for (int i = 0; i < cubeData.getCubeCount(); i++) {
        ICube blockData = cubeData.getCube(i);
        int meta = 0;
        for (int j = 0; j < partData.getMarkerBlocks().size(); j++) {
            CubeMarkerData cmd = partData.getMarkerBlocks().get(j);
            byte[] loc = cubeData.getCubeLocation(i);
            if (cmd.x == loc[0] & cmd.y == loc[1] & cmd.z == loc[2]) {
                meta = cmd.meta;
                break;
            }
        }
        int xOrigin = -offset.getX();
        int yOrigin = -offset.getY() + -buildSpace.getY();
        int zOrigin = offset.getZ();
        loadSkinBlockIntoWorld(world, xCoord, yCoord, zCoord, xOrigin, yOrigin, zOrigin, blockData, direction, meta, cubeData, i, mirror);
    }
}
Also used : ISkinPartType(riskyken.armourersWorkshop.api.common.skin.type.ISkinPartType) SkinCubeData(riskyken.armourersWorkshop.common.skin.data.SkinCubeData) IPoint3D(riskyken.armourersWorkshop.api.common.IPoint3D) IRectangle3D(riskyken.armourersWorkshop.api.common.IRectangle3D) CubeMarkerData(riskyken.armourersWorkshop.common.skin.cubes.CubeMarkerData) ICube(riskyken.armourersWorkshop.common.skin.cubes.ICube)

Aggregations

CubeMarkerData (riskyken.armourersWorkshop.common.skin.cubes.CubeMarkerData)5 SkinCubeData (riskyken.armourersWorkshop.common.skin.data.SkinCubeData)3 SkinPart (riskyken.armourersWorkshop.common.skin.data.SkinPart)3 Block (net.minecraft.block.Block)2 IPoint3D (riskyken.armourersWorkshop.api.common.IPoint3D)2 IRectangle3D (riskyken.armourersWorkshop.api.common.IRectangle3D)2 ISkinPartType (riskyken.armourersWorkshop.api.common.skin.type.ISkinPartType)2 SkinBlock (riskyken.armourersWorkshop.common.skin.type.block.SkinBlock)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 AbstractClientPlayer (net.minecraft.client.entity.AbstractClientPlayer)1 RenderBlocks (net.minecraft.client.renderer.RenderBlocks)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1 IEntityEquipment (riskyken.armourersWorkshop.api.common.skin.IEntityEquipment)1 ICubeColour (riskyken.armourersWorkshop.api.common.skin.cubes.ICubeColour)1 ModelSkinBow (riskyken.armourersWorkshop.client.model.skin.ModelSkinBow)1 SkinSaveException (riskyken.armourersWorkshop.common.exception.SkinSaveException)1 ICube (riskyken.armourersWorkshop.common.skin.cubes.ICube)1 Skin (riskyken.armourersWorkshop.common.skin.data.Skin)1 SkinPointer (riskyken.armourersWorkshop.common.skin.data.SkinPointer)1