codechicken.lib.util.ArrayUtils Java Examples

The following examples show how to use codechicken.lib.util.ArrayUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CCModel.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Generates copies of faces with clockwise vertices
 *
 * @return The model
 */
public static CCModel generateBackface(CCModel src, int srcpos, CCModel dst, int destpos, int length) {
    int vp = src.vp;
    if (srcpos % vp != 0 || destpos % vp != 0 || length % vp != 0) {
        throw new IllegalArgumentException("Vertices do not align with polygons");
    }

    int[][] o = new int[][] { { 0, 0 }, { 1, vp - 1 }, { 2, vp - 2 }, { 3, vp - 3 } };
    for (int i = 0; i < length; i++) {
        int b = (i / vp) * vp;
        int d = i % vp;
        int di = destpos + b + o[d][1];
        int si = srcpos + b + o[d][0];
        dst.verts[di] = src.verts[si].copy();
        for (int a = 0; a < src.attributes.size(); a++) {
            if (src.attributes.get(a) != null) {
                ArrayUtils.arrayCopy(src.attributes.get(a), si, dst.getOrAllocate(AttributeKeyRegistry.getAttributeKey(a)), di, 1);
            }
        }

        if (dst.normals() != null && dst.normals()[di] != null) {
            dst.normals()[di].negate();
        }
    }
    return dst;
}
 
Example #2
Source File: NEIClientConfig.java    From NotEnoughItems with MIT License 6 votes vote down vote up
private static void onWorldLoad(boolean newWorld) {
    world.config.setComment("World based configuration of NEI.\nMost of these options can be changed ingame.\nDeleting any element will restore it to it's default value");

    setWorldDefaults();
    creativeInv = new ItemStack[54];
    ArrayUtils.fillArray(creativeInv, ItemStack.EMPTY);
    LayoutManager.searchField.setText(getSearchExpression());
    LayoutManager.quantity.setText(Integer.toString(getItemQuantity()));
    SubsetWidget.loadHidden();

    if (newWorld && Minecraft.getMinecraft().isSingleplayer()) {
        world.config.getTag("inventory.cheatmode").setIntValue(Minecraft.getMinecraft().playerController.isInCreativeMode() ? 2 : 0);
    }

    NEIInfo.load(ClientUtils.getWorld());
}
 
Example #3
Source File: CCModel.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Copies length vertices and normals
 */
public static void copy(CCModel src, int srcpos, CCModel dst, int destpos, int length) {
    for (int k = 0; k < length; k++) {
        dst.verts[destpos + k] = src.verts[srcpos + k].copy();
    }

    for (int i = 0; i < src.attributes.size(); i++) {
        if (src.attributes.get(i) != null) {
            ArrayUtils.arrayCopy(src.attributes.get(i), srcpos, dst.getOrAllocate(AttributeKeyRegistry.getAttributeKey(i)), destpos, length);
        }
    }
}
 
Example #4
Source File: ItemQuadBakery.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static List<BakedQuad> bakeItem(TransformationMatrix transform, TextureAtlasSprite... sprites) {

        LambdaUtils.checkArgument(sprites, "Sprites must not be Null or empty!", ArrayUtils::isNullOrContainsNull);

        List<BakedQuad> quads = new LinkedList<>();
        for (int i = 0; i < sprites.length; i++) {
            TextureAtlasSprite sprite = sprites[i];
            quads.addAll(ItemLayerModel.getQuadsForSprite(i, sprite, transform));
        }
        return quads;
    }
 
Example #5
Source File: InventoryCopy.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public InventoryCopy(IInventory inv) {
    items = new ItemStack[inv.getSizeInventory()];
    ArrayUtils.fillArray(items, ItemStack.EMPTY, (Objects::isNull));
    accessible = new boolean[inv.getSizeInventory()];
    this.inv = inv;
    update();
}
 
Example #6
Source File: NEIClientPacketHandler.java    From NotEnoughItems with MIT License 5 votes vote down vote up
public static void sendOpenPotionWindow() {
    ItemStack[] potionStore = new ItemStack[9];
    ArrayUtils.fillArray(potionStore, ItemStack.EMPTY);
    InventoryUtils.readItemStacksFromTag(potionStore, NEIClientConfig.global.nbt.getCompoundTag("potionStore").getTagList("items", 10));
    PacketCustom packet = new PacketCustom(channel, 24);
    for (ItemStack stack : potionStore) {
        packet.writeItemStack(stack);
    }
    packet.sendToServer();
}
 
Example #7
Source File: PlayerSave.java    From NotEnoughItems with MIT License 5 votes vote down vote up
private void loadCreativeInv() {
    creativeInv = new ItemStack[54];
    ArrayUtils.fillArray(creativeInv, ItemStack.EMPTY);
    NBTTagList itemList = nbt.getTagList("creativeitems", 10);
    if (itemList != null) {
        InventoryUtils.readItemStacksFromTag(creativeInv, itemList);
    }
}
 
Example #8
Source File: ExtendedCreativeInv.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@Override
public boolean isEmpty() {
    ItemStack[] items;
    if (side.isClient()) {
        items = NEIClientConfig.creativeInv;
    } else {
        items = playerSave.creativeInv;
    }
    return ArrayUtils.count(items, (stack -> !stack.isEmpty())) <= 0;
}
 
Example #9
Source File: EnderItemStorage.java    From EnderStorage with MIT License 4 votes vote down vote up
@Override
public boolean isEmpty() {
    return ArrayUtils.count(items, (stack -> !stack.isEmpty())) <= 0;
}
 
Example #10
Source File: EnderItemStorage.java    From EnderStorage with MIT License 4 votes vote down vote up
public void empty() {
    items = new ItemStack[getSizeInventory()];
    ArrayUtils.fill(items, ItemStack.EMPTY);
}
 
Example #11
Source File: VertexAttribute.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static <R> R copyOf(AttributeKey<R> attr, R src, int length) {
    R dst = attr.newArray(length);
    ArrayUtils.arrayCopy(src, 0, dst, 0, ((Object[]) src).length);
    return dst;
}
 
Example #12
Source File: InventoryCopy.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public boolean isEmpty() {
    return ArrayUtils.count(items, (stack -> !stack.isEmpty())) <= 0;
}
 
Example #13
Source File: InventoryNBT.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public InventoryNBT(int size, CompoundNBT tag) {
    this.tag = tag;
    items = new ItemStack[size];
    ArrayUtils.fillArray(items, ItemStack.EMPTY, (Objects::isNull));
    readNBT();
}
 
Example #14
Source File: InventoryNBT.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public boolean isEmpty() {
    return ArrayUtils.count(items, (stack -> !stack.isEmpty())) <= 0;
}
 
Example #15
Source File: InventorySimple.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public InventorySimple(ItemStack[] items, int limit, String name) {
    this.items = items;
    ArrayUtils.fillArray(items, ItemStack.EMPTY, (Objects::isNull));
    this.limit = limit;
    this.name = name;
}
 
Example #16
Source File: InventorySimple.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public boolean isEmpty() {
    return ArrayUtils.count(items, (stack -> !stack.isEmpty())) <= 0;
}