Skip to content

Commit

Permalink
Un-refactored Entity->entity in strings/comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandertv committed Nov 12, 2024
1 parent 1c6aa27 commit aa5ad65
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
10 changes: 5 additions & 5 deletions server/world/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (e *EntityHandle) mustEntity(tx *Tx) Entity {
if ent, ok := e.Entity(tx); ok {
return ent
}
panic("can't load Entity with Tx of different world")
panic("can't load entity with Tx of different world")
}

func (e *EntityHandle) UUID() uuid.UUID {
Expand All @@ -136,7 +136,7 @@ func (e *EntityHandle) ExecWorld(f func(tx *Tx, e Entity)) {
}

func (e *EntityHandle) unsetAndLockWorld(tx *Tx) {
// If the Entity is in a tx created using ExecWorld, e.cond.L will already
// If the entity is in a tx created using ExecWorld, e.cond.L will already
// be locked. Don't try to lock again in that case.
if e.lockedTx.Load() != tx {
e.cond.L.Lock()
Expand All @@ -146,14 +146,14 @@ func (e *EntityHandle) unsetAndLockWorld(tx *Tx) {
}

func (e *EntityHandle) setAndUnlockWorld(w *World, tx *Tx) {
// If the Entity is in a tx created using ExecWorld, e.cond.L will already
// If the entity is in a tx created using ExecWorld, e.cond.L will already
// be locked. Don't try to lock again in that case.
if e.lockedTx.Load() != tx {
e.cond.L.Lock()
defer e.cond.L.Unlock()
}
if e.w != nil {
panic("cannot add Entity to new world before removing from old world")
panic("cannot add entity to new world before removing from old world")
}
e.w = w
e.cond.Signal()
Expand Down Expand Up @@ -269,7 +269,7 @@ func (conf EntityRegistryConfig) New(ent []EntityType) EntityRegistry {
for _, e := range ent {
name := e.EncodeEntity()
if _, ok := m[name]; ok {
panic("cannot register the same Entity (" + name + ") twice")
panic("cannot register the same entity (" + name + ") twice")
}
m[name] = e
}
Expand Down
14 changes: 7 additions & 7 deletions server/world/tick.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (t ticker) tickBlocksRandomly(tx *Tx, loaders []*Loader, tick int64) {
}
// Generally we would want to make sure the block has its block entities, but provided blocks
// with block entities are generally ticked already, we are safe to assume that blocks
// implementing the RandomTicker don't rely on additional block Entity data.
// implementing the RandomTicker don't rely on additional block entity data.
if rid := sub.Layers()[0].At(x, y, z); randomTickBlocks[rid] {
subY := (i + (tx.Range().Min() >> 4)) << 4
randomBlocks = append(randomBlocks, cube.Pos{cx + int(x), subY + int(y), cz + int(z)})
Expand Down Expand Up @@ -206,31 +206,31 @@ func (t ticker) tickEntities(tx *Tx, tick int64) {
}

if lastPos != chunkPos {
// The Entity was stored using an outdated chunk position. We update it and make sure it is ready
// The entity was stored using an outdated chunk position. We update it and make sure it is ready
// for loaders to view it.
tx.World().entities[handle] = chunkPos
c.Entities = append(c.Entities, handle)

var viewers []Viewer

// When changing an Entity's world, then teleporting it immediately, we could end up in a situation
// where the old chunk of the Entity was not loaded. In this case, it should be safe simply to ignore
// the loaders from the old chunk. We can assume they never saw the Entity in the first place.
// When changing an entity's world, then teleporting it immediately, we could end up in a situation
// where the old chunk of the entity was not loaded. In this case, it should be safe simply to ignore
// the loaders from the old chunk. We can assume they never saw the entity in the first place.
if old, ok := tx.World().chunks[lastPos]; ok {
old.Entities = sliceutil.DeleteVal(old.Entities, handle)
viewers = old.viewers
}

for _, viewer := range viewers {
if sliceutil.Index(c.viewers, viewer) == -1 {
// First we hide the Entity from all loaders that were previously viewing it, but no
// First we hide the entity from all loaders that were previously viewing it, but no
// longer are.
viewer.HideEntity(e)
}
}
for _, viewer := range c.viewers {
if sliceutil.Index(viewers, viewer) == -1 {
// Then we show the Entity to all loaders that are now viewing the Entity in the new
// Then we show the entity to all loaders that are now viewing the entity in the new
// chunk.
showEntity(e, viewer)
}
Expand Down
6 changes: 3 additions & 3 deletions server/world/weather.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,16 @@ func (w weather) adjustPositionToEntities(tx *Tx, vec mgl64.Vec3) mgl64.Vec3 {
list := make([]mgl64.Vec3, 0, len(ent)/3)
for _, e := range ent {
if h, ok := e.(interface{ Health() float64 }); ok && h.Health() > 0 {
// Any (living) Entity that is positioned higher than the highest block at its position is eligible to be
// struck by lightning. We first save all Entity positions where this is the case.
// Any (living) entity that is positioned higher than the highest block at its position is eligible to be
// struck by lightning. We first save all entity positions where this is the case.
pos := cube.PosFromVec3(e.Position())
if tx.HighestBlock(pos[0], pos[1]) < pos[2] {
list = append(list, e.Position())
}
}
}
// We then select one of the positions of entities higher than the highest block and adjust the position of the
// lightning to it, so that the Entity is struck directly.
// lightning to it, so that the entity is struck directly.
if len(list) > 0 {
vec = list[w.w.r.Intn(len(list))]
}
Expand Down
12 changes: 6 additions & 6 deletions server/world/world.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (w *World) blockInChunk(c *Column, pos cube.Pos) Block {
}
rid := c.Block(uint8(pos[0]), int16(pos[1]), uint8(pos[2]), 0)
if nbtBlocks[rid] {
// The block was also a block Entity, so we look it up in the map.
// The block was also a block entity, so we look it up in the map.
if b, ok := c.BlockEntities[pos]; ok {
return b
}
Expand Down Expand Up @@ -648,7 +648,7 @@ func (w *World) addEntity(tx *Tx, handle *EntityHandle) Entity {

e := handle.mustEntity(tx)
for _, v := range c.viewers {
// We show the Entity to all viewers currently in the chunk that the Entity is spawned in.
// We show the entity to all viewers currently in the chunk that the entity is spawned in.
showEntity(e, v)
}
w.Handler().HandleEntitySpawn(e)
Expand All @@ -665,7 +665,7 @@ func (w *World) removeEntity(e Entity, tx *Tx) *EntityHandle {
handle := e.Handle()
pos, found := w.entities[handle]
if !found {
// The Entity currently isn't in this world.
// The entity currently isn't in this world.
return nil
}
w.Handler().HandleEntityDespawn(e)
Expand Down Expand Up @@ -702,7 +702,7 @@ func (w *World) entitiesWithin(tx *Tx, box cube.BBox, ignored func(Entity) bool)
continue
}
if box.Vec3Within(handle.data.Pos) {
// The Entity position was within the BBox, so we add it to the slice to return.
// The entity position was within the BBox, so we add it to the slice to return.
entities = append(entities, e)
}
}
Expand Down Expand Up @@ -1213,12 +1213,12 @@ func columnFrom(c *chunk.Column, w *World) *Column {
for _, e := range c.Entities {
eid, ok := e.Data["identifier"].(string)
if !ok {
w.conf.Log.Error("read column: Entity without identifier field", "ID", e.ID)
w.conf.Log.Error("read column: entity without identifier field", "ID", e.ID)
continue
}
t, ok := w.conf.Entities.Lookup(eid)
if !ok {
w.conf.Log.Error("read column: unknown Entity type", "ID", e.ID, "type", eid)
w.conf.Log.Error("read column: unknown entity type", "ID", e.ID, "type", eid)
continue
}
col.Entities = append(col.Entities, entityFromData(t, e.ID, e.Data))
Expand Down

0 comments on commit aa5ad65

Please sign in to comment.