Skip to content

Commit

Permalink
Added optional properties for giving effects on consuming food
Browse files Browse the repository at this point in the history
  • Loading branch information
wothers committed May 20, 2023
1 parent 23bc6fa commit 00eb767
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/main/java/wothers/hr/items/HyperFood.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
package wothers.hr.items;

import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.item.FoodComponent;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

public class HyperFood extends HyperItem {
private final int hunger;
private final float saturation;
private final boolean isSnack;
private final String effect;
private final int effectDuration;
private final int effectAmplifier;
private final float effectChance;

public HyperFood(int maxStackSize, int hunger, float saturation, boolean isSnack, boolean isFireproof) {
this(maxStackSize, hunger, saturation, isSnack, null, 0, 0, 0f, isFireproof);
}

public HyperFood(int maxStackSize, int hunger, float saturation, boolean isSnack, String effect, int effectDuration, int effectAmplifier, float effectChance, boolean isFireproof) {
super(maxStackSize, isFireproof);
this.hunger = hunger;
this.saturation = saturation;
this.isSnack = isSnack;
this.effect = effect;
this.effectDuration = effectDuration;
this.effectAmplifier = effectAmplifier;
this.effectChance = effectChance;
}

@Override
Expand All @@ -25,6 +40,8 @@ public Item getItem() {
FoodComponent.Builder builder = new FoodComponent.Builder().hunger(hunger).saturationModifier(saturation);
if (isSnack)
builder = builder.snack();
if (effect != null)
builder = builder.statusEffect(new StatusEffectInstance(Registry.STATUS_EFFECT.get(new Identifier(effect)), effectDuration, effectAmplifier), effectChance);
item = new Item(settings.food(builder.build()));
}
return item;
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/wothers/ift/ItemsFromText.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ private void parseItem(String namespaceName, String itemName, Properties p) {
int hunger = Integer.parseInt(p.getProperty("hunger"));
float saturation = Float.parseFloat(p.getProperty("saturation"));
boolean isSnack = Boolean.parseBoolean(p.getProperty("isSnack"));
item = new HyperFood(Integer.parseInt(p.getProperty("stack")), hunger, saturation, isSnack, isFireproof);
String effect = p.getProperty("effect");
if (effect != null) {
int effectDuration = Integer.parseInt(p.getProperty("effectDuration"));
int effectAmplifier = Integer.parseInt(p.getProperty("effectAmplifier"));
float effectChance = Float.parseFloat(p.getProperty("effectChance"));
item = new HyperFood(Integer.parseInt(p.getProperty("stack")), hunger, saturation, isSnack, effect, effectDuration, effectAmplifier, effectChance, isFireproof);
} else {
item = new HyperFood(Integer.parseInt(p.getProperty("stack")), hunger, saturation, isSnack, isFireproof);
}
break;
case "tool":
float miningSpeed = Float.parseFloat(p.getProperty("miningSpeed"));
Expand Down

0 comments on commit 00eb767

Please sign in to comment.