net.minecraft.util.collection.DefaultedList Java Examples

The following examples show how to use net.minecraft.util.collection.DefaultedList. 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: ShapedCompressingRecipe.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
static DefaultedList<Ingredient> getIngredients(String[] strings_1, Map<String, Ingredient> map_1, int int_1, int int_2) {
    DefaultedList<Ingredient> defaultedList_1 = DefaultedList.ofSize(int_1 * int_2, Ingredient.EMPTY);
    Set<String> set_1 = Sets.newHashSet(map_1.keySet());
    set_1.remove(" ");

    for (int int_3 = 0; int_3 < strings_1.length; ++int_3) {
        for (int int_4 = 0; int_4 < strings_1[int_3].length(); ++int_4) {
            String string_1 = strings_1[int_3].substring(int_4, int_4 + 1);
            Ingredient ingredient_1 = map_1.get(string_1);
            if (ingredient_1 == null) {
                throw new JsonSyntaxException("Pattern references symbol '" + string_1 + "' but it's not defined in the key");
            }

            set_1.remove(string_1);
            defaultedList_1.set(int_4 + int_1 * int_3, ingredient_1);
        }
    }

    if (!set_1.isEmpty()) {
        throw new JsonSyntaxException("Key defines symbols that aren't used in pattern: " + set_1);
    } else {
        return defaultedList_1;
    }
}
 
Example #2
Source File: ShapedCompressingRecipeSerializer.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public T read(Identifier identifier_1, JsonObject jsonObject_1) {
    String string_1 = JsonHelper.getString(jsonObject_1, "group", "");
    Map<String, Ingredient> map_1 = ShapedCompressingRecipe.getComponents(JsonHelper.getObject(jsonObject_1, "key"));
    String[] strings_1 = ShapedCompressingRecipe.combinePattern(ShapedCompressingRecipe.getPattern(JsonHelper.getArray(jsonObject_1, "pattern")));
    int int_1 = strings_1[0].length();
    int int_2 = strings_1.length;
    DefaultedList<Ingredient> defaultedList_1 = ShapedCompressingRecipe.getIngredients(strings_1, map_1, int_1, int_2);
    ItemStack itemStack_1 = ShapedRecipe.getItemStack(JsonHelper.getObject(jsonObject_1, "result"));
    return factory.create(identifier_1, string_1, int_1, int_2, defaultedList_1, itemStack_1);
}
 
Example #3
Source File: ShapedCompressingRecipeSerializer.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public T read(Identifier identifier_1, PacketByteBuf packet) {
    int int_1 = packet.readVarInt();
    int int_2 = packet.readVarInt();
    String group = packet.readString(32767);
    DefaultedList<Ingredient> defaultedList_1 = DefaultedList.ofSize(int_1 * int_2, Ingredient.EMPTY);

    for (int int_3 = 0; int_3 < defaultedList_1.size(); ++int_3) {
        defaultedList_1.set(int_3, Ingredient.fromPacket(packet));
    }

    ItemStack itemStack_1 = packet.readItemStack();
    return factory.create(identifier_1, group, int_1, int_2, defaultedList_1, itemStack_1);
}
 
Example #4
Source File: ShapedCompressingRecipe.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
public ShapedCompressingRecipe(Identifier id, String group, int width, int height, DefaultedList<Ingredient> ingredients, ItemStack output) {
    this.id = id;
    this.group = group;
    this.width = width;
    this.height = height;
    this.ingredients = ingredients;
    this.output = output;
}
 
Example #5
Source File: RecipeInfo.java    From multiconnect with MIT License 5 votes vote down vote up
public static RecipeInfo<ShapelessRecipe> shapeless(String group, ItemStack output, ItemConvertible[]... inputs) {
    DefaultedList<Ingredient> ingredients = DefaultedList.of();
    for (ItemConvertible[] input : inputs) {
        ingredients.add(Ingredient.ofItems(input));
    }
    return new RecipeInfo<>(id -> new ShapelessRecipe(id, group, output, ingredients), RecipeSerializer.SHAPELESS, output);
}
 
Example #6
Source File: BatteryItem.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public void appendStacks(ItemGroup group, DefaultedList<ItemStack> groupStacks) {
    if (this.isIn(group)) {
        ItemStack charged = new ItemStack(this);
        GalacticraftEnergy.setEnergy(charged, MAX_ENERGY);
        groupStacks.add(charged);

        ItemStack depleted = new ItemStack(this);
        GalacticraftEnergy.setEnergy(depleted, 0);
        depleted.setDamage(depleted.getMaxDamage() - 1);
        groupStacks.add(depleted);
    }
}
 
