hytopia 0.1.33 → 0.1.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/server.collider.md +21 -0
- package/docs/server.collider.shape.md +13 -0
- package/docs/server.default_block_entity_rigid_body_options.md +13 -0
- package/docs/server.default_entity_rigid_body_options.md +1 -1
- package/docs/server.entity.blockhalfextents.md +13 -0
- package/docs/server.entity.blocktextureuri.md +13 -0
- package/docs/server.entity.md +63 -0
- package/docs/server.entity.tag.md +13 -0
- package/docs/server.entitymanager.getentitiesbytag.md +55 -0
- package/docs/server.entitymanager.getentitiesbytagsubstring.md +55 -0
- package/docs/server.entitymanager.md +28 -0
- package/docs/server.entityoptions.blockhalfextents.md +13 -0
- package/docs/server.entityoptions.blocktextureuri.md +13 -0
- package/docs/server.entityoptions.md +57 -0
- package/docs/server.entityoptions.tag.md +13 -0
- package/docs/server.hytopia.collider.md +21 -0
- package/docs/server.hytopia.collider.shape.md +13 -0
- package/docs/server.hytopia.default_block_entity_rigid_body_options.md +13 -0
- package/docs/server.hytopia.default_entity_rigid_body_options.md +1 -1
- package/docs/server.hytopia.entity.blockhalfextents.md +13 -0
- package/docs/server.hytopia.entity.blocktextureuri.md +13 -0
- package/docs/server.hytopia.entity.md +63 -0
- package/docs/server.hytopia.entity.tag.md +13 -0
- package/docs/server.hytopia.entitymanager.getentitiesbytag.md +55 -0
- package/docs/server.hytopia.entitymanager.getentitiesbytagsubstring.md +55 -0
- package/docs/server.hytopia.entitymanager.md +28 -0
- package/docs/server.hytopia.entityoptions.blockhalfextents.md +13 -0
- package/docs/server.hytopia.entityoptions.blocktextureuri.md +13 -0
- package/docs/server.hytopia.entityoptions.md +57 -0
- package/docs/server.hytopia.entityoptions.tag.md +13 -0
- package/docs/server.hytopia.md +12 -1
- package/docs/server.hytopia.rigidbody.md +0 -35
- package/docs/server.hytopia.rigidbodyoptions.md +0 -19
- package/docs/server.hytopia.webserver.md +1 -2
- package/docs/server.md +12 -1
- package/docs/server.rigidbody.md +0 -35
- package/docs/server.rigidbodyoptions.md +0 -19
- package/docs/server.webserver.md +1 -2
- package/examples/block-entity/README.md +15 -0
- package/examples/block-entity/assets/audio/music/cave.mp3 +0 -0
- package/examples/block-entity/assets/audio/music/desert.mp3 +0 -0
- package/examples/block-entity/assets/audio/music/end.mp3 +0 -0
- package/examples/block-entity/assets/audio/music/jungle.mp3 +0 -0
- package/examples/block-entity/assets/audio/music/nether.mp3 +0 -0
- package/examples/block-entity/assets/audio/music/night.mp3 +0 -0
- package/examples/block-entity/assets/audio/music/night2.mp3 +0 -0
- package/examples/block-entity/assets/audio/music/overworld.mp3 +0 -0
- package/examples/block-entity/assets/audio/music/snow.mp3 +0 -0
- package/examples/block-entity/assets/audio/sfx/damage.wav +0 -0
- package/examples/block-entity/assets/audio/sfx/step.wav +0 -0
- package/examples/block-entity/assets/certs/README.md +10 -0
- package/examples/block-entity/assets/certs/localhost.crt +20 -0
- package/examples/block-entity/assets/certs/localhost.key +27 -0
- package/examples/block-entity/assets/cubemaps/skybox/+x.png +0 -0
- package/examples/block-entity/assets/cubemaps/skybox/+y.png +0 -0
- package/examples/block-entity/assets/cubemaps/skybox/+z.png +0 -0
- package/examples/block-entity/assets/cubemaps/skybox/-x.png +0 -0
- package/examples/block-entity/assets/cubemaps/skybox/-y.png +0 -0
- package/examples/block-entity/assets/cubemaps/skybox/-z.png +0 -0
- package/examples/block-entity/assets/map.json +2623 -0
- package/examples/block-entity/assets/models/bat.gltf +1 -0
- package/examples/block-entity/assets/models/chicken.gltf +1 -0
- package/examples/block-entity/assets/models/cow.gltf +1 -0
- package/examples/block-entity/assets/models/donkey.gltf +1 -0
- package/examples/block-entity/assets/models/horse.gltf +1 -0
- package/examples/block-entity/assets/models/mindflayer.gltf +1 -0
- package/examples/block-entity/assets/models/pig.gltf +1 -0
- package/examples/block-entity/assets/models/player.gltf +1 -0
- package/examples/block-entity/assets/models/rabbit.gltf +1 -0
- package/examples/block-entity/assets/models/sheep.gltf +1 -0
- package/examples/block-entity/assets/models/skeleton.gltf +1 -0
- package/examples/block-entity/assets/models/spider.gltf +1 -0
- package/examples/block-entity/assets/models/squid.gltf +1 -0
- package/examples/block-entity/assets/models/stalker.gltf +1 -0
- package/examples/block-entity/assets/models/zombie.gltf +1 -0
- package/examples/block-entity/assets/textures/bricks.png +0 -0
- package/examples/block-entity/assets/textures/clay.png +0 -0
- package/examples/block-entity/assets/textures/cobblestone.png +0 -0
- package/examples/block-entity/assets/textures/diamond_ore.png +0 -0
- package/examples/block-entity/assets/textures/dirt.png +0 -0
- package/examples/block-entity/assets/textures/dragons_stone.png +0 -0
- package/examples/block-entity/assets/textures/emerald_ore.png +0 -0
- package/examples/block-entity/assets/textures/glass.png +0 -0
- package/examples/block-entity/assets/textures/gold_ore.png +0 -0
- package/examples/block-entity/assets/textures/grass/+x.png +0 -0
- package/examples/block-entity/assets/textures/grass/+y.png +0 -0
- package/examples/block-entity/assets/textures/grass/+z.png +0 -0
- package/examples/block-entity/assets/textures/grass/-x.png +0 -0
- package/examples/block-entity/assets/textures/grass/-y.png +0 -0
- package/examples/block-entity/assets/textures/grass/-z.png +0 -0
- package/examples/block-entity/assets/textures/gravel.png +0 -0
- package/examples/block-entity/assets/textures/ice.png +0 -0
- package/examples/block-entity/assets/textures/infected_shadowrock.png +0 -0
- package/examples/block-entity/assets/textures/iron_ore.png +0 -0
- package/examples/block-entity/assets/textures/lava.png +0 -0
- package/examples/block-entity/assets/textures/log_side.png +0 -0
- package/examples/block-entity/assets/textures/log_top.png +0 -0
- package/examples/block-entity/assets/textures/mossy_coblestone.png +0 -0
- package/examples/block-entity/assets/textures/nuit.png +0 -0
- package/examples/block-entity/assets/textures/oak_leaves.png +0 -0
- package/examples/block-entity/assets/textures/oak_planks.png +0 -0
- package/examples/block-entity/assets/textures/sand.png +0 -0
- package/examples/block-entity/assets/textures/sandstone.png +0 -0
- package/examples/block-entity/assets/textures/shadowrock.png +0 -0
- package/examples/block-entity/assets/textures/snow.png +0 -0
- package/examples/block-entity/assets/textures/stone.png +0 -0
- package/examples/block-entity/assets/textures/stone_bricks.png +0 -0
- package/examples/block-entity/assets/textures/void_grass/+x.png +0 -0
- package/examples/block-entity/assets/textures/void_grass/+y.png +0 -0
- package/examples/block-entity/assets/textures/void_grass/+z.png +0 -0
- package/examples/block-entity/assets/textures/void_grass/-x.png +0 -0
- package/examples/block-entity/assets/textures/void_grass/-y.png +0 -0
- package/examples/block-entity/assets/textures/void_grass/-z.png +0 -0
- package/examples/block-entity/assets/textures/void_sand.png +0 -0
- package/examples/block-entity/assets/textures/water.png +0 -0
- package/examples/block-entity/index.ts +173 -0
- package/examples/block-entity/package.json +14 -0
- package/examples/payload-game/index.ts +7 -0
- package/package.json +1 -1
- package/server.api.json +948 -510
- package/server.d.ts +38 -17
- package/server.js +80 -80
- package/docs/server.hytopia.rigidbody.settag.md +0 -53
- package/docs/server.hytopia.rigidbody.tag.md +0 -13
- package/docs/server.hytopia.rigidbodyoptions.tag.md +0 -13
- package/docs/server.rigidbody.settag.md +0 -53
- package/docs/server.rigidbody.tag.md +0 -13
- package/docs/server.rigidbodyoptions.tag.md +0 -13
- package/examples/README.md +0 -22
@@ -0,0 +1,173 @@
|
|
1
|
+
import {
|
2
|
+
startServer,
|
3
|
+
ColliderShape,
|
4
|
+
PlayerEntity,
|
5
|
+
Entity,
|
6
|
+
RigidBodyType,
|
7
|
+
GameServer,
|
8
|
+
SimpleCharacterController,
|
9
|
+
} from 'hytopia';
|
10
|
+
|
11
|
+
import worldMap from './assets/map.json';
|
12
|
+
|
13
|
+
startServer(world => {
|
14
|
+
// Boilerplate
|
15
|
+
world.simulation.enableDebugRendering(true);
|
16
|
+
world.loadMap(worldMap);
|
17
|
+
world.onPlayerJoin = player => {
|
18
|
+
const playerEntity = new PlayerEntity({
|
19
|
+
player,
|
20
|
+
name: 'Player',
|
21
|
+
modelUri: 'models/player.gltf',
|
22
|
+
modelLoopedAnimations: [ 'idle' ],
|
23
|
+
modelScale: 0.5,
|
24
|
+
});
|
25
|
+
|
26
|
+
playerEntity.spawn(world, { x: 0, y: 10, z: 0 });
|
27
|
+
};
|
28
|
+
|
29
|
+
world.onPlayerLeave = player => {
|
30
|
+
world.entityManager.getAllPlayerEntities(player).forEach(entity => entity.despawn());
|
31
|
+
};
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Spawn a block entity as a moving platform
|
35
|
+
*/
|
36
|
+
const blockPlatform = new Entity({
|
37
|
+
blockTextureUri: 'textures/grass', // A texture URI without a file extension will use a folder and look for the textures for each face in the folder (-x.png, +x.png, -y.png, +y.png, -z.png, +z.png)
|
38
|
+
blockHalfExtents: { x: 1, y: 0.5, z: 1 },
|
39
|
+
rigidBodyOptions: {
|
40
|
+
type: RigidBodyType.KINEMATIC_VELOCITY, // Kinematic means platform won't be effected by external physics, including gravity
|
41
|
+
linearVelocity: { x: 0, y: 0, z: 3 }, // A starting velocity that won't change because it's kinematic
|
42
|
+
},
|
43
|
+
});
|
44
|
+
|
45
|
+
// Clamp the z range the platform moves back and forth between
|
46
|
+
blockPlatform.onTick = blockPlatform => {
|
47
|
+
const position = blockPlatform.getTranslation();
|
48
|
+
|
49
|
+
if (position.z < -9) {
|
50
|
+
blockPlatform.setLinearVelocity({ x: 0, y: 0, z: 3 });
|
51
|
+
}
|
52
|
+
|
53
|
+
if (position.z > 8) {
|
54
|
+
blockPlatform.setLinearVelocity({ x: 0, y: 0, z: -3 });
|
55
|
+
}
|
56
|
+
};
|
57
|
+
|
58
|
+
blockPlatform.spawn(world, { x: 3, y: 3, z: -7 });
|
59
|
+
|
60
|
+
/**
|
61
|
+
* Spawn a 2x2x2 block entity that spins in the air
|
62
|
+
*/
|
63
|
+
const spinningBlock = new Entity({
|
64
|
+
blockTextureUri: 'textures/stone_bricks.png',
|
65
|
+
blockHalfExtents: { x: 1, y: 1, z: 1 }, // half extents at the target size / 2.
|
66
|
+
rigidBodyOptions: {
|
67
|
+
type: RigidBodyType.KINEMATIC_VELOCITY,
|
68
|
+
angularVelocity: { x: 1, y: 1, z: 1 },
|
69
|
+
}
|
70
|
+
});
|
71
|
+
|
72
|
+
spinningBlock.spawn(world, { x: 0, y: 10, z: -6 });
|
73
|
+
|
74
|
+
/**
|
75
|
+
* Spawn a block entity that interacts with physics and can be pushed by players
|
76
|
+
*/
|
77
|
+
const movableBlock = new Entity({ // Entity is dynamic by default, meaning it will interact with external forces, including gravity
|
78
|
+
blockTextureUri: 'textures/sand.png',
|
79
|
+
|
80
|
+
// A block of 1x1x1 would be half extents of 0.5x0.5x0.5,
|
81
|
+
// if you do not explicitly create rigidBodyOptions.colliders
|
82
|
+
// for the block, a collider will be created automatically
|
83
|
+
// based on the block half extends.
|
84
|
+
blockHalfExtents: { x: 0.5, y: 0.5, z: 0.5 },
|
85
|
+
});
|
86
|
+
|
87
|
+
movableBlock.onEntityCollision = (movableBlock, otherEntity, started) => {
|
88
|
+
if (started) {
|
89
|
+
world.chatManager.sendBroadcastMessage('The sand block was pushed!');
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
movableBlock.spawn(world, { x: -4, y: 10, z: -6 });
|
94
|
+
|
95
|
+
/**
|
96
|
+
* Spawn a very heavy block that interacts with physics, and is much harder to move,
|
97
|
+
* Also, prevent it from rotating.
|
98
|
+
*/
|
99
|
+
const heavyBlock = new Entity({
|
100
|
+
blockTextureUri: 'textures/stone_bricks.png',
|
101
|
+
blockHalfExtents: { x: 0.5, y: 0.5, z: 0.5 },
|
102
|
+
rigidBodyOptions: {
|
103
|
+
type: RigidBodyType.DYNAMIC,
|
104
|
+
additionalMass: 10,
|
105
|
+
enabledRotations: { x: false, y: false, z: false },
|
106
|
+
}
|
107
|
+
});
|
108
|
+
|
109
|
+
heavyBlock.spawn(world, { x: -4, y: 10, z: -1 });
|
110
|
+
|
111
|
+
/**
|
112
|
+
* Spawn a bouncing block, because why not?
|
113
|
+
* Also disable rotations so it doesn't spin around like a maniac
|
114
|
+
*/
|
115
|
+
const bouncingBlock = new Entity({
|
116
|
+
blockTextureUri: 'textures/ice.png',
|
117
|
+
blockHalfExtents: { x: 0.5, y: 0.5, z: 0.5 },
|
118
|
+
rigidBodyOptions: {
|
119
|
+
type: RigidBodyType.DYNAMIC,
|
120
|
+
enabledRotations: { x: false, y: false, z: false },
|
121
|
+
colliders: [
|
122
|
+
{
|
123
|
+
shape: ColliderShape.BLOCK,
|
124
|
+
halfExtents: { x: 0.5, y: 0.5, z: 0.5 },
|
125
|
+
bounciness: 2
|
126
|
+
}
|
127
|
+
]
|
128
|
+
}
|
129
|
+
});
|
130
|
+
|
131
|
+
bouncingBlock.spawn(world, { x: 0, y: 10, z: -3 });
|
132
|
+
|
133
|
+
/**
|
134
|
+
* Make a block pet that follows a player around
|
135
|
+
* Because, again why not?
|
136
|
+
*/
|
137
|
+
const blockPet = new Entity({
|
138
|
+
blockTextureUri: 'textures/bricks.png',
|
139
|
+
blockHalfExtents: { x: 0.5, y: 0.5, z: 0.5 },
|
140
|
+
// attach a simple character controller so we can pathfind,
|
141
|
+
// the character controller will be created and associated when we spawn the entity
|
142
|
+
createCustomCharacterController: entity => new SimpleCharacterController(entity),
|
143
|
+
});
|
144
|
+
|
145
|
+
blockPet.spawn(world, { x: 0, y: 10, z: -6 });
|
146
|
+
|
147
|
+
// Simple pathfinding
|
148
|
+
let pathfindAccumulator = 0;
|
149
|
+
blockPet.onTick = (blockPet, tickDeltaMs) => {
|
150
|
+
pathfindAccumulator += tickDeltaMs;
|
151
|
+
|
152
|
+
if (pathfindAccumulator > 3000) { // only pathfind every 3 seconds so we don't do unecessary pathfinding
|
153
|
+
pathfindAccumulator = 0;
|
154
|
+
|
155
|
+
const connectedPlayers = GameServer.instance.playerManager.getConnectedPlayers();
|
156
|
+
if (!connectedPlayers.length) { return; } // if no players, don't pathfind.
|
157
|
+
|
158
|
+
// pick a random player to follow
|
159
|
+
const targetPlayer = connectedPlayers[Math.floor(Math.random() * connectedPlayers.length)];
|
160
|
+
|
161
|
+
// get the player's entity
|
162
|
+
const targetPlayerEntity = world.entityManager.getAllPlayerEntities(targetPlayer)[0];
|
163
|
+
|
164
|
+
if (!targetPlayerEntity) { return; } // if the player doesn't have an entity, don't pathfind.
|
165
|
+
|
166
|
+
// pathfind to the player's entity
|
167
|
+
const blockPetCharacterController = blockPet.characterController as SimpleCharacterController;
|
168
|
+
const targetPosition = targetPlayerEntity.getTranslation();
|
169
|
+
blockPetCharacterController.move(targetPosition, 3);
|
170
|
+
blockPetCharacterController.face(targetPosition, 1);
|
171
|
+
}
|
172
|
+
};
|
173
|
+
});
|
@@ -19,6 +19,7 @@
|
|
19
19
|
import {
|
20
20
|
Audio,
|
21
21
|
BlockType,
|
22
|
+
PlayerCameraMode,
|
22
23
|
ColliderShape,
|
23
24
|
CollisionGroup,
|
24
25
|
DefaultCharacterController,
|
@@ -105,6 +106,12 @@ startServer(world => { // Perform our game setup logic in the startServer init c
|
|
105
106
|
modelScale: 0.5,
|
106
107
|
});
|
107
108
|
|
109
|
+
// Setup a first person camera for the player
|
110
|
+
player.camera.setMode(PlayerCameraMode.FIRST_PERSON); // set first person mode
|
111
|
+
player.camera.setOffset({ x: 0, y: 0.4, z: 0 }); // shift camrea up on Y axis so we see from "head" perspective.
|
112
|
+
player.camera.setHiddenModelNodes([ 'head', 'neck' ]); // hide the head node from the model so we don't see it in the camera, this is just hidden for the controlling player.
|
113
|
+
player.camera.setForwardOffset(0.3); // Shift the camera forward so we are looking slightly in front of where the player is looking.
|
114
|
+
|
108
115
|
// Spawn the player entity at a random coordinate
|
109
116
|
const randomSpawnCoordinate = PLAYER_SPAWN_COORDINATES[Math.floor(Math.random() * PLAYER_SPAWN_COORDINATES.length)];
|
110
117
|
playerEntity.spawn(world, randomSpawnCoordinate);
|
package/package.json
CHANGED