Skip to content

Commit

Permalink
Add addNoSilkTouchLootModifier. Close #1425
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredlll08 committed Feb 3, 2023
1 parent a00a38b commit 21ebe00
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
import com.blamejared.crafttweaker.api.loot.LootManager;
import com.blamejared.crafttweaker.api.loot.condition.LootConditions;
import com.blamejared.crafttweaker.api.loot.modifier.ILootModifier;
import com.blamejared.crafttweaker.natives.loot.condition.ExpandInvertedLootItemCondition;
import com.blamejared.crafttweaker.natives.loot.condition.ExpandLootItemBlockStatePropertyCondition;
import com.blamejared.crafttweaker.natives.loot.condition.ExpandMatchTool;
import com.blamejared.crafttweaker.natives.predicate.ExpandEnchantmentPredicate;
import com.blamejared.crafttweaker.natives.predicate.ExpandItemPredicate;
import com.blamejared.crafttweaker.natives.predicate.ExpandMinMaxBoundsInts;
import com.blamejared.crafttweaker_annotations.annotations.Document;
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.advancements.critereon.StatePropertiesPredicate;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.block.Block;
import org.openzen.zencode.java.ZenCodeType;

Expand Down Expand Up @@ -41,6 +44,28 @@ public static void addLootModifier(final Block internal, final String name, fina
);
}

/**
* Adds an {@link ILootModifier} to this block, with the given name, only if it is not harvested with the silk touch enchantment.
*
* @param internal The block to add the loot modifier to.
* @param name The name of the loot modifier to add.
* @param modifier The loot modifier to add.
*/
@ZenCodeType.Method
public static void addNoSilkTouchLootModifier(final Block internal, final String name, final ILootModifier modifier) {

LootManager.INSTANCE.getModifierManager().register(
name,
LootConditions.allOf(
ExpandLootItemBlockStatePropertyCondition.create(internal),
ExpandInvertedLootItemCondition.create(ExpandMatchTool.create(ExpandItemPredicate.create()
.hasEnchantment(ExpandEnchantmentPredicate.create(Enchantments.SILK_TOUCH))))
),

modifier
);
}

/**
* Adds an {@link ILootModifier} to this block, firing only if it matches the state outlined in the
* {@link StatePropertiesPredicate}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
import com.blamejared.crafttweaker.api.loot.LootManager;
import com.blamejared.crafttweaker.api.loot.condition.LootConditions;
import com.blamejared.crafttweaker.api.loot.modifier.ILootModifier;
import com.blamejared.crafttweaker.natives.loot.condition.ExpandInvertedLootItemCondition;
import com.blamejared.crafttweaker.natives.loot.condition.ExpandLootItemBlockStatePropertyCondition;
import com.blamejared.crafttweaker.natives.loot.condition.ExpandMatchTool;
import com.blamejared.crafttweaker.natives.predicate.ExpandEnchantmentPredicate;
import com.blamejared.crafttweaker.natives.predicate.ExpandItemPredicate;
import com.blamejared.crafttweaker.natives.predicate.ExpandMinMaxBoundsInts;
import com.blamejared.crafttweaker.natives.predicate.ExpandStatePropertiesPredicate;
import com.blamejared.crafttweaker_annotations.annotations.Document;
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.advancements.critereon.StatePropertiesPredicate;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.block.state.BlockState;
import org.openzen.zencode.java.ZenCodeType;

Expand Down Expand Up @@ -60,6 +63,31 @@ public static void addTargetedLootModifier(final BlockState internal, final Stri
);
}

/**
* Adds an {@link ILootModifier} to this block, with the given name, only if it is not harvested with the silk touch enchantment.
*
* @param internal The block to add the loot modifier to.
* @param name The name of the loot modifier to add.
* @param modifier The loot modifier to add.
*/
@ZenCodeType.Method
public static void addNoSilkTouchLootModifier(final BlockState internal, final String name, final ILootModifier modifier) {

final StatePropertiesPredicate.Builder properties = ExpandStatePropertiesPredicate.create();
internal.getProperties().forEach(it -> properties.hasProperty(it, internal.getValue(it).toString()));

LootManager.INSTANCE.getModifierManager().register(
name,
LootConditions.allOf(
ExpandLootItemBlockStatePropertyCondition.create(internal.getBlock()).setProperties(properties),
ExpandInvertedLootItemCondition.create(ExpandMatchTool.create(ExpandItemPredicate.create()
.hasEnchantment(ExpandEnchantmentPredicate.create(Enchantments.SILK_TOUCH))))
),

modifier
);
}

/**
* Adds an {@link ILootModifier} that fires if this block state gets broken with the given tool.
*
Expand Down

0 comments on commit 21ebe00

Please sign in to comment.