Eating glow berries adds glow effect

This commit is contained in:
William Blake Galbreath
2025-01-11 22:58:05 -08:00
committed by granny
parent e09623ae80
commit c62c4b3ec4
4 changed files with 37 additions and 71 deletions

View File

@@ -9,3 +9,12 @@
public static final Item CREAKING_HEART = registerBlock(Blocks.CREAKING_HEART);
public static final Item CHEST = registerBlock(Blocks.CHEST, properties -> properties.component(DataComponents.CONTAINER, ItemContainerContents.EMPTY));
public static final Item CRAFTING_TABLE = registerBlock(Blocks.CRAFTING_TABLE);
@@ -2010,7 +_,7 @@
"sweet_berries", createBlockItemWithCustomItemName(Blocks.SWEET_BERRY_BUSH), new Item.Properties().food(Foods.SWEET_BERRIES)
);
public static final Item GLOW_BERRIES = registerItem(
- "glow_berries", createBlockItemWithCustomItemName(Blocks.CAVE_VINES), new Item.Properties().food(Foods.GLOW_BERRIES)
+ "glow_berries", settings -> new org.purpurmc.purpur.item.GlowBerryItem(Blocks.CAVE_VINES, settings.useItemDescriptionPrefix()), new Item.Properties().food(Foods.GLOW_BERRIES) // Purpur - Eating glow berries adds glow effect
);
public static final Item CAMPFIRE = registerBlock(
Blocks.CAMPFIRE, properties -> properties.component(DataComponents.CONTAINER, ItemContainerContents.EMPTY)

View File

@@ -206,6 +206,7 @@ public class PurpurWorldConfig {
public int enderPearlCooldown = 20;
public int enderPearlCooldownCreative = 20;
public float enderPearlEndermiteChance = 0.05F;
public int glowBerriesEatGlowDuration = 0;
private void itemSettings() {
itemImmuneToCactus.clear();
getList("gameplay-mechanics.item.immune.cactus", new ArrayList<>()).forEach(key -> {
@@ -252,6 +253,7 @@ public class PurpurWorldConfig {
enderPearlCooldown = getInt("gameplay-mechanics.item.ender-pearl.cooldown", enderPearlCooldown);
enderPearlCooldownCreative = getInt("gameplay-mechanics.item.ender-pearl.creative-cooldown", enderPearlCooldownCreative);
enderPearlEndermiteChance = (float) getDouble("gameplay-mechanics.item.ender-pearl.endermite-spawn-chance", enderPearlEndermiteChance);
glowBerriesEatGlowDuration = getInt("gameplay-mechanics.item.glow_berries.eat-glow-duration", glowBerriesEatGlowDuration);
}
public double minecartMaxSpeed = 0.4D;

View File

@@ -0,0 +1,26 @@
package org.purpurmc.purpur.item;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import org.bukkit.event.entity.EntityPotionEffectEvent;
public class GlowBerryItem extends BlockItem {
public GlowBerryItem(Block block, Properties settings) {
super(block, settings);
}
@Override
public ItemStack finishUsingItem(ItemStack stack, Level world, LivingEntity user) {
ItemStack result = super.finishUsingItem(stack, world, user);
if (world.purpurConfig.glowBerriesEatGlowDuration > 0 && user instanceof ServerPlayer player) {
player.addEffect(new MobEffectInstance(MobEffects.GLOWING, world.purpurConfig.glowBerriesEatGlowDuration), EntityPotionEffectEvent.Cause.FOOD);
}
return result;
}
}