9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-30 20:29:14 +00:00
Files
SakuraMC/patches/server/0067-Old-enchanted-golden-apples.patch
2024-11-21 22:10:57 +00:00

89 lines
4.0 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <kfian294ma4@gmail.com>
Date: Fri, 23 Feb 2024 14:40:32 +0000
Subject: [PATCH] Old enchanted golden apples
diff --git a/src/main/java/me/samsuik/sakura/player/combat/CustomGoldenApple.java b/src/main/java/me/samsuik/sakura/player/combat/CustomGoldenApple.java
new file mode 100644
index 0000000000000000000000000000000000000000..18cb28a9bdfcb9a421bc001f057b4be54c1550be
--- /dev/null
+++ b/src/main/java/me/samsuik/sakura/player/combat/CustomGoldenApple.java
@@ -0,0 +1,64 @@
+package me.samsuik.sakura.player.combat;
+
+import net.minecraft.core.component.DataComponents;
+import net.minecraft.world.InteractionHand;
+import net.minecraft.world.InteractionResult;
+import net.minecraft.world.effect.MobEffectInstance;
+import net.minecraft.world.effect.MobEffects;
+import net.minecraft.world.entity.LivingEntity;
+import net.minecraft.world.entity.player.Player;
+import net.minecraft.world.item.Item;
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.item.component.Consumable;
+import net.minecraft.world.item.component.Consumables;
+import net.minecraft.world.item.consume_effects.ApplyStatusEffectsConsumeEffect;
+import net.minecraft.world.level.Level;
+import org.jspecify.annotations.NullMarked;
+
+import java.util.List;
+import java.util.Optional;
+
+@NullMarked
+@SuppressWarnings("OptionalAssignedToNull")
+public final class CustomGoldenApple extends Item {
+ private static final Consumable LEGACY_ENCHANTED_GOLDEN_APPLE = Consumables.defaultFood()
+ .onConsume(
+ new ApplyStatusEffectsConsumeEffect(
+ List.of(
+ new MobEffectInstance(MobEffects.REGENERATION, 600, 4),
+ new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 6000, 0),
+ new MobEffectInstance(MobEffects.FIRE_RESISTANCE, 6000, 0),
+ new MobEffectInstance(MobEffects.ABSORPTION, 2400, 0)
+ )
+ )
+ )
+ .build();
+
+ public CustomGoldenApple(Properties settings) {
+ super(settings);
+ }
+
+ @Override
+ public InteractionResult use(Level level, Player player, InteractionHand hand) {
+ ItemStack stack = player.getItemInHand(hand);
+ if (this.itemHasConsumableComponent(stack, level)) {
+ return super.use(level, player, hand);
+ } else {
+ return LEGACY_ENCHANTED_GOLDEN_APPLE.startConsuming(player, stack, hand);
+ }
+ }
+
+ @Override
+ public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity entity) {
+ if (this.itemHasConsumableComponent(stack, level)) {
+ return super.finishUsingItem(stack, level, entity);
+ } else {
+ return LEGACY_ENCHANTED_GOLDEN_APPLE.onConsume(level, entity, stack);
+ }
+ }
+
+ private boolean itemHasConsumableComponent(ItemStack stack, Level level) {
+ Optional<?> consumable = stack.getComponentsPatch().get(DataComponents.CONSUMABLE);
+ return consumable != null || !level.sakuraConfig().players.combat.oldEnchantedGoldenApple;
+ }
+}
diff --git a/src/main/java/net/minecraft/world/item/Items.java b/src/main/java/net/minecraft/world/item/Items.java
index 5a70111cd39af50981cfd440c021340da1de5eab..92a3ae94e936809004c9664c18dae74edf154399 100644
--- a/src/main/java/net/minecraft/world/item/Items.java
+++ b/src/main/java/net/minecraft/world/item/Items.java
@@ -1174,6 +1174,7 @@ public class Items {
public static final Item GOLDEN_APPLE = registerItem("golden_apple", new Item.Properties().food(Foods.GOLDEN_APPLE, Consumables.GOLDEN_APPLE));
public static final Item ENCHANTED_GOLDEN_APPLE = registerItem(
"enchanted_golden_apple",
+ me.samsuik.sakura.player.combat.CustomGoldenApple::new, // Sakura - old enchanted golden apples
new Item.Properties()
.rarity(Rarity.RARE)
.food(Foods.ENCHANTED_GOLDEN_APPLE, Consumables.ENCHANTED_GOLDEN_APPLE)