Skip to content

Commit

Permalink
Scaling for damage to replace pehkui
Browse files Browse the repository at this point in the history
  • Loading branch information
WenXin20 committed Dec 28, 2024
1 parent 1e54bb1 commit 40c9306
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/wenxin2/marioverse/Marioverse.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -45,6 +47,7 @@ public class Marioverse {
public static final DeferredRegister<MenuType<?>> MENUS = DeferredRegister.create(Registries.MENU, Marioverse.MOD_ID);
public static final DeferredRegister<ParticleType<?>> PARTICLES = DeferredRegister.create(Registries.PARTICLE_TYPE, Marioverse.MOD_ID);
public static final DeferredRegister<SoundEvent> SOUNDS = DeferredRegister.create(Registries.SOUND_EVENT, Marioverse.MOD_ID);
public static final DeferredRegister<Attribute> ATTRIBUTES = DeferredRegister.create(Registries.ATTRIBUTE, Marioverse.MOD_ID);

public Marioverse(IEventBus bus, Dist dist, ModContainer container) {
BLOCKS.register(bus);
Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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()) {
Expand All @@ -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);
}
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/wenxin2/marioverse/init/AttributesRegistry.java
Original file line number Diff line number Diff line change
@@ -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() {}
}

0 comments on commit 40c9306

Please sign in to comment.