Skip to content

Commit

Permalink
Fix delete stack docs and add PlayerInventory#remove
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredlll08 committed Jul 5, 2021
1 parent e4817dd commit 1545db9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
@@ -1,11 +1,15 @@
package com.blamejared.crafttweaker.impl_native.inventory;

import com.blamejared.crafttweaker.api.annotations.ZenRegister;
import com.blamejared.crafttweaker.api.item.IIngredient;
import com.blamejared.crafttweaker.api.item.IItemStack;
import com.blamejared.crafttweaker.impl.item.MCItemStack;
import com.blamejared.crafttweaker.impl.item.MCItemStackMutable;
import com.blamejared.crafttweaker_annotations.annotations.Document;
import com.blamejared.crafttweaker_annotations.annotations.NativeTypeRegistration;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import org.openzen.zencode.java.ZenCodeType;

@ZenRegister
Expand Down Expand Up @@ -88,9 +92,9 @@ public static boolean add(PlayerInventory internal, int slot, IItemStack stack)
}

/**
* Removes all instances of the given stack from the inventory.
* Removes the first instance of the given stack from the inventory.
*
* @param stack The stack to delete.
* @param stack The stack to remove.
*
* @docParam stack <item:minecraft:diamond>
*/
Expand Down Expand Up @@ -151,4 +155,23 @@ public static void setIItemStack(PlayerInventory internal, IItemStack stack) {
internal.setItemStack(stack.getInternal());
}

/**
* Removes all stacks that match the ingredient.
*
* @param ingredient The ingredient to match against.
*
* @docParam ingredient <item:minecraft:diamond>
*/
@ZenCodeType.Method
public static void remove(PlayerInventory internal, IIngredient ingredient) {

for(NonNullList<ItemStack> nonnulllist : internal.allInventories) {
for(int i = 0; i < nonnulllist.size(); ++i) {
if(ingredient.matches(new MCItemStackMutable(nonnulllist.get(i)))) {
nonnulllist.set(i, ItemStack.EMPTY);
}
}
}
}

}
2 changes: 2 additions & 0 deletions src/main/resources/META-INF/accesstransformer.cfg
Expand Up @@ -71,3 +71,5 @@ public net.minecraft.advancements.criterion.StatePropertiesPredicate$RangedMache

public net.minecraft.item.crafting.SmithingRecipe field_234838_b_ # addition
public net.minecraft.item.crafting.SmithingRecipe field_234837_a_ # base

public net.minecraft.entity.player.PlayerInventory field_184440_g # allInventories

0 comments on commit 1545db9

Please sign in to comment.