Merge remote-tracking branch 'origin/main'

This commit is contained in:
IM23a-spirgif
2025-05-28 16:12:18 +02:00
9 changed files with 210 additions and 10 deletions
@@ -1,6 +1,7 @@
package net.krituximon.stalinium.item;
import net.krituximon.stalinium.Stalinium;
import net.krituximon.stalinium.item.custom.*;
import net.krituximon.stalinium.sound.ModSounds;
import net.minecraft.world.item.*;
import net.neoforged.bus.api.IEventBus;
@@ -40,15 +41,15 @@ public class ModItems {
.attributes(HoeItem.createAttributes(ModTiers.STALINIUM, 1.0f, -3.0f))));
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))));
public static final DeferredItem<ArmorItem> STALINIUM_CHESTPLATE = ITEMS.register("stalinium_chestplate",
() -> new ArmorItem(ModArmorMaterials.STALINIUM_ARMOR_MATERIAL, ArmorItem.Type.CHESTPLATE,
() -> new StaliniumChestplateLeggingsItem(ModArmorMaterials.STALINIUM_ARMOR_MATERIAL, ArmorItem.Type.CHESTPLATE,
new Item.Properties().durability(ArmorItem.Type.CHESTPLATE.getDurability(19))));
public static final DeferredItem<ArmorItem> STALINIUM_LEGGINGS = ITEMS.register("stalinium_leggings",
() -> new ArmorItem(ModArmorMaterials.STALINIUM_ARMOR_MATERIAL, ArmorItem.Type.LEGGINGS,
() -> new StaliniumChestplateLeggingsItem(ModArmorMaterials.STALINIUM_ARMOR_MATERIAL, ArmorItem.Type.LEGGINGS,
new Item.Properties().durability(ArmorItem.Type.LEGGINGS.getDurability(19))));
public static final DeferredItem<ArmorItem> STALINIUM_BOOTS = ITEMS.register("stalinium_boots",
@@ -0,0 +1,93 @@
package net.krituximon.stalinium.item.custom;
import com.google.common.collect.ImmutableMap;
import net.krituximon.stalinium.item.ModArmorMaterials;
import net.minecraft.core.Holder;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ArmorMaterial;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import java.util.List;
import java.util.Map;
public class ModArmorItem extends ArmorItem {
private static final Map<Holder<ArmorMaterial>, List<MobEffectInstance>> MATERIAL_TO_EFFECT_MAP =
(new ImmutableMap.Builder<Holder<ArmorMaterial>, List<MobEffectInstance>>())
.put(ModArmorMaterials.STALINIUM_ARMOR_MATERIAL,
List.of(new MobEffectInstance(MobEffects.HEALTH_BOOST, 100, 0, false, false)))
.build();
public ModArmorItem(Holder<ArmorMaterial> material, Type type, Properties properties) {
super(material, type, properties);
}
@Override
public void inventoryTick(ItemStack stack, Level level, Entity entity, int slotId, boolean isSelected) {
if (entity instanceof Player player && !level.isClientSide() && hasFullSuitOfArmorOn(player)) {
evaluateArmorEffects(player);
}
}
private void evaluateArmorEffects(Player player) {
for (Map.Entry<Holder<ArmorMaterial>, List<MobEffectInstance>> entry : MATERIAL_TO_EFFECT_MAP.entrySet()) {
Holder<ArmorMaterial> mapArmorMaterial = entry.getKey();
List<MobEffectInstance> mapEffect = entry.getValue();
if (hasPlayerCorrectArmorOn(mapArmorMaterial, player)) {
addEffectToPlayer(player, mapEffect);
}
}
}
private void addEffectToPlayer(Player player, List<MobEffectInstance> mapEffect) {
AABB box = player.getBoundingBox().inflate(20.0);
int playersInBox = player.level().getEntitiesOfClass(
Player.class,
box,
p -> p instanceof ServerPlayer && player.isAlliedTo(p)
).size();
for (MobEffectInstance effect : mapEffect) {
int newAmplifier = Math.min(4, effect.getAmplifier() + playersInBox);
player.addEffect(new MobEffectInstance(
effect.getEffect(),
effect.getDuration(),
newAmplifier,
effect.isAmbient(),
effect.isVisible()
));
}
}
private boolean hasPlayerCorrectArmorOn(Holder<ArmorMaterial> mapArmorMaterial, Player player) {
for (ItemStack armorStack : player.getArmorSlots()) {
if (!(armorStack.getItem() instanceof ArmorItem)) {
return false;
}
}
ArmorItem boots = ((ArmorItem) player.getInventory().getArmor(0).getItem());
ArmorItem leggings = ((ArmorItem) player.getInventory().getArmor(1).getItem());
ArmorItem chestplate = ((ArmorItem) player.getInventory().getArmor(2).getItem());
ArmorItem helmet = ((ArmorItem) player.getInventory().getArmor(3).getItem());
return boots.getMaterial() == mapArmorMaterial && leggings.getMaterial() == mapArmorMaterial
&& chestplate.getMaterial() == mapArmorMaterial && helmet.getMaterial() == mapArmorMaterial;
}
private boolean hasFullSuitOfArmorOn(Player player) {
ItemStack boots = player.getInventory().getArmor(0);
ItemStack leggings = player.getInventory().getArmor(1);
ItemStack chestplate = player.getInventory().getArmor(2);
ItemStack helmet = player.getInventory().getArmor(3);
return !boots.isEmpty() && !leggings.isEmpty() && !chestplate.isEmpty() && !helmet.isEmpty();
}
}
@@ -1,4 +1,4 @@
package net.krituximon.stalinium.item;
package net.krituximon.stalinium.item.custom;
import net.krituximon.stalinium.util.PlacedLogStorage;
import net.minecraft.client.gui.screens.Screen;
@@ -0,0 +1,107 @@
package net.krituximon.stalinium.item.custom;
import com.google.common.collect.ImmutableMap;
import net.krituximon.stalinium.item.ModArmorMaterials;
import net.minecraft.core.Holder;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ArmorMaterial;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import java.util.List;
import java.util.Map;
public class StaliniumChestplateLeggingsItem extends ArmorItem {
private static final Map<Holder<ArmorMaterial>, List<MobEffectInstance>> MATERIAL_TO_EFFECT_MAP =
(new ImmutableMap.Builder<Holder<ArmorMaterial>, List<MobEffectInstance>>())
.put(ModArmorMaterials.STALINIUM_ARMOR_MATERIAL,
List.of(new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 100, 0, false, false)))
.build();
public StaliniumChestplateLeggingsItem(Holder<ArmorMaterial> material, Type type, Properties properties) {
super(material, type, properties);
}
@Override
public void inventoryTick(ItemStack stack, Level level, Entity entity, int slotId, boolean isSelected) {
if (entity instanceof Player player && !level.isClientSide() && hasChestAndLeggingsOn(player)) {
evaluateArmorEffects(player);
}
}
private void evaluateArmorEffects(Player player) {
for (Map.Entry<Holder<ArmorMaterial>, List<MobEffectInstance>> entry : MATERIAL_TO_EFFECT_MAP.entrySet()) {
Holder<ArmorMaterial> mapArmorMaterial = entry.getKey();
List<MobEffectInstance> mapEffect = entry.getValue();
if (hasPlayerCorrectArmorOn(mapArmorMaterial, player)) {
addEffectToPlayer(player, mapEffect);
}
}
}
private void addEffectToPlayer(Player player, List<MobEffectInstance> mapEffect) {
AABB box = player.getBoundingBox().inflate(5.0);
List<Player> allies = player.level().getEntitiesOfClass(
Player.class,
box,
p -> p instanceof ServerPlayer && player.isAlliedTo(p)
);
for (MobEffectInstance effect : mapEffect) {
player.addEffect(new MobEffectInstance(
effect.getEffect(),
effect.getDuration(),
effect.getAmplifier(),
effect.isAmbient(),
effect.isVisible()));
for (Player ally : allies) {
ally.addEffect(new MobEffectInstance(
effect.getEffect(),
effect.getDuration(),
effect.getAmplifier(),
effect.isAmbient(),
effect.isVisible()
));
}
}
}
private boolean hasPlayerCorrectArmorOn(Holder<ArmorMaterial> mapArmorMaterial, Player player) {
ItemStack leggingsStack = player.getInventory().getArmor(1);
ItemStack chestplateStack = player.getInventory().getArmor(2);
if (leggingsStack.isEmpty() || chestplateStack.isEmpty()) {
return false;
}
ArmorItem leggingsItem = (ArmorItem) leggingsStack.getItem();
ArmorItem chestplateItem = (ArmorItem) chestplateStack.getItem();
return leggingsItem.getMaterial() == mapArmorMaterial
&& chestplateItem.getMaterial() == mapArmorMaterial;
}
private boolean hasChestAndLeggingsOn(Player player) {
ItemStack leggings = player.getInventory().getArmor(1);
ItemStack chestplate = player.getInventory().getArmor(2);
return !leggings.isEmpty() && !chestplate.isEmpty();
}
@Override
public boolean isDamageable(ItemStack stack) {
return false;
}
@Override
public boolean isDamaged(ItemStack stack) {
return false;
}
}
@@ -1,4 +1,4 @@
package net.krituximon.stalinium.item;
package net.krituximon.stalinium.item.custom;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.core.BlockPos;
@@ -7,7 +7,6 @@ import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.*;
import net.minecraft.world.item.context.UseOnContext;
@@ -1,4 +1,4 @@
package net.krituximon.stalinium.item;
package net.krituximon.stalinium.item.custom;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.core.BlockPos;
@@ -1,4 +1,4 @@
package net.krituximon.stalinium.item;
package net.krituximon.stalinium.item.custom;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.core.BlockPos;
@@ -1,4 +1,4 @@
package net.krituximon.stalinium.item;
package net.krituximon.stalinium.item.custom;
import net.krituximon.stalinium.Stalinium;
import net.minecraft.client.gui.screens.Screen;