Added Full Set Bonus Effect
This commit is contained in:
+1
-1
@@ -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) {
|
||||||
@@ -29,36 +30,45 @@ public class ModArmorItem extends ArmorItem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void inventoryTick(ItemStack stack, Level level, Entity entity, int slotId, boolean isSelected) {
|
public void inventoryTick(ItemStack stack, Level level, Entity entity, int slotId, boolean isSelected) {
|
||||||
if(entity instanceof Player player && !level.isClientSide() && hasFullSuitOfArmorOn(player)) {
|
if (entity instanceof Player player && !level.isClientSide() && hasFullSuitOfArmorOn(player)) {
|
||||||
evaluateArmorEffects(player);
|
evaluateArmorEffects(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void evaluateArmorEffects(Player player) {
|
private void evaluateArmorEffects(Player player) {
|
||||||
for(Map.Entry<Holder<ArmorMaterial>, List<MobEffectInstance>> entry : MATERIAL_TO_EFFECT_MAP.entrySet()) {
|
for (Map.Entry<Holder<ArmorMaterial>, List<MobEffectInstance>> entry : MATERIAL_TO_EFFECT_MAP.entrySet()) {
|
||||||
Holder<ArmorMaterial> mapArmorMaterial = entry.getKey();
|
Holder<ArmorMaterial> mapArmorMaterial = entry.getKey();
|
||||||
List<MobEffectInstance> mapEffect = entry.getValue();
|
List<MobEffectInstance> mapEffect = entry.getValue();
|
||||||
|
|
||||||
if(hasPlayerCorrectArmorOn(mapArmorMaterial, player)) {
|
if (hasPlayerCorrectArmorOn(mapArmorMaterial, player)) {
|
||||||
addEffectToPlayer(player, mapEffect);
|
addEffectToPlayer(player, mapEffect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasPlayerCorrectArmorOn(Holder<ArmorMaterial> mapArmorMaterial, Player player) {
|
private boolean hasPlayerCorrectArmorOn(Holder<ArmorMaterial> mapArmorMaterial, Player player) {
|
||||||
for(ItemStack armorStack : player.getArmorSlots()) {
|
for (ItemStack armorStack : player.getArmorSlots()) {
|
||||||
if(!(armorStack.getItem() instanceof ArmorItem)) {
|
if (!(armorStack.getItem() instanceof ArmorItem)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user