github.com/df-mc/dragonfly@v0.9.13/server/world/viewer.go (about) 1 package world 2 3 import ( 4 "github.com/df-mc/dragonfly/server/block/cube" 5 "github.com/df-mc/dragonfly/server/world/chunk" 6 "github.com/go-gl/mathgl/mgl64" 7 "github.com/google/uuid" 8 "time" 9 ) 10 11 // Viewer is a viewer in the world. It can view changes that are made in the world, such as the addition of 12 // entities and the changes of blocks. 13 type Viewer interface { 14 // ViewEntity views the entity passed. It is called for every entity that the viewer may encounter in the 15 // world, either by moving entities or by moving the viewer using a world.Loader. 16 ViewEntity(e Entity) 17 // HideEntity stops viewing the entity passed. It is called for every entity that leaves the viewing range 18 // of the viewer, either by its movement or the movement of the viewer using a world.Loader. 19 HideEntity(e Entity) 20 // ViewEntityGameMode views the game mode of the entity passed. This is necessary for game-modes like spectator, 21 // which may update how the entity is viewed for others. 22 ViewEntityGameMode(e Entity) 23 // ViewEntityMovement views the movement of an entity. The entity is moved with a delta position, yaw and 24 // pitch, which, when applied to the respective values of the entity, will result in the final values. 25 ViewEntityMovement(e Entity, pos mgl64.Vec3, rot cube.Rotation, onGround bool) 26 // ViewEntityVelocity views the velocity of an entity. It is called right before a call to 27 // ViewEntityMovement so that the Viewer may interpolate the movement itself. 28 ViewEntityVelocity(e Entity, vel mgl64.Vec3) 29 // ViewEntityTeleport views the teleportation of an entity. The entity is immediately moved to a different 30 // target position. 31 ViewEntityTeleport(e Entity, pos mgl64.Vec3) 32 // ViewFurnaceUpdate updates a furnace for the associated session based on previous times. 33 ViewFurnaceUpdate(prevCookTime, cookTime, prevRemainingFuelTime, remainingFuelTime, prevMaxFuelTime, maxFuelTime time.Duration) 34 // ViewChunk views the chunk passed at a particular position. It is called for every chunk loaded using 35 // the world.Loader. 36 ViewChunk(pos ChunkPos, c *chunk.Chunk, blockEntities map[cube.Pos]Block) 37 // ViewTime views the time of the world. It is called every time the time is changed or otherwise every 38 // second. 39 ViewTime(t int) 40 // ViewEntityItems views the items currently held by an entity that is able to equip items. 41 ViewEntityItems(e Entity) 42 // ViewEntityArmour views the items currently equipped as armour by the entity. 43 ViewEntityArmour(e Entity) 44 // ViewEntityAction views an action performed by an entity. Available actions may be found in the `action` 45 // package, and include things such as swinging an arm. 46 ViewEntityAction(e Entity, a EntityAction) 47 // ViewEntityState views the current state of an entity. It is called whenever an entity changes its 48 // physical appearance, for example when sprinting. 49 ViewEntityState(e Entity) 50 // ViewEntityAnimation starts viewing an animation performed by an entity. The animation has to be from a resource pack. 51 ViewEntityAnimation(e Entity, animationName string) 52 // ViewParticle views a particle spawned at a given position in the world. It is called when a particle, 53 // for example a block breaking particle, is spawned near the player. 54 ViewParticle(pos mgl64.Vec3, p Particle) 55 // ViewSound is called when a sound is played in the world. 56 ViewSound(pos mgl64.Vec3, s Sound) 57 // ViewBlockUpdate views the updating of a block. It is called when a block is set at the position passed 58 // to the method. 59 ViewBlockUpdate(pos cube.Pos, b Block, layer int) 60 // ViewBlockAction views an action performed by a block. Available actions may be found in the `action` 61 // package, and include things such as a chest opening. 62 ViewBlockAction(pos cube.Pos, a BlockAction) 63 // ViewEmote views an emote being performed by another entity. 64 ViewEmote(e Entity, emote uuid.UUID) 65 // ViewSkin views the current skin of a player. 66 ViewSkin(e Entity) 67 // ViewWorldSpawn views the current spawn location of the world. 68 ViewWorldSpawn(pos cube.Pos) 69 // ViewWeather views the weather of the world, including rain and thunder. 70 ViewWeather(raining, thunder bool) 71 } 72 73 // NopViewer is a Viewer implementation that does not implement any behaviour. It may be embedded by other structs to 74 // prevent having to implement all of Viewer's methods. 75 type NopViewer struct{} 76 77 // Compile time check to make sure NopViewer implements Viewer. 78 var _ Viewer = NopViewer{} 79 80 func (NopViewer) ViewEntity(Entity) {} 81 func (NopViewer) HideEntity(Entity) {} 82 func (NopViewer) ViewEntityGameMode(Entity) {} 83 func (NopViewer) ViewEntityMovement(Entity, mgl64.Vec3, cube.Rotation, bool) {} 84 func (NopViewer) ViewEntityVelocity(Entity, mgl64.Vec3) {} 85 func (NopViewer) ViewEntityTeleport(Entity, mgl64.Vec3) {} 86 func (NopViewer) ViewChunk(ChunkPos, *chunk.Chunk, map[cube.Pos]Block) {} 87 func (NopViewer) ViewTime(int) {} 88 func (NopViewer) ViewEntityItems(Entity) {} 89 func (NopViewer) ViewEntityArmour(Entity) {} 90 func (NopViewer) ViewEntityAction(Entity, EntityAction) {} 91 func (NopViewer) ViewEntityState(Entity) {} 92 func (NopViewer) ViewEntityAnimation(Entity, string) {} 93 func (NopViewer) ViewParticle(mgl64.Vec3, Particle) {} 94 func (NopViewer) ViewSound(mgl64.Vec3, Sound) {} 95 func (NopViewer) ViewBlockUpdate(cube.Pos, Block, int) {} 96 func (NopViewer) ViewBlockAction(cube.Pos, BlockAction) {} 97 func (NopViewer) ViewEmote(Entity, uuid.UUID) {} 98 func (NopViewer) ViewSkin(Entity) {} 99 func (NopViewer) ViewWorldSpawn(cube.Pos) {} 100 func (NopViewer) ViewWeather(bool, bool) {} 101 func (NopViewer) ViewFurnaceUpdate(time.Duration, time.Duration, time.Duration, time.Duration, time.Duration, time.Duration) { 102 }