Skip to content

Commit

Permalink
Add config for power ups & entity velocity
Browse files Browse the repository at this point in the history
  • Loading branch information
WenXin20 committed Sep 10, 2024
1 parent c340c59 commit 396dad4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
29 changes: 26 additions & 3 deletions src/main/java/com/wenxin2/marioverse/blocks/QuestionBlock.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/wenxin2/marioverse/init/ConfigRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]")
Expand Down
10 changes: 6 additions & 4 deletions src/main/resources/assets/marioverse/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 396dad4

Please sign in to comment.