generated from NeoForgeMDKs/MDK-1.21-NeoGradle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
MCZME
committed
Aug 31, 2024
1 parent
d5481df
commit 9b18964
Showing
9 changed files
with
123 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/mczme/lingshi/common/effect/GratificationEffect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package mczme.lingshi.common.effect; | ||
|
||
import mczme.lingshi.common.registry.ModEffects; | ||
import net.minecraft.core.component.DataComponents; | ||
import net.minecraft.world.effect.MobEffect; | ||
import net.minecraft.world.effect.MobEffectCategory; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.food.FoodData; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.neoforged.bus.api.SubscribeEvent; | ||
import net.neoforged.neoforge.event.entity.living.LivingEntityUseItemEvent; | ||
|
||
public class GratificationEffect extends MobEffect { | ||
public GratificationEffect(MobEffectCategory category, int color) { | ||
super(category, color); | ||
} | ||
|
||
@Override | ||
public boolean applyEffectTick(LivingEntity pLivingEntity, int pAmplifier) { | ||
if(!pLivingEntity.level().isClientSide() && pLivingEntity instanceof Player player) { | ||
FoodData foodData = player.getFoodData(); | ||
if(foodData.getFoodLevel() < 18.0F) { | ||
float Exhaustion = Math.min(player.getFoodData().getExhaustionLevel(), 4.0F); | ||
if (player.getFoodData().getExhaustionLevel() > 0.0F) { | ||
player.causeFoodExhaustion(-Exhaustion); | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean shouldApplyEffectTickThisTick(int pDuration, int pAmplifier) { | ||
return true; | ||
} | ||
|
||
public static class Event{ | ||
@SubscribeEvent | ||
public void onEvent(LivingEntityUseItemEvent.Finish event) { | ||
if(event.getEntity() instanceof Player player && !event.getEntity().level().isClientSide()){ | ||
if(player.hasEffect(ModEffects.GRATIFICATION_EFFECT)){ | ||
ItemStack itemStack = event.getItem(); | ||
if(itemStack.get(DataComponents.FOOD) != null) { | ||
player.getFoodData().eat(0,itemStack.get(DataComponents.FOOD).saturation()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/mczme/lingshi/common/event/IndependentEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package mczme.lingshi.common.event; | ||
|
||
import mczme.lingshi.common.effect.GratificationEffect; | ||
import net.neoforged.neoforge.common.NeoForge; | ||
|
||
public class IndependentEvent { | ||
public static void register(){ | ||
NeoForge.EVENT_BUS.register(new GratificationEffect.Event()); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/mczme/lingshi/common/registry/ModEffects.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package mczme.lingshi.common.registry; | ||
|
||
import mczme.lingshi.common.effect.GratificationEffect; | ||
import mczme.lingshi.lingshi; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.world.effect.MobEffect; | ||
import net.minecraft.world.effect.MobEffectCategory; | ||
import net.neoforged.bus.api.IEventBus; | ||
import net.neoforged.neoforge.registries.DeferredHolder; | ||
import net.neoforged.neoforge.registries.DeferredRegister; | ||
|
||
public class ModEffects { | ||
public static final DeferredRegister<MobEffect> MOD_EFFECTS = DeferredRegister.create(Registries.MOB_EFFECT, lingshi.MODID); | ||
|
||
public static final DeferredHolder<MobEffect,GratificationEffect> GRATIFICATION_EFFECT = MOD_EFFECTS.register("gratification_effect", () -> new GratificationEffect(MobEffectCategory.BENEFICIAL, 0xffffff)); | ||
|
||
public static void register(IEventBus eventBus){ | ||
MOD_EFFECTS.register(eventBus); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-2 Bytes
(100%)
src/main/resources/assets/lingshi/textures/item/cabbage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.