net.minecraft.world.storage.loot.functions.LootFunction Java Examples

The following examples show how to use net.minecraft.world.storage.loot.functions.LootFunction. 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: ChestGenHooks.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void addItem(ResourceLocation lootTable, ItemStack item, int minAmount, int additionalAmount, int weight) {
    LootEntryItem itemEntry = new LootEntryItem(item.getItem(), weight, 1, new LootFunction[]{
        new LootFunction(NO_CONDITIONS) {
            @Override
            public ItemStack apply(ItemStack stack, Random rand, LootContext context) {
                stack.setItemDamage(item.getItemDamage());
                stack.setTagCompound(item.getTagCompound());
                stack.setCount(minAmount + rand.nextInt(additionalAmount));
                return stack;
            }
        }
    }, NO_CONDITIONS, "#gregtech:loot_" + item.toString());
    if (lootEntryItems.containsKey(lootTable)) {
        lootEntryItems.get(lootTable).add(itemEntry);
    } else {
        lootEntryItems.put(lootTable, Lists.newArrayList(itemEntry));
    }
}
 
Example #2
Source File: AbstractItemLootEntry.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void addLoot(Collection<ItemStack> stacks, Random rand, LootContext context) {
    ItemStack itemStack = createItemStack();
    for (LootFunction lootfunction : this.functions) {
        if (LootConditionManager.testAllConditions(lootfunction.getConditions(), rand, context)) {
            itemStack = lootfunction.apply(itemStack, rand, context);
        }
    }
    if (!itemStack.isEmpty()) {
        if (itemStack.getCount() < itemStack.getItem().getItemStackLimit(itemStack)) {
            stacks.add(itemStack);
        } else {
            int i = itemStack.getCount();

            while (i > 0) {
                ItemStack itemstack1 = itemStack.copy();
                itemstack1.setCount(Math.min(itemStack.getMaxStackSize(), i));
                i -= itemstack1.getCount();
                stacks.add(itemstack1);
            }
        }
    }
}
 
Example #3
Source File: GTEventLootTableLoad.java    From GT-Classic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public void onLootTableLoad(LootTableLoadEvent event) {
	/*
	 * Iterates both the stack array and resource location array to create a 2d
	 * table
	 */
	if (GTConfig.general.addLootItems) {
		for (ItemStack item : lootpool) {
			for (ResourceLocation table : loottable) {
				if (event.getName().equals(table)) {
					event.getTable().getPool("main").addEntry(new LootEntryItem(item.getItem(), 16, 0, new LootFunction[] {
							createCountFunction(1, 6) }, NO_CONDITIONS, getStackResourceName(item)));
				}
			}
		}
	}
}
 
Example #4
Source File: SakuraEventLoader.java    From Sakura_mod with MIT License 5 votes vote down vote up
public static void addFishingLoot(ItemStack stack,int weight){
    LootCondition[] lootConditions = new LootCondition[0];
    LootFunction[] setMeta = new LootFunction[] { new SetMetadata(lootConditions, new RandomValueRange(stack.getMetadata())) };
    LootEntry entry = new LootEntryItem(stack.getItem(), weight, 0, setMeta, lootConditions, stack.getUnlocalizedName());

    FishinglootPools.add(entry);
}
 
Example #5
Source File: LootEntryMetaItem.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static LootEntryMetaItem deserialize(JsonObject object, JsonDeserializationContext context, int weight, int quality, LootCondition[] conditions) {
    String entryName = net.minecraftforge.common.ForgeHooks.readLootEntryName(object, "item");
    LootFunction[] lootFunctions;
    if (object.has("functions")) {
        lootFunctions = JsonUtils.deserializeClass(object, "functions", context, LootFunction[].class);
    } else {
        lootFunctions = new LootFunction[0];
    }
    String metaItemName = JsonUtils.getString(object, "name");
    MetaValueItem metaValueItem = getMetaItem(metaItemName);
    if (metaValueItem == null) {
        throw new IllegalArgumentException("Unknown meta item: '" + metaItemName + "'");
    }
    return new LootEntryMetaItem(metaValueItem, weight, quality, lootFunctions, conditions, entryName);
}
 
Example #6
Source File: LootEntryOreDict.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static LootEntryOreDict deserialize(JsonObject object, JsonDeserializationContext context, int weight, int quality, LootCondition[] conditions) {

        String entryName = net.minecraftforge.common.ForgeHooks.readLootEntryName(object, "item");
        LootFunction[] lootFunctions;
        if (object.has("functions")) {
            lootFunctions = JsonUtils.deserializeClass(object, "functions", context, LootFunction[].class);
        } else {
            lootFunctions = new LootFunction[0];
        }
        String oreDictName = JsonUtils.getString(object, "name");
        return new LootEntryOreDict(oreDictName, weight, quality, lootFunctions, conditions, entryName);
    }
 
Example #7
Source File: LootEntryMetaItem.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected LootEntryMetaItem(MetaValueItem metaValueItem, int weightIn, int qualityIn, LootFunction[] functionsIn, LootCondition[] conditionsIn, String entryName) {
    super(weightIn, qualityIn, functionsIn, conditionsIn, entryName);
    this.metaValueItem = metaValueItem;
}
 
Example #8
Source File: AbstractItemLootEntry.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected AbstractItemLootEntry(int weightIn, int qualityIn, LootFunction[] functionsIn, LootCondition[] conditionsIn, String entryName) {
    super(weightIn, qualityIn, conditionsIn, entryName);
    this.functions = functionsIn;
}
 
Example #9
Source File: LootEntryOreDict.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected LootEntryOreDict(String oreDictName, int weightIn, int qualityIn, LootFunction[] functionsIn, LootCondition[] conditionsIn, String entryName) {
    super(weightIn, qualityIn, functionsIn, conditionsIn, entryName);
    this.oreDictName = oreDictName;
}
 
Example #10
Source File: AbstractItemLootEntry.java    From GregTech with GNU Lesser General Public License v3.0 votes vote down vote up
AbstractItemLootEntry create(JsonObject jsonObject, int weightIn, int qualityIn, LootFunction[] functionsIn, LootCondition[] conditionsIn, String entryName);