Search in sources :

Example 6 with ItemMaterial

use of pl.asie.charset.lib.material.ItemMaterial in project Charset by CharsetMC.

the class IngredientMaterial method createMatchingStacks.

@Override
protected ItemStack[][] createMatchingStacks() {
    if (chain != null) {
        List<ItemStack> stacks = new ArrayList<>();
        for (ItemStack stack : dependency.getMatchingStacks()) {
            ItemMaterial materialOut = getChainedMaterial(ItemMaterialRegistry.INSTANCE.getOrCreateMaterial(stack));
            if (materialOut != null) {
                stacks.add(materialOut.getStack());
            }
        }
        ItemStack[][] stackArrays = new ItemStack[stacks.size()][1];
        for (int i = 0; i < stacks.size(); i++) {
            stackArrays[i][0] = stacks.get(i);
        }
        return stackArrays;
    } else {
        Collection<ItemMaterial> mats = ItemMaterialRegistry.INSTANCE.getMaterialsByTypes(types);
        ItemStack[][] stacks = new ItemStack[mats.size()][1];
        int idx = 0;
        for (ItemMaterial material : mats) {
            stacks[idx++][0] = material.getStack();
        }
        return stacks;
    }
}
Also used : ArrayList(java.util.ArrayList) ItemMaterial(pl.asie.charset.lib.material.ItemMaterial) ItemStack(net.minecraft.item.ItemStack)

Example 7 with ItemMaterial

use of pl.asie.charset.lib.material.ItemMaterial in project Charset by CharsetMC.

the class RenderTileEntityStacks method getQuads.

@Override
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
    if (side != null || !(state instanceof IExtendedBlockState)) {
        return Collections.emptyList();
    }
    TileEntityStacks stacks = ((IExtendedBlockState) state).getValue(BlockStacks.PROPERTY_TILE);
    if (stacks == null || stacks.stacks.isEmpty()) {
        return Collections.emptyList();
    }
    List<BakedQuad> list = new ArrayList<>();
    int i = 0;
    for (ItemMaterial material : stacks.stacks) {
        Vec3d[] vecs = INGOT_POSITIONS[i];
        ItemMaterial blockMaterial = material.getRelated("block");
        TextureAtlasSprite sprite;
        int c;
        if (blockMaterial == null) {
            ItemStack ingotStack = material.getStack();
            sprite = RenderUtils.getItemSprite(new ItemStack(Blocks.IRON_BLOCK));
            c = ColorLookupHandler.INSTANCE.getColor(ingotStack, RenderUtils.AveragingMode.FULL) | 0xFF000000;
        } else {
            sprite = RenderUtils.getItemSprite(blockMaterial.getStack());
            c = Minecraft.getMinecraft().getItemColors().colorMultiplier(blockMaterial.getStack(), 0);
        }
        float[] color = new float[] { MathHelper.clamp(((c >> 16) & 0xFF) / 255.0f, 0, 1), MathHelper.clamp(((c >> 8) & 0xFF) / 255.0f, 0, 1), MathHelper.clamp(((c) & 0xFF) / 255.0f, 0, 1), 1.0f };
        int j = 0;
        int yOff = (i >> 3) & 1;
        for (int[] vecOrder : QUAD_ORDERS[yOff]) {
            UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(DefaultVertexFormats.ITEM);
            EnumFacing face = QUAD_FACES[yOff][j];
            builder.setTexture(sprite);
            builder.setApplyDiffuseLighting(isAmbientOcclusion());
            builder.setContractUVs(false);
            builder.setQuadOrientation(face);
            int uv_offset = j < 4 ? 1 : 0;
            if (yOff == 1)
                uv_offset = 1 - uv_offset;
            for (int k = 0; k < vecOrder.length; k++) {
                Vec3d vec = vecs[vecOrder[k]];
                int[] uv = QUAD_UVS[(k + uv_offset) & 3];
                for (int e = 0; e < builder.getVertexFormat().getElementCount(); e++) {
                    VertexFormatElement el = builder.getVertexFormat().getElement(e);
                    switch(el.getUsage()) {
                        case POSITION:
                            builder.put(e, (float) vec.x / 16f, (float) vec.y / 16f, (float) vec.z / 16f, 1);
                            break;
                        case COLOR:
                            builder.put(e, color);
                            break;
                        case NORMAL:
                            builder.put(e, face.getFrontOffsetX(), face.getFrontOffsetY(), face.getFrontOffsetZ(), 0);
                            break;
                        case UV:
                            float u = sprite.getInterpolatedU(uv[0]);
                            float v = sprite.getInterpolatedV(uv[1]);
                            builder.put(e, u, v, 0, 1);
                            break;
                        default:
                            builder.put(e);
                    }
                }
            }
            list.add(builder.build());
            j++;
        }
        i++;
    }
    return list;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) ItemMaterial(pl.asie.charset.lib.material.ItemMaterial) Vec3d(net.minecraft.util.math.Vec3d) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) VertexFormatElement(net.minecraft.client.renderer.vertex.VertexFormatElement) ItemStack(net.minecraft.item.ItemStack)

