diff --git a/src/main/java/com/wenxin2/marioverse/Marioverse.java b/src/main/java/com/wenxin2/marioverse/Marioverse.java index 87c964ef..3a7d5f71 100644 --- a/src/main/java/com/wenxin2/marioverse/Marioverse.java +++ b/src/main/java/com/wenxin2/marioverse/Marioverse.java @@ -4,6 +4,7 @@ import com.mojang.serialization.MapCodec; import com.wenxin2.marioverse.event_handlers.MarioverseEventHandlers; import com.wenxin2.marioverse.event_handlers.RegistryEventHandlers; +import com.wenxin2.marioverse.init.AttributesRegistry; import com.wenxin2.marioverse.init.BlockEntityRegistry; import com.wenxin2.marioverse.init.BlockRegistry; import com.wenxin2.marioverse.init.ConfigRegistry; @@ -18,6 +19,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvent; import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.ai.attributes.Attribute; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.level.block.entity.BlockEntityType; import net.neoforged.api.distmarker.Dist; @@ -45,6 +47,7 @@ public class Marioverse { public static final DeferredRegister> MENUS = DeferredRegister.create(Registries.MENU, Marioverse.MOD_ID); public static final DeferredRegister> PARTICLES = DeferredRegister.create(Registries.PARTICLE_TYPE, Marioverse.MOD_ID); public static final DeferredRegister SOUNDS = DeferredRegister.create(Registries.SOUND_EVENT, Marioverse.MOD_ID); + public static final DeferredRegister ATTRIBUTES = DeferredRegister.create(Registries.ATTRIBUTE, Marioverse.MOD_ID); public Marioverse(IEventBus bus, Dist dist, ModContainer container) { BLOCKS.register(bus); @@ -65,6 +68,7 @@ public Marioverse(IEventBus bus, Dist dist, ModContainer container) { MenuRegistry.init(); ParticleRegistry.init(); SoundRegistry.init(); + AttributesRegistry.init(); ConfigRegistry.register(container); if (dist.isClient()) { diff --git a/src/main/java/com/wenxin2/marioverse/event_handlers/MarioverseEventHandlers.java b/src/main/java/com/wenxin2/marioverse/event_handlers/MarioverseEventHandlers.java index 1964bb67..99eb5686 100644 --- a/src/main/java/com/wenxin2/marioverse/event_handlers/MarioverseEventHandlers.java +++ b/src/main/java/com/wenxin2/marioverse/event_handlers/MarioverseEventHandlers.java @@ -6,6 +6,7 @@ import com.wenxin2.marioverse.entities.FireGoombaEntity; import com.wenxin2.marioverse.entities.GoombaEntity; import com.wenxin2.marioverse.entities.ai.goals.ShootBouncingFireballGoal; +import com.wenxin2.marioverse.init.AttributesRegistry; import com.wenxin2.marioverse.init.ConfigRegistry; import com.wenxin2.marioverse.init.KeybindRegistry; import com.wenxin2.marioverse.init.SoundRegistry; @@ -28,6 +29,7 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeInstance; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; @@ -127,6 +129,13 @@ public static void onEntityDamaged(LivingIncomingDamageEvent event) { || ScaleTypes.WIDTH.getScaleData(event.getEntity()).getTargetScale() > 0.75F)*/) { // ScaleTypes.HEIGHT.getScaleData(event.getEntity()).setTargetScale(0.5F); // ScaleTypes.WIDTH.getScaleData(event.getEntity()).setTargetScale(0.75F); + + AttributeInstance scaleAttribute = player.getAttribute(Attributes.SCALE); + if (scaleAttribute != null) { + if (player.getAttribute(Attributes.SCALE) != null + && !player.getAttribute(Attributes.SCALE).hasModifier(AttributesRegistry.SCALE_MODIFIER.id())) + scaleAttribute.addPermanentModifier(AttributesRegistry.SCALE_MODIFIER); + } world.playSound(null, player.blockPosition(), SoundRegistry.DAMAGE_TAKEN.get(), SoundSource.PLAYERS, 1.0F, 1.0F); } @@ -188,6 +197,13 @@ public static void onEntityDamaged(LivingIncomingDamageEvent event) { || ScaleTypes.WIDTH.getScaleData(event.getEntity()).getTargetScale() > 0.75F)*/) { // ScaleTypes.HEIGHT.getScaleData(event.getEntity()).setTargetScale(0.5F); // ScaleTypes.WIDTH.getScaleData(event.getEntity()).setTargetScale(0.75F); + + AttributeInstance scaleAttribute = entity.getAttribute(Attributes.SCALE); + if (scaleAttribute != null) { + if (entity.getAttribute(Attributes.SCALE) != null + && !entity.getAttribute(Attributes.SCALE).hasModifier(AttributesRegistry.SCALE_MODIFIER.id())) + scaleAttribute.addPermanentModifier(AttributesRegistry.SCALE_MODIFIER); + } world.playSound(null, entity.blockPosition(), SoundRegistry.DAMAGE_TAKEN.get(), SoundSource.HOSTILE, 1.0F, 1.0F); } @@ -253,12 +269,24 @@ public static void onEntityHeal(LivingHealEvent event) { || ScaleTypes.WIDTH.getScaleData(entity).getTargetScale() < 1.0F)*/) { // ScaleTypes.HEIGHT.getScaleData(entity).setTargetScale(1.0F); // ScaleTypes.WIDTH.getScaleData(entity).setTargetScale(1.0F); + AttributeInstance scaleAttribute = player.getAttribute(Attributes.SCALE); + if (scaleAttribute != null) { + if (player.getAttribute(Attributes.SCALE) != null + && !player.getAttribute(Attributes.SCALE).hasModifier(AttributesRegistry.SCALE_MODIFIER.id())) + scaleAttribute.removeModifier(AttributesRegistry.SCALE_MODIFIER); + } } } else if (tag.getBoolean("marioverse:has_mushroom") && ConfigRegistry.DAMAGE_SHRINKS_PLAYERS.get() /*&& (ScaleTypes.HEIGHT.getScaleData(entity).getTargetScale() < 1.0F || ScaleTypes.WIDTH.getScaleData(entity).getTargetScale() < 1.0F)*/) { // ScaleTypes.HEIGHT.getScaleData(entity).setTargetScale(1.0F); // ScaleTypes.WIDTH.getScaleData(entity).setTargetScale(1.0F); + AttributeInstance scaleAttribute = player.getAttribute(Attributes.SCALE); + if (scaleAttribute != null) { + if (player.getAttribute(Attributes.SCALE) != null + && !player.getAttribute(Attributes.SCALE).hasModifier(AttributesRegistry.SCALE_MODIFIER.id())) + scaleAttribute.removeModifier(AttributesRegistry.SCALE_MODIFIER); + } } } else if (entity instanceof LivingEntity livingEntity) { if (livingEntity.getHealth() > livingEntity.getMaxHealth() * ConfigRegistry.HEALTH_SHRINK_MOBS.get()) { @@ -268,12 +296,24 @@ public static void onEntityHeal(LivingHealEvent event) { || ScaleTypes.WIDTH.getScaleData(entity).getTargetScale() < 1.0F)*/) { // ScaleTypes.HEIGHT.getScaleData(entity).setTargetScale(1.0F); // ScaleTypes.WIDTH.getScaleData(entity).setTargetScale(1.0F); + AttributeInstance scaleAttribute = livingEntity.getAttribute(Attributes.SCALE); + if (scaleAttribute != null) { + if (livingEntity.getAttribute(Attributes.SCALE) != null + && !livingEntity.getAttribute(Attributes.SCALE).hasModifier(AttributesRegistry.SCALE_MODIFIER.id())) + scaleAttribute.removeModifier(AttributesRegistry.SCALE_MODIFIER); + } } } else if (tag.getBoolean("marioverse:has_mushroom") && ConfigRegistry.DAMAGE_SHRINKS_PLAYERS.get() /*&& (ScaleTypes.HEIGHT.getScaleData(entity).getTargetScale() < 1.0F || ScaleTypes.WIDTH.getScaleData(entity).getTargetScale() < 1.0F)*/) { // ScaleTypes.HEIGHT.getScaleData(entity).setTargetScale(1.0F); // ScaleTypes.WIDTH.getScaleData(entity).setTargetScale(1.0F); + AttributeInstance scaleAttribute = livingEntity.getAttribute(Attributes.SCALE); + if (scaleAttribute != null) { + if (livingEntity.getAttribute(Attributes.SCALE) != null + && !livingEntity.getAttribute(Attributes.SCALE).hasModifier(AttributesRegistry.SCALE_MODIFIER.id())) + scaleAttribute.removeModifier(AttributesRegistry.SCALE_MODIFIER); + } } } } diff --git a/src/main/java/com/wenxin2/marioverse/init/AttributesRegistry.java b/src/main/java/com/wenxin2/marioverse/init/AttributesRegistry.java new file mode 100644 index 00000000..ed3157f1 --- /dev/null +++ b/src/main/java/com/wenxin2/marioverse/init/AttributesRegistry.java @@ -0,0 +1,16 @@ +package com.wenxin2.marioverse.init; + +import com.wenxin2.marioverse.Marioverse; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.ai.attributes.Attribute; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; +import net.minecraft.world.entity.ai.attributes.RangedAttribute; +import net.neoforged.neoforge.registries.DeferredHolder; + +public class AttributesRegistry { + public static AttributeModifier SCALE_MODIFIER = new AttributeModifier( + ResourceLocation.fromNamespaceAndPath(Marioverse.MOD_ID, "scale_modifier"), + -0.5, AttributeModifier.Operation.ADD_MULTIPLIED_BASE); + + public static void init() {} +}