mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-28 07:55:53 +00:00
Add Shears ToolActions (#7997)
Make shear interactions extend to subclasses Add Shears actions for beehive harvesting, pumpkin carving and trip wire disarming
This commit is contained in:
1 parent
c5a1c90366
commit
a336e443f7
31 files changed
+231
-161
No files matched your search
@@ -0,0 +1,61 @@
|
||||
package net.minecraftforge.common.loot;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParam;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
|
||||
import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType;
|
||||
import net.minecraftforge.common.ToolAction;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* This LootItemCondition "forge:can_tool_perform_action" can be used to check if a tool can perform a given ToolAction.
|
||||
*/
|
||||
public class CanToolPerformAction implements LootItemCondition {
|
||||
|
||||
public static final LootItemConditionType LOOT_CONDITION_TYPE = new LootItemConditionType(new CanToolPerformAction.Serializer());
|
||||
|
||||
final ToolAction action;
|
||||
|
||||
public CanToolPerformAction(ToolAction action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public LootItemConditionType getType() {
|
||||
return LOOT_CONDITION_TYPE;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Set<LootContextParam<?>> getReferencedContextParams() {
|
||||
return ImmutableSet.of(LootContextParams.TOOL);
|
||||
}
|
||||
|
||||
public boolean test(LootContext lootContext) {
|
||||
ItemStack itemstack = lootContext.getParamOrNull(LootContextParams.TOOL);
|
||||
return itemstack != null && itemstack.canPerformAction(this.action);
|
||||
}
|
||||
|
||||
public static LootItemCondition.Builder canToolPerformAction(ToolAction action) {
|
||||
return () -> new CanToolPerformAction(action);
|
||||
}
|
||||
|
||||
public static class Serializer implements net.minecraft.world.level.storage.loot.Serializer<CanToolPerformAction> {
|
||||
public void serialize(JsonObject json, CanToolPerformAction itemCondition, @Nonnull JsonSerializationContext context) {
|
||||
json.addProperty("action", itemCondition.action.name());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public CanToolPerformAction deserialize(JsonObject json, @Nonnull JsonDeserializationContext context) {
|
||||
return new CanToolPerformAction(ToolAction.get(json.get("action").getAsString()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user