Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 159 additions & 0 deletions patches/server/0313-Cure-effects-food-property.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aniket Joshi <arealronin@gmail.com>
Date: Thu, 6 Oct 2022 14:11:41 +0530
Subject: [PATCH] Cure effects food property


diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 1ec9a48f2f44f5bd647e0661423ae90970aee262..6aa57ecbf656e306a9ed358019c9eaff7da16730 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -4373,6 +4373,7 @@ public abstract class LivingEntity extends Entity {
if (stack.isEdible()) {
world.playSound((net.minecraft.world.entity.player.Player) null, this.getX(), this.getY(), this.getZ(), this.getEatingSound(stack), SoundSource.NEUTRAL, 1.0F, 1.0F + (world.random.nextFloat() - world.random.nextFloat()) * 0.4F);
this.addEatEffect(stack, world, this);
+ this.removeEatEffect(stack, world, this); // Purpur
if (!(this instanceof net.minecraft.world.entity.player.Player) || !((net.minecraft.world.entity.player.Player) this).getAbilities().instabuild) {
stack.shrink(1);
}
@@ -4401,6 +4402,23 @@ public abstract class LivingEntity extends Entity {

}

+ // Purpur start
+ private void removeEatEffect(ItemStack stack, Level world, LivingEntity targetEntity) {
+ Item item = stack.getItem();
+ List<MobEffect> list = item.getFoodProperties() != null ? item.getFoodProperties().getEffectsToCure() : null;
+
+ if (list != null && !world.isClientSide && item.isEdible() && !list.isEmpty()) {
+ Map<MobEffect, MobEffectInstance> effects = targetEntity.activeEffects;
+ if (!effects.isEmpty()) {
+ for (MobEffect effect : effects.keySet()) {
+ if (list.contains(effect))
+ targetEntity.removeEffect(effect, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.FOOD);
+ }
+ }
+ }
+ }
+ // Purpur end
+
private static byte entityEventForEquipmentBreak(EquipmentSlot slot) {
switch (slot) {
case MAINHAND:
diff --git a/src/main/java/net/minecraft/world/food/FoodProperties.java b/src/main/java/net/minecraft/world/food/FoodProperties.java
index 6c945ae8fe8b1517e312c688f829fab41f12d9f4..2c8944a7cc6d4b44a1a55927f6b292fb43d75b8c 100644
--- a/src/main/java/net/minecraft/world/food/FoodProperties.java
+++ b/src/main/java/net/minecraft/world/food/FoodProperties.java
@@ -15,12 +15,19 @@ public class FoodProperties {
private boolean canAlwaysEat; public void setCanAlwaysEat(boolean canAlwaysEat) { this.canAlwaysEat = canAlwaysEat; }
private boolean fastFood; public void setFastFood(boolean isFastFood) { this.fastFood = isFastFood; }
public FoodProperties copy() {
- return new FoodProperties(this.nutrition, this.saturationModifier, this.isMeat, this.canAlwaysEat, this.fastFood, new ArrayList<>(this.effects));
+ return new FoodProperties(this.nutrition, this.saturationModifier, this.isMeat, this.canAlwaysEat, this.fastFood, new ArrayList<>(this.effects), effectsToCure);
}
+ private final List<net.minecraft.world.effect.MobEffect> effectsToCure;
// Purpur end
private final List<Pair<MobEffectInstance, Float>> effects;

FoodProperties(int hunger, float saturationModifier, boolean meat, boolean alwaysEdible, boolean snack, List<Pair<MobEffectInstance, Float>> statusEffects) {
+ // Purpur start
+ this(hunger, saturationModifier, meat, alwaysEdible, snack, statusEffects, null);
+ }
+ FoodProperties(int hunger, float saturationModifier, boolean meat, boolean alwaysEdible, boolean snack, List<Pair<MobEffectInstance, Float>> statusEffects, List<net.minecraft.world.effect.MobEffect> effectsToCure) {
+ this.effectsToCure = effectsToCure;
+ // Purpur end
this.nutrition = hunger;
this.saturationModifier = saturationModifier;
this.isMeat = meat;
@@ -52,6 +59,11 @@ public class FoodProperties {
public List<Pair<MobEffectInstance, Float>> getEffects() {
return this.effects;
}
+ // Purpur start
+ public List<net.minecraft.world.effect.MobEffect> getEffectsToCure() {
+ return this.effectsToCure;
+ }
+ // Purpur end

public static class Builder {
private int nutrition;
@@ -60,6 +72,7 @@ public class FoodProperties {
private boolean canAlwaysEat;
private boolean fastFood;
private final List<Pair<MobEffectInstance, Float>> effects = Lists.newArrayList();
+ private final List<net.minecraft.world.effect.MobEffect> effectsToCure = new ArrayList<>(); // Purpur

public FoodProperties.Builder nutrition(int hunger) {
this.nutrition = hunger;
@@ -91,8 +104,15 @@ public class FoodProperties {
return this;
}

+ // Purpur start
+ public FoodProperties.Builder effectToCure(net.minecraft.world.effect.MobEffect effect) {
+ this.effectsToCure.add(effect);
+ return this;
+ }
+ // Purpur end
+
public FoodProperties build() {
- return new FoodProperties(this.nutrition, this.saturationModifier, this.isMeat, this.canAlwaysEat, this.fastFood, this.effects);
+ return new FoodProperties(this.nutrition, this.saturationModifier, this.isMeat, this.canAlwaysEat, this.fastFood, this.effects, this.effectsToCure); // Purpur
}
}
}
diff --git a/src/main/java/net/minecraft/world/food/Foods.java b/src/main/java/net/minecraft/world/food/Foods.java
index 71beab673f04cd051c46ea37f8c847316885d38d..254611b8ae84e3ede3d61768079a35a4134ab306 100644
--- a/src/main/java/net/minecraft/world/food/Foods.java
+++ b/src/main/java/net/minecraft/world/food/Foods.java
@@ -29,7 +29,7 @@ public class Foods {
public static final FoodProperties ENCHANTED_GOLDEN_APPLE = (new FoodProperties.Builder()).nutrition(4).saturationMod(1.2F).effect(new MobEffectInstance(MobEffects.REGENERATION, 400, 1), 1.0F).effect(new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 6000, 0), 1.0F).effect(new MobEffectInstance(MobEffects.FIRE_RESISTANCE, 6000, 0), 1.0F).effect(new MobEffectInstance(MobEffects.ABSORPTION, 2400, 3), 1.0F).alwaysEat().build();
public static final FoodProperties GOLDEN_APPLE = (new FoodProperties.Builder()).nutrition(4).saturationMod(1.2F).effect(new MobEffectInstance(MobEffects.REGENERATION, 100, 1), 1.0F).effect(new MobEffectInstance(MobEffects.ABSORPTION, 2400, 0), 1.0F).alwaysEat().build();
public static final FoodProperties GOLDEN_CARROT = (new FoodProperties.Builder()).nutrition(6).saturationMod(1.2F).build();
- public static final FoodProperties HONEY_BOTTLE = (new FoodProperties.Builder()).nutrition(6).saturationMod(0.1F).build();
+ public static final FoodProperties HONEY_BOTTLE = (new FoodProperties.Builder()).nutrition(6).saturationMod(0.1F).effectToCure(MobEffects.POISON).build(); // Purpur
public static final FoodProperties MELON_SLICE = (new FoodProperties.Builder()).nutrition(2).saturationMod(0.3F).build();
public static final FoodProperties MUSHROOM_STEW = stew(6).build();
public static final FoodProperties MUTTON = (new FoodProperties.Builder()).nutrition(2).saturationMod(0.3F).meat().build();
diff --git a/src/main/java/net/minecraft/world/item/HoneyBottleItem.java b/src/main/java/net/minecraft/world/item/HoneyBottleItem.java
index c8d6b5e60b6c8c612fa8580c63a32c4a8f8b0a7b..1dee3f9a4fbf55ee4c5082bab43c566b3b8130fb 100644
--- a/src/main/java/net/minecraft/world/item/HoneyBottleItem.java
+++ b/src/main/java/net/minecraft/world/item/HoneyBottleItem.java
@@ -27,9 +27,11 @@ public class HoneyBottleItem extends Item {
serverPlayer.awardStat(Stats.ITEM_USED.get(this));
}

- if (!world.isClientSide) {
- user.removeEffect(MobEffects.POISON, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.FOOD); // Paper
- }
+ // Purpur start - moved this to default food properties.
+ //if (!world.isClientSide) {
+ // user.removeEffect(MobEffects.POISON, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.FOOD); // Paper
+ //}
+ // Purpur end

if (stack.isEmpty()) {
return new ItemStack(Items.GLASS_BOTTLE);
diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
index ccca392a45cb05abb55ddd5c6c36e6f9c7a5d171..12478f4df9dc0dbbd7330e973204ec6f1cbd4ae8 100644
--- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java
+++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
@@ -571,6 +571,18 @@ public class PurpurConfig {
food.getEffects().add(Pair.of(new MobEffectInstance(effect, duration, amplifier, ambient, visible, showIcon), chance));
});
}
+ List<String> effectsToCure = properties.getStringList(foodKey + ".cure-effects");
+ if (!effectsToCure.isEmpty()) {
+ effectsToCure.forEach(effectKey -> {
+ MobEffect effect = Registry.MOB_EFFECT.get(new ResourceLocation(effectKey));
+ if (effect == null) {
+ PurpurConfig.log(Level.SEVERE, "Invalid food property cure effect for " + foodKey + ": " + effectKey);
+ return;
+ }
+ food.getEffectsToCure().removeIf(pair -> pair == effect);
+ food.getEffectsToCure().add(effect);
+ });
+ } else food.getEffectsToCure().clear();
});
}