diff --git a/src/main/java/com/wenxin2/marioverse/blocks/QuestionBlock.java b/src/main/java/com/wenxin2/marioverse/blocks/QuestionBlock.java index 629533c2..a777032b 100644 --- a/src/main/java/com/wenxin2/marioverse/blocks/QuestionBlock.java +++ b/src/main/java/com/wenxin2/marioverse/blocks/QuestionBlock.java @@ -225,7 +225,7 @@ public void spawnEntity(Level world, BlockPos pos, ItemStack stack) { if (armorStand != null) { if (world.getBlockState(pos.above()).isAir()) armorStand.setPos(pos.getX() + 0.5D, pos.getY() + 1.0D, pos.getZ() + 0.5D); - else armorStand.setPos(pos.getX() + 0.5D, pos.below((int) Math.max(1, armorStand.getType().getHeight())).getY(), pos.getZ() + 0.5D); + else armorStand.setPos(pos.getX() + 0.5D, pos.below((int) Math.max(2, armorStand.getType().getHeight())).getY(), pos.getZ() + 0.5D); world.addFreshEntity(armorStand); stack.copyWithCount(1); } diff --git a/src/main/java/com/wenxin2/marioverse/entities/BaseMushroomEntity.java b/src/main/java/com/wenxin2/marioverse/entities/BaseMushroomEntity.java index cccff911..777b3154 100644 --- a/src/main/java/com/wenxin2/marioverse/entities/BaseMushroomEntity.java +++ b/src/main/java/com/wenxin2/marioverse/entities/BaseMushroomEntity.java @@ -48,11 +48,14 @@ public void tick() { @Override public boolean hurt(DamageSource source, float amount) { - this.level().addParticle(ParticleTypes.POOF, - this.getX(0.5), this.getY(0.5), this.getZ(0.5), - 0.0, 0.0, 0.0); - - // Immediately remove the entity + // Poof particle effect + if (!this.level().isClientSide) { + for (int i = 0; i < 10; i++) { + this.level().addParticle(ParticleTypes.POOF, + this.getX(0.5), this.getY(0.5), this.getZ(0.5), + 0.0, 0.0, 0.0); + } + } this.remove(RemovalReason.KILLED); return true; } diff --git a/src/main/java/com/wenxin2/marioverse/entities/BasePowerUpEntity.java b/src/main/java/com/wenxin2/marioverse/entities/BasePowerUpEntity.java index b6cefd1d..b8156e3e 100644 --- a/src/main/java/com/wenxin2/marioverse/entities/BasePowerUpEntity.java +++ b/src/main/java/com/wenxin2/marioverse/entities/BasePowerUpEntity.java @@ -49,9 +49,11 @@ public void tick() { public boolean hurt(DamageSource source, float amount) { // Poof particle effect if (!this.level().isClientSide) { - this.level().addParticle(ParticleTypes.POOF, - this.getX(0.5), this.getY(0.5), this.getZ(0.5), - 0.0, 0.0, 0.0); + for (int i = 0; i < 10; i++) { + this.level().addParticle(ParticleTypes.POOF, + this.getX(0.5), this.getY(0.5), this.getZ(0.5), + 0.0, 0.0, 0.0); + } } this.remove(RemovalReason.KILLED); return true; diff --git a/src/main/java/com/wenxin2/marioverse/entities/MushroomEntity.java b/src/main/java/com/wenxin2/marioverse/entities/MushroomEntity.java index 3fe8906b..171200e6 100644 --- a/src/main/java/com/wenxin2/marioverse/entities/MushroomEntity.java +++ b/src/main/java/com/wenxin2/marioverse/entities/MushroomEntity.java @@ -2,10 +2,12 @@ import com.wenxin2.marioverse.init.ConfigRegistry; import com.wenxin2.marioverse.init.SoundRegistry; +import com.wenxin2.marioverse.init.TagRegistry; import java.util.List; import net.minecraft.sounds.SoundSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.goal.FloatGoal; import net.minecraft.world.entity.ai.goal.LookAtPlayerGoal; import net.minecraft.world.entity.ai.goal.WaterAvoidingRandomStrollGoal; @@ -74,12 +76,12 @@ public void checkForCollisions() { @Override public void handleCollision(Entity entity) { - if (!this.level().isClientSide && !(entity instanceof BasePowerUpEntity)) { + if (!this.level().isClientSide) { this.level().playSound(null, this.blockPosition(), SoundRegistry.POWER_UP_SPAWNS.get(), SoundSource.PLAYERS, 1.0F, 1.0F); - if (entity instanceof Player player) { - if (player.getHealth() <= ConfigRegistry.HEALTH_SHRINK_PLAYER.get()) { - if (ConfigRegistry.DAMAGE_SHRINKS_PLAYER.get()) { + if (entity instanceof Player player && ConfigRegistry.DAMAGE_SHRINKS_PLAYERS.get()) { + if (player.getHealth() > ConfigRegistry.HEALTH_SHRINK_PLAYERS.get()) { + if (ConfigRegistry.DAMAGE_SHRINKS_PLAYERS.get()) { ScaleTypes.HEIGHT.getScaleData(player).setTargetScale(1.0F); ScaleTypes.WIDTH.getScaleData(player).setTargetScale(1.0F); } @@ -87,11 +89,24 @@ public void handleCollision(Entity entity) { } if (player.getHealth() < player.getMaxHealth()) player.heal(ConfigRegistry.MUSHROOM_HEAL_AMT.get().floatValue()); + // Poof particle + this.level().broadcastEntityEvent(this, (byte) 20); + this.remove(Entity.RemovalReason.KILLED); + } else if (entity instanceof LivingEntity livingEntity && ConfigRegistry.DAMAGE_SHRINKS_ALL_MOBS.get() + && !livingEntity.getType().is(TagRegistry.DAMAGE_SHRINKS_ENTITY_BLACKLIST)) { + if (livingEntity.getHealth() > livingEntity.getMaxHealth() * ConfigRegistry.HEALTH_SHRINK_MOBS.get()) { + if (ConfigRegistry.DAMAGE_SHRINKS_ALL_MOBS.get()) { + ScaleTypes.HEIGHT.getScaleData(livingEntity).setTargetScale(1.0F); + ScaleTypes.WIDTH.getScaleData(livingEntity).setTargetScale(1.0F); + } + livingEntity.getPersistentData().putBoolean("marioverse:has_mushroom", Boolean.TRUE); + } + if (livingEntity.getHealth() < livingEntity.getMaxHealth()) + livingEntity.heal(ConfigRegistry.MUSHROOM_HEAL_AMT.get().floatValue()); + // Poof particle + this.level().broadcastEntityEvent(this, (byte) 20); + this.remove(Entity.RemovalReason.KILLED); } - - // Poof particle - this.level().broadcastEntityEvent(this, (byte) 20); - this.remove(Entity.RemovalReason.KILLED); } } } 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 dbb06c45..81bf4b0c 100644 --- a/src/main/java/com/wenxin2/marioverse/event_handlers/MarioverseEventHandlers.java +++ b/src/main/java/com/wenxin2/marioverse/event_handlers/MarioverseEventHandlers.java @@ -1,10 +1,10 @@ package com.wenxin2.marioverse.event_handlers; -import com.ibm.icu.number.Scale; import com.wenxin2.marioverse.Marioverse; import com.wenxin2.marioverse.blocks.client.WarpPipeScreen; import com.wenxin2.marioverse.blocks.entities.WarpPipeBlockEntity; import com.wenxin2.marioverse.init.ConfigRegistry; +import com.wenxin2.marioverse.init.TagRegistry; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.entity.LivingEntity; @@ -43,8 +43,22 @@ public static void onEntityDamaged(LivingIncomingDamageEvent event) { if (event.getEntity() instanceof Player player) { float healthAfterDamage = player.getHealth() - event.getAmount(); tag.putBoolean("marioverse:has_mushroom", false); - if (healthAfterDamage <= ConfigRegistry.HEALTH_SHRINK_PLAYER.get()) { - if (!tag.getBoolean("marioverse:has_mushroom") && ConfigRegistry.DAMAGE_SHRINKS_PLAYER.get()) { + if (healthAfterDamage <= ConfigRegistry.HEALTH_SHRINK_PLAYERS.get()) { + if (!tag.getBoolean("marioverse:has_mushroom") && ConfigRegistry.DAMAGE_SHRINKS_PLAYERS.get() + && !player.getType().is(TagRegistry.DAMAGE_SHRINKS_ENTITY_BLACKLIST)) { + ScaleTypes.HEIGHT.getScaleData(event.getEntity()).setTargetScale(0.5F); + ScaleTypes.WIDTH.getScaleData(event.getEntity()).setTargetScale(0.75F); + } + } + } else if (event.getEntity() instanceof LivingEntity livingEntity && ConfigRegistry.DAMAGE_SHRINKS_ALL_MOBS.get()) { + float maxHealth = livingEntity.getMaxHealth(); + float healthAfterDamage = livingEntity.getHealth() - event.getAmount(); + float threshold = maxHealth * ConfigRegistry.HEALTH_SHRINK_MOBS.get().floatValue(); + + tag.putBoolean("marioverse:has_mushroom", false); + if (healthAfterDamage <= threshold) { + if (!tag.getBoolean("marioverse:has_mushroom") + && !livingEntity.getType().is(TagRegistry.DAMAGE_SHRINKS_ENTITY_BLACKLIST)) { ScaleTypes.HEIGHT.getScaleData(event.getEntity()).setTargetScale(0.5F); ScaleTypes.WIDTH.getScaleData(event.getEntity()).setTargetScale(0.75F); } @@ -66,10 +80,19 @@ public static void onEntityDamaged(LivingIncomingDamageEvent event) { public static void onEntityHeal(LivingHealEvent event) { CompoundTag tag = event.getEntity().getPersistentData(); - if (event.getEntity() instanceof Player player && player.getHealth() > ConfigRegistry.HEALTH_SHRINK_PLAYER.get()) { + if (event.getEntity() instanceof Player player && player.getHealth() > ConfigRegistry.HEALTH_SHRINK_PLAYERS.get()) { + if (!tag.getBoolean("marioverse:has_mushroom")) { + tag.putBoolean("marioverse:has_mushroom", true); + if (ConfigRegistry.DAMAGE_SHRINKS_PLAYERS.get()) { + ScaleTypes.HEIGHT.getScaleData(event.getEntity()).setTargetScale(1.0F); + ScaleTypes.WIDTH.getScaleData(event.getEntity()).setTargetScale(1.0F); + } + } + } else if (event.getEntity() instanceof LivingEntity livingEntity + && livingEntity.getHealth() > livingEntity.getMaxHealth() * ConfigRegistry.HEALTH_SHRINK_MOBS.get()) { if (!tag.getBoolean("marioverse:has_mushroom")) { tag.putBoolean("marioverse:has_mushroom", true); - if (ConfigRegistry.DAMAGE_SHRINKS_PLAYER.get()) { + if (ConfigRegistry.DAMAGE_SHRINKS_PLAYERS.get()) { ScaleTypes.HEIGHT.getScaleData(event.getEntity()).setTargetScale(1.0F); ScaleTypes.WIDTH.getScaleData(event.getEntity()).setTargetScale(1.0F); } diff --git a/src/main/java/com/wenxin2/marioverse/init/ConfigRegistry.java b/src/main/java/com/wenxin2/marioverse/init/ConfigRegistry.java index 70fdba7c..274decfe 100644 --- a/src/main/java/com/wenxin2/marioverse/init/ConfigRegistry.java +++ b/src/main/java/com/wenxin2/marioverse/init/ConfigRegistry.java @@ -28,13 +28,15 @@ public class ConfigRegistry public static ModConfigSpec.BooleanValue CREATIVE_CLOSE_PIPES; public static ModConfigSpec.BooleanValue CREATIVE_WATER_SPOUT; public static ModConfigSpec.BooleanValue CREATIVE_WRENCH_PIPE_LINKING; - public static ModConfigSpec.BooleanValue DAMAGE_SHRINKS_PLAYER; + public static ModConfigSpec.BooleanValue DAMAGE_SHRINKS_ALL_MOBS; + public static ModConfigSpec.BooleanValue DAMAGE_SHRINKS_PLAYERS; public static ModConfigSpec.BooleanValue DEBUG_PIPE_BUBBLES_SELECTION_BOX; public static ModConfigSpec.BooleanValue DEBUG_WATER_SPOUT_SELECTION_BOX; public static ModConfigSpec.BooleanValue DEBUG_SELECTION_BOX; public static ModConfigSpec.BooleanValue DEBUG_SELECTION_BOX_CREATIVE; public static ModConfigSpec.BooleanValue DISABLE_TEXT; - public static ModConfigSpec.DoubleValue HEALTH_SHRINK_PLAYER; + public static ModConfigSpec.DoubleValue HEALTH_SHRINK_MOBS; + public static ModConfigSpec.DoubleValue HEALTH_SHRINK_PLAYERS; public static ModConfigSpec.DoubleValue MUSHROOM_HEAL_AMT; public static ModConfigSpec.BooleanValue QUESTION_ADD_ITEMS; public static ModConfigSpec.BooleanValue QUESTION_REMOVE_ITEMS; @@ -171,18 +173,26 @@ private ConfigRegistry() { BUILDER.pop(); BUILDER.push(CATEGORY_GAMEPLAY); - DAMAGE_SHRINKS_PLAYER = BUILDER.translation("configuration.marioverse.damage_shrinks_players") + DAMAGE_SHRINKS_PLAYERS = BUILDER.translation("configuration.marioverse.damage_shrinks_players") .comment("Allow damage to shrink players.") .comment("§9[Default: true]") .define("damage_shrinks_players", true); + DAMAGE_SHRINKS_ALL_MOBS = BUILDER.translation("configuration.marioverse.damage_shrinks_all_mobs") + .comment("Allow damage to shrink all mobs.") + .comment("§9[Default: false]") + .define("damage_shrinks_all_mobs", false); MUSHROOM_HEAL_AMT = BUILDER.translation("configuration.marioverse.mushroom_heal_amount") .comment("Amount of health Mushrooms heals.") .comment("§9[Default: 2.5F]§b") .defineInRange("mushroom_heal_amount", 2.5F, 0.0F, 100.0F); - HEALTH_SHRINK_PLAYER = BUILDER.translation("configuration.marioverse.health_shrink_player") + HEALTH_SHRINK_PLAYERS = BUILDER.translation("configuration.marioverse.health_shrink_players") .comment("Health to shrink player at.") .comment("§9[Default: 10.0F]§b") - .defineInRange("health_shrink_player", 10.0F, 0.0F, 100.0F); + .defineInRange("health_shrink_players", 10.0F, 0.0F, 100.0F); + HEALTH_SHRINK_MOBS = BUILDER.translation("configuration.marioverse.health_shrink_mobs") + .comment("Health in percent to shrink mobs at.") + .comment("§9[Default: 0.2%]§b") + .defineInRange("health_shrink_mobs", 0.2F, 0.0F, 1.0F); BUILDER.pop(); BUILDER.pop(); diff --git a/src/main/java/com/wenxin2/marioverse/init/TagRegistry.java b/src/main/java/com/wenxin2/marioverse/init/TagRegistry.java index 2fc38eb4..f4b8a500 100644 --- a/src/main/java/com/wenxin2/marioverse/init/TagRegistry.java +++ b/src/main/java/com/wenxin2/marioverse/init/TagRegistry.java @@ -15,10 +15,13 @@ public class TagRegistry { public static final TagKey WARP_PIPE_BLOCKS = blockTags(Marioverse.MOD_ID, "warp_pipes"); public static final TagKey WRENCH_EFFICIENT = blockTags(Marioverse.MOD_ID, "wrench_efficient"); public static final TagKey DYEABLE_WARP_PIPE_ITEMS = itemTags(Marioverse.MOD_ID, "dyeable_warp_pipes"); + public static final TagKey POWER_UP_ITEMS = itemTags(Marioverse.MOD_ID, "power_ups"); public static final TagKey QUESTION_BLOCK_ITEM_BLACKLIST = itemTags(Marioverse.MOD_ID, "question_block_blacklist"); public static final TagKey QUESTION_BLOCK_ITEMS = itemTags(Marioverse.MOD_ID, "question_blocks"); public static final TagKey WARP_PIPE_ITEMS = itemTags(Marioverse.MOD_ID, "warp_pipes"); public static final TagKey> WARP_BLACKLIST = entityTypeTags(Marioverse.MOD_ID, "warp_blacklist"); + public static final TagKey> DAMAGE_SHRINKS_ENTITY_BLACKLIST = entityTypeTags(Marioverse.MOD_ID, "damage_shrinks_blacklist"); + public static final TagKey> POWER_UP_ENTITIES = entityTypeTags(Marioverse.MOD_ID, "power_ups"); public static final TagKey> QUESTION_BLOCK_ENTITY_BLACKLIST = entityTypeTags(Marioverse.MOD_ID, "question_block_blacklist"); public static final TagKey> QUICK_TRAVEL_BLACKLIST = entityTypeTags(Marioverse.MOD_ID, "quick_travel_blacklist"); diff --git a/src/main/java/com/wenxin2/marioverse/init/compat/ScaleRegistry.java b/src/main/java/com/wenxin2/marioverse/init/compat/ScaleRegistry.java index 84bd821e..ecc97f42 100644 --- a/src/main/java/com/wenxin2/marioverse/init/compat/ScaleRegistry.java +++ b/src/main/java/com/wenxin2/marioverse/init/compat/ScaleRegistry.java @@ -2,13 +2,11 @@ import com.wenxin2.marioverse.Marioverse; import net.minecraft.resources.ResourceLocation; -import net.neoforged.fml.common.EventBusSubscriber; import virtuoel.pehkui.api.ScaleModifier; import virtuoel.pehkui.api.ScaleModifiers; import virtuoel.pehkui.api.ScaleRegistries; import virtuoel.pehkui.api.ScaleType; -@EventBusSubscriber(modid = Marioverse.MOD_ID, bus = EventBusSubscriber.Bus.MOD) public class ScaleRegistry { public static final ScaleType MUSHROOM_SCALE; diff --git a/src/main/resources/assets/marioverse/lang/en_us.json b/src/main/resources/assets/marioverse/lang/en_us.json index 20852286..07c65d46 100644 --- a/src/main/resources/assets/marioverse/lang/en_us.json +++ b/src/main/resources/assets/marioverse/lang/en_us.json @@ -148,13 +148,14 @@ "configuration.marioverse.allow_pipe_unwaxing": "Allow Pipe Unwaxing", "configuration.marioverse.blindness_effect": "Blindness When Warping", "configuration.marioverse.creative_wrench_pipe_linking": "Link Pipes Creative Only", + "configuration.marioverse.damage_shrinks_all_mobs": "Damage Shrinks All Mobs", "configuration.marioverse.damage_shrinks_players": "Damage Shrinks Player", "configuration.marioverse.debug_pipe_bubbles_selection_box": "Pipe Bubbles Debug Selection Box", "configuration.marioverse.debug_selection_box": "Clear Pipes Debug Selection Box", "configuration.marioverse.debug_selection_box_creative": "Debug Selection Box Creative Only", "configuration.marioverse.debug_water_spout_selection_box": "Water Spout Debug Selection Box", "configuration.marioverse.disable_text": "Disable Text", - "configuration.marioverse.health_shrink_player": "Health to Shrink Player", + "configuration.marioverse.health_shrink_players": "Health to Shrink Players", "configuration.marioverse.mushroom_heal_amount": "Mushroom Heal Amount", "configuration.marioverse.question_add_items": "Add Items to Question Blocks in Survival", "configuration.marioverse.question_remove_items": "Activate Question Blocks by Right-Click", diff --git a/src/main/resources/data/marioverse/tags/entity_type/damage_shrinks_blacklist.json b/src/main/resources/data/marioverse/tags/entity_type/damage_shrinks_blacklist.json new file mode 100644 index 00000000..7289612a --- /dev/null +++ b/src/main/resources/data/marioverse/tags/entity_type/damage_shrinks_blacklist.json @@ -0,0 +1,7 @@ +{ + "_comment": "Blacklist to prevent entities from shrinking when damaged", + "replace": false, + "values": [ + { "id": "#marioverse:power_ups", "required": false } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/marioverse/tags/entity_type/power_ups.json b/src/main/resources/data/marioverse/tags/entity_type/power_ups.json new file mode 100644 index 00000000..00425cfe --- /dev/null +++ b/src/main/resources/data/marioverse/tags/entity_type/power_ups.json @@ -0,0 +1,7 @@ +{ + "_comment": "Tag for all power ups", + "replace": false, + "values": [ + { "id": "marioverse:mushroom", "required": false } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/marioverse/tags/item/power_ups.json b/src/main/resources/data/marioverse/tags/item/power_ups.json new file mode 100644 index 00000000..47a50b01 --- /dev/null +++ b/src/main/resources/data/marioverse/tags/item/power_ups.json @@ -0,0 +1,7 @@ +{ + "_comment": "Tag for all power up items", + "replace": false, + "values": [ + { "id": "marioverse:mushroom", "required": false } + ] +} \ No newline at end of file