This repository has been archived by the owner on Jan 26, 2025. It is now read-only.
generated from FabricMC/fabric-example-mod
-
-
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
1 parent
aaa3262
commit 2b2cb4f
Showing
10 changed files
with
87 additions
and
101 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
49 changes: 24 additions & 25 deletions
49
common/src/main/java/top/ctnstudios/stonecraft/ItemCleanNegative.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 |
---|---|---|
@@ -1,46 +1,45 @@ | ||
package top.ctnstudios.stonecraft; | ||
|
||
import com.google.common.collect.Sets; | ||
import net.minecraft.world.effect.MobEffect; | ||
import net.minecraft.world.effect.MobEffectCategory; | ||
import net.minecraft.world.effect.MobEffectInstance; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.food.FoodProperties; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
import top.ctnstudios.stonecraft.MainCommon; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.effect.StatusEffect; | ||
import net.minecraft.entity.effect.StatusEffectCategory; | ||
import net.minecraft.entity.effect.StatusEffectInstance; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.FoodComponent; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.world.World; | ||
|
||
import java.util.Set; | ||
|
||
public class ItemCleanNegative extends Item { | ||
private final Set<MobEffectInstance> effects; | ||
private final Set<StatusEffectInstance> effects; | ||
|
||
public ItemCleanNegative(int hunger, float saturation, MobEffectInstance ... effects) { | ||
super(new Item.Properties().arch$tab(MainCommon.STONE_CRAFT_TABS).food( | ||
new FoodProperties.Builder() | ||
.nutrition(hunger) | ||
.saturationMod(saturation) | ||
.alwaysEat() | ||
public ItemCleanNegative(int hunger, float saturation, StatusEffectInstance ... effects) { | ||
super(new Item.Settings().arch$tab(MainCommon.STONE_CRAFT_TABS).food( | ||
new FoodComponent.Builder() | ||
.hunger(hunger) | ||
.saturationModifier(saturation) | ||
.alwaysEdible() | ||
.build() | ||
)); | ||
|
||
this.effects = Sets.newHashSet(effects); | ||
} | ||
@Override | ||
public ItemStack finishUsingItem(ItemStack item, Level world, LivingEntity user) { | ||
if (user instanceof Player player) { | ||
player.getActiveEffects().forEach((effect) -> checkAndCleanNegativeEffectInstance(player, effect.getEffect())); | ||
effects.forEach((effect) -> player.addEffect(effect)); | ||
public ItemStack finishUsing(ItemStack item, World world, LivingEntity user) { | ||
if (user instanceof PlayerEntity player) { | ||
player.getStatusEffects().forEach((effect) -> checkAndCleanNegativeEffectInstance(player, effect.getEffectType())); | ||
effects.forEach((effect) -> player.addStatusEffect(effect)); | ||
} | ||
|
||
return super.finishUsingItem(item, world, user); | ||
return super.finishUsing(item, world, user); | ||
} | ||
|
||
private void checkAndCleanNegativeEffectInstance(Player player, MobEffect effect) { | ||
if (effect.getCategory() == MobEffectCategory.HARMFUL) { | ||
player.removeEffect(effect); | ||
private void checkAndCleanNegativeEffectInstance(PlayerEntity player, StatusEffect effect) { | ||
if (effect.getCategory() == StatusEffectCategory.HARMFUL) { | ||
player.removeStatusEffect(effect); | ||
} | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -1,18 +1,16 @@ | ||
org.gradle.jvmargs=-Xmx2048M | ||
|
||
archives_base_name=stonecraft | ||
minecraft_version=1.20.1 | ||
maven_group=top.ctnstudios.stonecraft | ||
enabled_platforms=forge,fabric,quilt | ||
|
||
archives_base_name=stonecraft | ||
mod_version=0.3.0 | ||
maven_group=top.ctnstudios.stonecraft | ||
|
||
architectury_version=9.1.12 | ||
|
||
fabric_loader_version=0.15.1 | ||
fabric_api_version=0.91.0+1.20.1 | ||
|
||
forge_version=1.20.1-47.2.17 | ||
|
||
quilt_loader_version=0.22.1-beta.4 | ||
yarn_version=1.20.1+build.10 | ||
|
||
fabric_api_version=0.91.0+1.20.1 | ||
quilt_fabric_api_version=7.4.0+0.90.0-1.20.1 | ||
architectury_version=9.1.12 |
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