Skip to content

Commit

Permalink
More configs for mushrooms
Browse files Browse the repository at this point in the history
- Allow all entities to shrink when damaged
  • Loading branch information
WenXin20 committed Sep 10, 2024
1 parent c42d181 commit f0e71a9
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
31 changes: 23 additions & 8 deletions src/main/java/com/wenxin2/marioverse/entities/MushroomEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,24 +76,37 @@ 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);
}
player.getPersistentData().putBoolean("marioverse:has_mushroom", Boolean.TRUE);
}
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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
20 changes: 15 additions & 5 deletions src/main/java/com/wenxin2/marioverse/init/ConfigRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/wenxin2/marioverse/init/TagRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ public class TagRegistry {
public static final TagKey<Block> WARP_PIPE_BLOCKS = blockTags(Marioverse.MOD_ID, "warp_pipes");
public static final TagKey<Block> WRENCH_EFFICIENT = blockTags(Marioverse.MOD_ID, "wrench_efficient");
public static final TagKey<Item> DYEABLE_WARP_PIPE_ITEMS = itemTags(Marioverse.MOD_ID, "dyeable_warp_pipes");
public static final TagKey<Item> POWER_UP_ITEMS = itemTags(Marioverse.MOD_ID, "power_ups");
public static final TagKey<Item> QUESTION_BLOCK_ITEM_BLACKLIST = itemTags(Marioverse.MOD_ID, "question_block_blacklist");
public static final TagKey<Item> QUESTION_BLOCK_ITEMS = itemTags(Marioverse.MOD_ID, "question_blocks");
public static final TagKey<Item> WARP_PIPE_ITEMS = itemTags(Marioverse.MOD_ID, "warp_pipes");
public static final TagKey<EntityType<?>> WARP_BLACKLIST = entityTypeTags(Marioverse.MOD_ID, "warp_blacklist");
public static final TagKey<EntityType<?>> DAMAGE_SHRINKS_ENTITY_BLACKLIST = entityTypeTags(Marioverse.MOD_ID, "damage_shrinks_blacklist");
public static final TagKey<EntityType<?>> POWER_UP_ENTITIES = entityTypeTags(Marioverse.MOD_ID, "power_ups");
public static final TagKey<EntityType<?>> QUESTION_BLOCK_ENTITY_BLACKLIST = entityTypeTags(Marioverse.MOD_ID, "question_block_blacklist");
public static final TagKey<EntityType<?>> QUICK_TRAVEL_BLACKLIST = entityTypeTags(Marioverse.MOD_ID, "quick_travel_blacklist");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/assets/marioverse/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"_comment": "Blacklist to prevent entities from shrinking when damaged",
"replace": false,
"values": [
{ "id": "#marioverse:power_ups", "required": false }
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"_comment": "Tag for all power ups",
"replace": false,
"values": [
{ "id": "marioverse:mushroom", "required": false }
]
}
7 changes: 7 additions & 0 deletions src/main/resources/data/marioverse/tags/item/power_ups.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"_comment": "Tag for all power up items",
"replace": false,
"values": [
{ "id": "marioverse:mushroom", "required": false }
]
}

0 comments on commit f0e71a9

Please sign in to comment.