Added Full Set Bonus Effect

This commit is contained in:
IM23a-cernik
2025-05-28 13:46:05 +02:00
parent 89d4f6c8f5
commit 1656539669
3 changed files with 25 additions and 15 deletions
+1 -1
View File
@@ -34,7 +34,7 @@ mod_name=Stalinium
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=MIT mod_license=MIT
# The mod version. See https://semver.org/ # The mod version. See https://semver.org/
mod_version=0.0.15 mod_version=0.0.17
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources. # This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html # See https://maven.apache.org/guides/mini/guide-naming-conventions.html
@@ -41,7 +41,7 @@ public class ModItems {
.attributes(HoeItem.createAttributes(ModTiers.STALINIUM, 1.0f, -3.0f)))); .attributes(HoeItem.createAttributes(ModTiers.STALINIUM, 1.0f, -3.0f))));
public static final DeferredItem<ArmorItem> STALINIUM_HELMET = ITEMS.register("stalinium_helmet", public static final DeferredItem<ArmorItem> STALINIUM_HELMET = ITEMS.register("stalinium_helmet",
() -> new ArmorItem(ModArmorMaterials.STALINIUM_ARMOR_MATERIAL, ArmorItem.Type.HELMET, () -> new ModArmorItem(ModArmorMaterials.STALINIUM_ARMOR_MATERIAL, ArmorItem.Type.HELMET,
new Item.Properties().durability(ArmorItem.Type.HELMET.getDurability(19)))); new Item.Properties().durability(ArmorItem.Type.HELMET.getDurability(19))));
public static final DeferredItem<ArmorItem> STALINIUM_CHESTPLATE = ITEMS.register("stalinium_chestplate", public static final DeferredItem<ArmorItem> STALINIUM_CHESTPLATE = ITEMS.register("stalinium_chestplate",
@@ -3,6 +3,7 @@ package net.krituximon.stalinium.item.custom;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import net.krituximon.stalinium.item.ModArmorMaterials; import net.krituximon.stalinium.item.ModArmorMaterials;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects; import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
@@ -11,6 +12,7 @@ import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ArmorMaterial; import net.minecraft.world.item.ArmorMaterial;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -19,8 +21,7 @@ public class ModArmorItem extends ArmorItem {
private static final Map<Holder<ArmorMaterial>, List<MobEffectInstance>> MATERIAL_TO_EFFECT_MAP = private static final Map<Holder<ArmorMaterial>, List<MobEffectInstance>> MATERIAL_TO_EFFECT_MAP =
(new ImmutableMap.Builder<Holder<ArmorMaterial>, List<MobEffectInstance>>()) (new ImmutableMap.Builder<Holder<ArmorMaterial>, List<MobEffectInstance>>())
.put(ModArmorMaterials.STALINIUM_ARMOR_MATERIAL, .put(ModArmorMaterials.STALINIUM_ARMOR_MATERIAL,
List.of(new MobEffectInstance(MobEffects.JUMP, 200, 1, false, false), List.of(new MobEffectInstance(MobEffects.HEALTH_BOOST, 100, 0, false, false)))
new MobEffectInstance(MobEffects.GLOWING, 200, 1, false, false)))
.build(); .build();
public ModArmorItem(Holder<ArmorMaterial> material, Type type, Properties properties) { public ModArmorItem(Holder<ArmorMaterial> material, Type type, Properties properties) {
@@ -46,13 +47,22 @@ public class ModArmorItem extends ArmorItem {
} }
private void addEffectToPlayer(Player player, List<MobEffectInstance> mapEffect) { private void addEffectToPlayer(Player player, List<MobEffectInstance> mapEffect) {
boolean hasPlayerEffect = mapEffect.stream().allMatch(effect -> player.hasEffect(effect.getEffect())); AABB box = player.getBoundingBox().inflate(20.0);
int playersInBox = player.level().getEntitiesOfClass(
Player.class,
box,
p -> p instanceof ServerPlayer && player.isAlliedTo(p)
).size();
if(!hasPlayerEffect) {
for (MobEffectInstance effect : mapEffect) { for (MobEffectInstance effect : mapEffect) {
player.addEffect(new MobEffectInstance(effect.getEffect(), int newAmplifier = Math.min(4, effect.getAmplifier() + playersInBox);
effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.isVisible())); player.addEffect(new MobEffectInstance(
} effect.getEffect(),
effect.getDuration(),
newAmplifier,
effect.isAmbient(),
effect.isVisible()
));
} }
} }