mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 08:27:43 +01:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@d129162 Properly handle BlockBreakEvent#isDropItems (#8936) PaperMC/Paper@67a1a8c Fix Inventory#getLocation not working for the composter (#9596) PaperMC/Paper@5b34a09 Add option to disable chorus plant and mushroom block updates (#9442) PaperMC/Paper@ed8401c Fix rotation for spawning display entities (#9552) PaperMC/Paper@bd67b83 Determine lava and water fluid explosion resistance by their block explosion resistance (#9482) PaperMC/Paper@d928dda Don't tab-complete namespaced commands if `send-namespaced` is false (#9366) PaperMC/Paper@f43a19c Fix CME in CraftPersistentDataTypeRegistry (#6701) PaperMC/Paper@45ba652 [ci skip] Rebuild patches PaperMC/Paper@990765b Fire entity death event for ender dragon (#9495) PaperMC/Paper@1259b93 Fixed CraftItemStack/CraftItemMeta enchantment level inconsistency (#8792) PaperMC/Paper@88891c3 Add Entity Coordinate and Rotation API (#9461) PaperMC/Paper@5bf82aa Add cancellability to PlayerTrackEntityEvent (#8605) PaperMC/Paper@1b96c64 Improve cancelling PreCreatureSpawnEvent with per player mob spawns (#9400) PaperMC/Paper@7232506 Add entity tracker min Y distance config option (#9406) PaperMC/Paper@00a68b1 Player listing API (#8782) PaperMC/Paper@af6142e [ci skip] Update Gradle wrapper PaperMC/Paper@281855c Remove unused lag-compensate-block-breaking option (#9635) PaperMC/Paper@35ef053 [ci skip] update editorconfig and gitattributes (#9608) PaperMC/Paper@97b9c4a Fix NPE on Boat#getStatus (#9115) PaperMC/Paper@2be57c6 Expand Pose API (#8781) PaperMC/Paper@b29ecd4 Expose clicked BlockFace during BlockDamageEvent (#9632) PaperMC/Paper@e3f29f4 MerchantRecipe: add copy constructor (#8703) PaperMC/Paper@fed9042 More DragonBattle API (#5655) PaperMC/Paper@27d39ca Properly clone custom nbt tags inside ItemMeta (#7849) PaperMC/Paper@0c7385b Add PlayerPickItemEvent (#5590) PaperMC/Paper@9395aa6 Improve performance of mass crafts (#9603) PaperMC/Paper@7386a13 Fix endgateway teleportation offset (#9517) PaperMC/Paper@a712766 Allow custom damage for trident (#8132) PaperMC/Paper@3716832 Prevent overfilled bundles from duplicating items (#9633) PaperMC/Paper@9cbad8e Expose Hand during BlockCanBuildEvent (#9636)
151 lines
8.5 KiB
Diff
151 lines
8.5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: BillyGalbreath <Blake.Galbreath@Gmail.com>
|
|
Date: Tue, 18 Jan 2022 04:51:51 -0600
|
|
Subject: [PATCH] Configurable food attributes
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/food/FoodProperties.java b/src/main/java/net/minecraft/world/food/FoodProperties.java
|
|
index 9967ba762567631f2bdb1e4f8fe16a13ea927b46..6c945ae8fe8b1517e312c688f829fab41f12d9f4 100644
|
|
--- a/src/main/java/net/minecraft/world/food/FoodProperties.java
|
|
+++ b/src/main/java/net/minecraft/world/food/FoodProperties.java
|
|
@@ -2,15 +2,22 @@ package net.minecraft.world.food;
|
|
|
|
import com.google.common.collect.Lists;
|
|
import com.mojang.datafixers.util.Pair;
|
|
+
|
|
+import java.util.ArrayList;
|
|
import java.util.List;
|
|
import net.minecraft.world.effect.MobEffectInstance;
|
|
|
|
public class FoodProperties {
|
|
- private final int nutrition;
|
|
- private final float saturationModifier;
|
|
- private final boolean isMeat;
|
|
- private final boolean canAlwaysEat;
|
|
- private final boolean fastFood;
|
|
+ // Purpur start
|
|
+ private int nutrition; public void setNutrition(int nutrition) { this.nutrition = nutrition; }
|
|
+ private float saturationModifier; public void setSaturationModifier(float saturation) { this.saturationModifier = saturation; }
|
|
+ private boolean isMeat; public void setIsMeat(boolean isMeat) { this.isMeat = isMeat; }
|
|
+ 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));
|
|
+ }
|
|
+ // 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) {
|
|
diff --git a/src/main/java/net/minecraft/world/food/Foods.java b/src/main/java/net/minecraft/world/food/Foods.java
|
|
index b16d9e2eaa589f19c563ee70b1a56d67dbcdecb0..71beab673f04cd051c46ea37f8c847316885d38d 100644
|
|
--- a/src/main/java/net/minecraft/world/food/Foods.java
|
|
+++ b/src/main/java/net/minecraft/world/food/Foods.java
|
|
@@ -4,6 +4,9 @@ import net.minecraft.world.effect.MobEffectInstance;
|
|
import net.minecraft.world.effect.MobEffects;
|
|
|
|
public class Foods {
|
|
+ public static final java.util.Map<String, FoodProperties> ALL_PROPERTIES = new java.util.HashMap<>(); // Purpur
|
|
+ public static final java.util.Map<String, FoodProperties> DEFAULT_PROPERTIES = new java.util.HashMap<>(); // Purpur
|
|
+
|
|
public static final FoodProperties APPLE = (new FoodProperties.Builder()).nutrition(4).saturationMod(0.3F).build();
|
|
public static final FoodProperties BAKED_POTATO = (new FoodProperties.Builder()).nutrition(5).saturationMod(0.6F).build();
|
|
public static final FoodProperties BEEF = (new FoodProperties.Builder()).nutrition(3).saturationMod(0.3F).meat().build();
|
|
diff --git a/src/main/java/net/minecraft/world/item/Items.java b/src/main/java/net/minecraft/world/item/Items.java
|
|
index 31f5ed9dd1727eee24804a384817d2b76a45676b..5fbb13ebef0ca66419f3e5006d19e4a5918a038a 100644
|
|
--- a/src/main/java/net/minecraft/world/item/Items.java
|
|
+++ b/src/main/java/net/minecraft/world/item/Items.java
|
|
@@ -1309,6 +1309,13 @@ public class Items {
|
|
((BlockItem)item).registerBlocks(Item.BY_BLOCK, item);
|
|
}
|
|
|
|
+ // Purpur start
|
|
+ if (item.getFoodProperties() != null) {
|
|
+ Foods.ALL_PROPERTIES.put(key.location().getPath(), item.getFoodProperties());
|
|
+ Foods.DEFAULT_PROPERTIES.put(key.location().getPath(), item.getFoodProperties().copy());
|
|
+ }
|
|
+ // Purpur end
|
|
+
|
|
return Registry.register(BuiltInRegistries.ITEM, key, item);
|
|
}
|
|
}
|
|
diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
|
index bb5da073f0839a624ae4c86dfed20e56233ff5a3..51080c334f78796c75c906bdd79f5e2df94995a4 100644
|
|
--- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
|
+++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
|
@@ -457,4 +457,75 @@ public class PurpurConfig {
|
|
String setPattern = getString("settings.username-valid-characters", defaultPattern);
|
|
usernameValidCharactersPattern = java.util.regex.Pattern.compile(setPattern == null || setPattern.isBlank() ? defaultPattern : setPattern);
|
|
}
|
|
+
|
|
+ private static void foodSettings() {
|
|
+ ConfigurationSection properties = config.getConfigurationSection("settings.food-properties");
|
|
+ if (properties == null) {
|
|
+ config.addDefault("settings.food-properties", new HashMap<>());
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ Map<MobEffect, Map<String, Object>> effectDefaults = new HashMap<>();
|
|
+ Map<String, Object> EFFECT_DEFAULT = Map.of(
|
|
+ "chance", 0.0F,
|
|
+ "duration", 0,
|
|
+ "amplifier", 0,
|
|
+ "ambient", false,
|
|
+ "visible", true,
|
|
+ "show-icon", true
|
|
+ );
|
|
+
|
|
+ properties.getKeys(false).forEach(foodKey -> {
|
|
+ FoodProperties food = Foods.ALL_PROPERTIES.get(foodKey);
|
|
+ if (food == null) {
|
|
+ PurpurConfig.log(Level.SEVERE, "Invalid food property: " + foodKey);
|
|
+ return;
|
|
+ }
|
|
+ FoodProperties foodDefaults = Foods.DEFAULT_PROPERTIES.get(foodKey);
|
|
+ food.setNutrition(properties.getInt(foodKey + ".nutrition", foodDefaults.getNutrition()));
|
|
+ food.setSaturationModifier((float) properties.getDouble(foodKey + ".saturation-modifier", foodDefaults.getSaturationModifier()));
|
|
+ food.setIsMeat(properties.getBoolean(foodKey + ".is-meat", foodDefaults.isMeat()));
|
|
+ food.setCanAlwaysEat(properties.getBoolean(foodKey + ".can-always-eat", foodDefaults.canAlwaysEat()));
|
|
+ food.setFastFood(properties.getBoolean(foodKey + ".fast-food", foodDefaults.isFastFood()));
|
|
+ ConfigurationSection effects = properties.getConfigurationSection(foodKey + ".effects");
|
|
+ if (effects != null) {
|
|
+ effectDefaults.clear();
|
|
+ foodDefaults.getEffects().forEach(pair -> {
|
|
+ MobEffectInstance effect = pair.getFirst();
|
|
+ effectDefaults.put(effect.getEffect(), Map.of(
|
|
+ "chance", pair.getSecond(),
|
|
+ "duration", effect.getDuration(),
|
|
+ "amplifier", effect.getAmplifier(),
|
|
+ "ambient", effect.isAmbient(),
|
|
+ "visible", effect.isVisible(),
|
|
+ "show-icon", effect.showIcon()
|
|
+ ));
|
|
+ });
|
|
+ effects.getKeys(false).forEach(effectKey -> {
|
|
+ MobEffect effect = BuiltInRegistries.MOB_EFFECT.get(new ResourceLocation(effectKey));
|
|
+ if (effect == null) {
|
|
+ PurpurConfig.log(Level.SEVERE, "Invalid food property effect for " + foodKey + ": " + effectKey);
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ Map<String, Object> effectDefault = effectDefaults.get(effect);
|
|
+ if (effectDefault == null) {
|
|
+ effectDefault = EFFECT_DEFAULT;
|
|
+ }
|
|
+
|
|
+ food.getEffects().removeIf(pair -> pair.getFirst().getEffect() == effect);
|
|
+ float chance = (float) effects.getDouble(effectKey + ".chance", ((Float) effectDefault.get("chance")).doubleValue());
|
|
+ int duration = effects.getInt(effectKey + ".duration", (int) effectDefault.get("duration"));
|
|
+ if (chance <= 0.0F || duration < 0) {
|
|
+ return;
|
|
+ }
|
|
+ int amplifier = effects.getInt(effectKey + ".amplifier", (int) effectDefault.get("amplifier"));
|
|
+ boolean ambient = effects.getBoolean(effectKey + ".ambient", (boolean) effectDefault.get("ambient"));
|
|
+ boolean visible = effects.getBoolean(effectKey + ".visible", (boolean) effectDefault.get("visible"));
|
|
+ boolean showIcon = effects.getBoolean(effectKey + ".show-icon", (boolean) effectDefault.get("show-icon"));
|
|
+ food.getEffects().add(Pair.of(new MobEffectInstance(effect, duration, amplifier, ambient, visible, showIcon), chance));
|
|
+ });
|
|
+ }
|
|
+ });
|
|
+ }
|
|
}
|