From 396dad4a008b0d353070ea3192c336ee17ac788e Mon Sep 17 00:00:00 2001 From: WenXin2 Date: Mon, 9 Sep 2024 20:13:00 -0500 Subject: [PATCH] Add config for power ups & entity velocity --- .../marioverse/blocks/QuestionBlock.java | 29 +++++++++++++++++-- .../marioverse/init/ConfigRegistry.java | 5 ++++ .../assets/marioverse/lang/en_us.json | 10 ++++--- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/wenxin2/marioverse/blocks/QuestionBlock.java b/src/main/java/com/wenxin2/marioverse/blocks/QuestionBlock.java index 6b678d26..9c0a2e8e 100644 --- a/src/main/java/com/wenxin2/marioverse/blocks/QuestionBlock.java +++ b/src/main/java/com/wenxin2/marioverse/blocks/QuestionBlock.java @@ -1,9 +1,11 @@ package com.wenxin2.marioverse.blocks; import com.wenxin2.marioverse.blocks.entities.QuestionBlockEntity; +import com.wenxin2.marioverse.entities.BasePowerUpEntity; import com.wenxin2.marioverse.init.ConfigRegistry; import com.wenxin2.marioverse.init.TagRegistry; import com.wenxin2.marioverse.init.SoundRegistry; +import com.wenxin2.marioverse.items.BasePowerUpItem; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; import net.minecraft.sounds.SoundSource; @@ -159,12 +161,33 @@ else if (storedItem.getItem() instanceof SpawnEggItem) } public void spawnEntity(Level world, BlockPos pos, ItemStack stack) { - if (stack.getItem() instanceof SpawnEggItem spawnEgg && ConfigRegistry.QUESTION_SPAWNS_MOBS.get()) { + if (stack.getItem() instanceof BasePowerUpItem powerUpItem && ConfigRegistry.QUESTION_SPAWNS_POWER_UPS.get()) { + EntityType entityType = powerUpItem.getType(stack); + Entity entity = entityType.spawn((ServerLevel) world, stack, null, pos.above(1), MobSpawnType.SPAWN_EGG, true, false); + + if (world instanceof ServerLevel serverWorld && !entityType.is(TagRegistry.QUESTION_BLOCK_ENTITY_BLACKLIST)) { + if (world.getBlockState(pos.above()).isAir()) { + if (entity != null) + entity.setDeltaMovement(entity.getDeltaMovement().add(0, 0.25, 0)); + } + else entityType.spawn(serverWorld, stack, null, pos.below((int) Math.max(1, entityType.getHeight())), MobSpawnType.SPAWN_EGG, true, true); + stack.copyWithCount(1); + } else if (world.getBlockState(pos.above()).isAir()) { + ItemEntity itemEntity = new ItemEntity(world, pos.getX() + 0.5D, pos.getY() + 1.0D, pos.getZ() + 0.5D, stack.copyWithCount(1)); + world.addFreshEntity(itemEntity); + } else { + ItemEntity itemEntity = new ItemEntity(world, pos.getX() + 0.5D, pos.getY() - 0.5D, pos.getZ() + 0.5D, stack.copyWithCount(1)); + world.addFreshEntity(itemEntity); + } + } else if (stack.getItem() instanceof SpawnEggItem spawnEgg && ConfigRegistry.QUESTION_SPAWNS_MOBS.get()) { EntityType entityType = spawnEgg.getType(stack); + Entity entity = entityType.spawn((ServerLevel) world, stack, null, pos.above(1), MobSpawnType.SPAWN_EGG, true, false); if (world instanceof ServerLevel serverWorld && !entityType.is(TagRegistry.QUESTION_BLOCK_ENTITY_BLACKLIST)) { - if (world.getBlockState(pos.above()).isAir()) - entityType.spawn(serverWorld, stack, null, pos.above(2), MobSpawnType.SPAWN_EGG, true, true); + if (world.getBlockState(pos.above()).isAir()) { + if (entity != null) + entity.setDeltaMovement(entity.getDeltaMovement().add(0, 0.25, 0)); + } else entityType.spawn(serverWorld, stack, null, pos.below((int) Math.max(1, entityType.getHeight())), MobSpawnType.SPAWN_EGG, true, true); stack.copyWithCount(1); } else if (world.getBlockState(pos.above()).isAir()) { diff --git a/src/main/java/com/wenxin2/marioverse/init/ConfigRegistry.java b/src/main/java/com/wenxin2/marioverse/init/ConfigRegistry.java index 93682ad1..27248ac0 100644 --- a/src/main/java/com/wenxin2/marioverse/init/ConfigRegistry.java +++ b/src/main/java/com/wenxin2/marioverse/init/ConfigRegistry.java @@ -35,6 +35,7 @@ public class ConfigRegistry public static ModConfigSpec.BooleanValue QUESTION_ADD_ITEMS; public static ModConfigSpec.BooleanValue QUESTION_REMOVE_ITEMS; public static ModConfigSpec.BooleanValue QUESTION_SPAWNS_MOBS; + public static ModConfigSpec.BooleanValue QUESTION_SPAWNS_POWER_UPS; public static ModConfigSpec.BooleanValue REDSTONE_OPENS_QUESTION; public static ModConfigSpec.BooleanValue TELEPORT_MOBS; public static ModConfigSpec.BooleanValue TELEPORT_NON_MOBS; @@ -112,6 +113,10 @@ private ConfigRegistry() { BUILDER.pop(); BUILDER.push(CATEGORY_QUESTION_BLOCK); + QUESTION_SPAWNS_POWER_UPS = BUILDER.translation("configuration.marioverse.question_spawns_power_ups") + .comment("Allow question blocks to spawn power ups.") + .comment("§9[Default: true]") + .define("question_spawns_power_ups", true); QUESTION_SPAWNS_MOBS = BUILDER.translation("configuration.marioverse.question_spawns_mobs") .comment("Allow question blocks to spawn mobs.") .comment("§9[Default: true]") diff --git a/src/main/resources/assets/marioverse/lang/en_us.json b/src/main/resources/assets/marioverse/lang/en_us.json index dd4cf8b0..4c7d6ec2 100644 --- a/src/main/resources/assets/marioverse/lang/en_us.json +++ b/src/main/resources/assets/marioverse/lang/en_us.json @@ -28,6 +28,7 @@ "block.marioverse.pipe_bubbles": "Pipe Bubbles", "block.marioverse.water_spout": "Water Spout", + "item.marioverse.mushroom": "Mushroom", "item.marioverse.pipe_wrench": "Pipe Wrench", "item.marioverse.pipe_wrench.bubbles.true": "Pipe bubbles on", "item.marioverse.pipe_wrench.bubbles.false": "Pipe bubbles off", @@ -151,13 +152,14 @@ "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.require_creative_bubbles": "Pipe Bubbles Creative Only", - "configuration.marioverse.require_creative_close_pipes": "Closing Pipes Creative Only", - "configuration.marioverse.require_creative_water_spouts": "Water Spouts Creative Only", - "configuration.marioverse.question_spawns_mobs": "Question Blocks Spawn Mobs", "configuration.marioverse.question_add_items": "Add Items to Question Blocks in Survival", "configuration.marioverse.question_remove_items": "Activate Question Blocks by Right-Click", + "configuration.marioverse.question_spawns_mobs": "Question Blocks Spawn Mobs", + "configuration.marioverse.question_spawns_power_ups": "Question Blocks Spawn Power Ups", "configuration.marioverse.redstone_opens_question": "Activate Question Blocks with Redstone", + "configuration.marioverse.require_creative_bubbles": "Pipe Bubbles Creative Only", + "configuration.marioverse.require_creative_close_pipes": "Closing Pipes Creative Only", + "configuration.marioverse.require_creative_water_spouts": "Water Spouts Creative Only", "configuration.marioverse.teleport_mobs": "Teleport Mobs", "configuration.marioverse.teleport_non_mobs": "Teleport Non-Living Entities", "configuration.marioverse.teleport_players": "Teleport Players",