Example 8 with ItemMaterial

use of pl.asie.charset.lib.material.ItemMaterial in project Charset by CharsetMC.

the class TileEntityStacks method writeNBTData.

@Override
public NBTTagCompound writeNBTData(NBTTagCompound compound, boolean isClient) {
    compound = super.writeNBTData(compound, isClient);
    NBTTagList list = new NBTTagList();
    for (ItemMaterial stack : stacks) {
        NBTTagCompound cpd = new NBTTagCompound();
        stack.writeToNBT(cpd, "material");
        list.appendTag(cpd);
    }
    compound.setTag("stacks", list);
    return compound;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemMaterial(pl.asie.charset.lib.material.ItemMaterial)

Example 9 with ItemMaterial

use of pl.asie.charset.lib.material.ItemMaterial in project Charset by CharsetMC.

the class TileEntityStacks method offerStack.

public boolean offerStack(ItemStack stack) {
    if (!canAcceptStackType(stack) || stacks.size() >= 64) {
        return false;
    }
    ItemMaterial material = ItemMaterialRegistry.INSTANCE.getMaterialIfPresent(stack);
    stacks.add(material);
    markBlockForUpdate();
    return true;
}
Also used : ItemMaterial(pl.asie.charset.lib.material.ItemMaterial)

Example 10 with ItemMaterial

use of pl.asie.charset.lib.material.ItemMaterial in project Charset by CharsetMC.

the class CharsetTransportBoats method onJoinWorld.

@SubscribeEvent
public void onJoinWorld(EntityJoinWorldEvent event) {
    if (event.getEntity().getClass() == EntityBoat.class) {
        ItemStack boatStack = ItemBoatCharset.STACK.get();
        ItemMaterial plankMaterial = (boatStack != null) ? ItemBoatCharset.getMaterial(boatStack) : ItemMaterialRegistry.INSTANCE.getOrCreateMaterial(new ItemStack(Blocks.PLANKS, 1, ((EntityBoat) event.getEntity()).getBoatType().getMetadata()));
        event.setCanceled(true);
        EntityBoatCharset entityBoatCharset = new EntityBoatCharset(event.getWorld(), event.getEntity().posX, event.getEntity().posY, event.getEntity().posZ, plankMaterial);
        entityBoatCharset.rotationYaw = event.getEntity().rotationYaw;
        event.getWorld().spawnEntity(entityBoatCharset);
    }
}
Also used : EntityBoat(net.minecraft.entity.item.EntityBoat) ItemMaterial(pl.asie.charset.lib.material.ItemMaterial) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

ItemMaterial (pl.asie.charset.lib.material.ItemMaterial)11 ItemStack (net.minecraft.item.ItemStack)7 ArrayList (java.util.ArrayList)3 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)2 EnumFacing (net.minecraft.util.EnumFacing)2 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)2 IAction (crafttweaker.IAction)1 IItemStack (crafttweaker.api.item.IItemStack)1 TObjectIntHashMap (gnu.trove.map.hash.TObjectIntHashMap)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)1 VertexFormatElement (net.minecraft.client.renderer.vertex.VertexFormatElement)1 Entity (net.minecraft.entity.Entity)1 EntityBoat (net.minecraft.entity.item.EntityBoat)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 TileEntity (net.minecraft.tileentity.TileEntity)1