Skip to content

Commit

Permalink
Fire "summon entity" trigger for mobs spawned via Botania means
Browse files Browse the repository at this point in the history
- constructing a fel blaze (for all players within 5 blocks, like for vanilla iron/snow golems)
- starting the gaia fight (for all players considered to be in the fight)
(fixes #4554)
  • Loading branch information
TheRealWormbo committed Mar 17, 2024
1 parent 00026a8 commit 2f019c2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
*/
package vazkii.botania.common.block;

import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.monster.Blaze;
Expand Down Expand Up @@ -58,6 +60,10 @@ public void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldS
((MobAccessor) blaze).setLootTable(LOOT_TABLE);
blaze.finalizeSpawn((ServerLevelAccessor) world, world.getCurrentDifficultyAt(pos), MobSpawnType.EVENT, null, null);
world.addFreshEntity(blaze);

for (ServerPlayer player : world.getEntitiesOfClass(ServerPlayer.class, blaze.getBoundingBox().inflate(5.0))) {
CriteriaTriggers.SUMMONED_ENTITY.trigger(player, blaze);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ public static boolean spawn(Player player, ItemStack stack, Level world, BlockPo
e.mobSpawnTicks = MOB_SPAWN_TICKS;
e.hardMode = hard;

int playerCount = e.getPlayersAround().size();
List<Player> playersAround = e.getPlayersAround();
int playerCount = playersAround.size();
e.playerCount = playerCount;

float healthMultiplier = 1;
Expand All @@ -268,6 +269,12 @@ public static boolean spawn(Player player, ItemStack stack, Level world, BlockPo
e.playSound(BotaniaSounds.gaiaSummon, 1F, 1F);
e.finalizeSpawn((ServerLevelAccessor) world, world.getCurrentDifficultyAt(e.blockPosition()), MobSpawnType.EVENT, null, null);
world.addFreshEntity(e);

for (Player nearbyPlayer : playersAround) {
if (nearbyPlayer instanceof ServerPlayer serverPlayer) {
CriteriaTriggers.SUMMONED_ENTITY.trigger(serverPlayer, e);
}
}
}

return true;
Expand Down

0 comments on commit 2f019c2

Please sign in to comment.