Example #7
Source File: ShapelessCompressingRecipeSerializer.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
private static DefaultedList<Ingredient> getIngredients(JsonArray jsonArray_1) {
    DefaultedList<Ingredient> defaultedList_1 = DefaultedList.of();

    for (int int_1 = 0; int_1 < jsonArray_1.size(); ++int_1) {
        Ingredient ingredient_1 = Ingredient.fromJson(jsonArray_1.get(int_1));
        if (!ingredient_1.isEmpty()) {
            defaultedList_1.add(ingredient_1);
        }
    }

    return defaultedList_1;
}
 
Example #8
Source File: ShapelessCompressingRecipeSerializer.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
    public T read(Identifier id, PacketByteBuf packet) {
//            String group = packet.readString(32767);
        int ingredientCount = packet.readVarInt();
        DefaultedList<Ingredient> ingredients = DefaultedList.ofSize(ingredientCount, Ingredient.EMPTY);

        for (int index = 0; index < ingredients.size(); ++index) {
            ingredients.set(index, Ingredient.fromPacket(packet));
        }

        ItemStack result = packet.readItemStack();
        return factory.create(id, /*group, */result, ingredients);
    }
 
Example #9
Source File: ShapelessCompressingRecipeSerializer.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
    public T read(Identifier id, JsonObject json) {
//            String group = JsonHelper.getString(json, "group", "");
        DefaultedList<Ingredient> ingredients = getIngredients(JsonHelper.getArray(json, "ingredients"));
        if (ingredients.isEmpty()) {
            throw new JsonParseException("No ingredients for compressing recipe");
        } else if (ingredients.size() > 9) {
            throw new JsonParseException("Too many ingredients for compressing recipe");
        } else {
            ItemStack result = ShapelessCompressingRecipe.getStack(JsonHelper.getObject(json, "result"));
            return factory.create(id, /*group, */result, ingredients);
        }
    }
 
Example #10
Source File: OxygenTankItem.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public void appendStacks(ItemGroup itemGroup_1, DefaultedList<ItemStack> list) {
    if (this.isIn(itemGroup_1)) {
        list.add(applyDefaultTags(new ItemStack(this), 0));
        list.add(applyDefaultTags(new ItemStack(this), maxOxygen));
    }
}
 
Example #11
Source File: GuiBlockEntity.java    From LibGui with MIT License 4 votes vote down vote up
@Override
public DefaultedList<ItemStack> getItems() {
	return items;
}
 
Example #12
Source File: FabricationRecipe.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
@Override
public DefaultedList<Ingredient> getPreviewInputs() {
    DefaultedList<Ingredient> list = DefaultedList.of();
    list.add(this.input);
    return list;
}
 
Example #13
Source File: ShapelessCompressingRecipe.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
public DefaultedList<Ingredient> getInput() {
    return this.input;
}
 
Example #14
Source File: ShapelessCompressingRecipe.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
@Override
public DefaultedList<Ingredient> getPreviewInputs() {
    return this.input;
}
 
Example #15
Source File: ShapelessCompressingRecipe.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
public ShapelessCompressingRecipe(Identifier id, /*String group, */ItemStack output, DefaultedList<Ingredient> input) {
        this.id = id;
//        this.group = group;
        this.output = output;
        this.input = input;
    }
 
Example #16
Source File: ShapedCompressingRecipe.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
public DefaultedList<Ingredient> getPreviewInputs() {
    return this.ingredients;
}
 
Example #17
Source File: ShapedCompressingRecipe.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
public DefaultedList<Ingredient> getIngredients() {
    return ingredients;
}
 
Example #18
Source File: ImplementedInventory.java    From LibGui with MIT License 2 votes vote down vote up
/**
 * Gets the item list of this inventory.
 * Must return the same instance every time it's called.
 *
 * @return the item list
 */
DefaultedList<ItemStack> getItems();
 
Example #19
Source File: ImplementedInventory.java    From LibGui with MIT License 2 votes vote down vote up
/**
 * Creates an inventory from the item list.
 *
 * @param items the item list
 * @return a new inventory
 */
static ImplementedInventory of(DefaultedList<ItemStack> items) {
    return () -> items;
}
 
Example #20
Source File: ImplementedInventory.java    From LibGui with MIT License 2 votes vote down vote up
/**
 * Creates a new inventory with the size.
 *
 * @param size the inventory size
 * @return a new inventory
 */
static ImplementedInventory ofSize(int size) {
    return of(DefaultedList.ofSize(size, ItemStack.EMPTY));
}
 
Example #21
Source File: ShapelessCompressingRecipeSerializer.java    From Galacticraft-Rewoven with MIT License votes vote down vote up
T create(Identifier id, ItemStack output, DefaultedList<Ingredient> ingredients); 
Example #22
Source File: ShapedCompressingRecipeSerializer.java    From Galacticraft-Rewoven with MIT License votes vote down vote up
T create(Identifier id, String group, int int_1, int int_2, DefaultedList<Ingredient> input, ItemStack output);