MinecraftScripterAI
Discord ↗
Link Copied to Clipboard
×
"a script that is very chaotic and makes mobs spawn and a black hole"
/* This script spawns mobs and creates a black hole. The black hole is represented by a custom block that sucks in nearby entities. The script also randomly spawns mobs around the player. */ public class ChaosScript { // The mob types to spawn private static final EntityType<?>[] MOB_TYPES = new EntityType<?>[] { EntityType.ZOMBIE, EntityType.SKELETON, EntityType.CREEPER }; // The black hole block private static final Block BLACK_HOLE = Blocks.BLACK_CONCRETE; public static void createChaos(World world, PlayerEntity player) { // Spawn mobs Random rand = new Random(); for (int i = 0; i < 10; i++) { EntityType<?> type = MOB_TYPES[rand.nextInt(MOB_TYPES.length)]; Entity mob = type.create(world); mob.moveTo(player.getX() + rand.nextInt(10) - 5, player.getY(), player.getZ() + rand.nextInt(10) - 5, 0, 0); world.addFreshEntity(mob); } // Create black hole BlockPos blackHolePos = player.blockPosition().offset(rand.nextInt(10) - 5, 0, rand.nextInt(10) - 5); world.setBlock(blackHolePos, BLACK_HOLE.defaultBlockState(), 3); // Suck in nearby entities List<Entity> entities = world.getEntitiesOfClass(Entity.class, new AxisAlignedBB(blackHolePos).inflate(10)); for (Entity entity : entities) { Vector3d direction = new Vector3d(blackHolePos.getX() - entity.getX(), blackHolePos.getY() - entity.getY(), blackHolePos.getZ() - entity.getZ()); entity.setDeltaMovement(entity.getDeltaMovement().add(direction.scale(0.1))); } } }