Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

World stop sending chunks #718

Closed
ItsZodiaX opened this issue Dec 22, 2022 · 4 comments
Closed

World stop sending chunks #718

ItsZodiaX opened this issue Dec 22, 2022 · 4 comments

Comments

@ItsZodiaX
Copy link
Contributor

After around 5 minutes from when the server started the worlds that got created by world.Config{}.New() doesn't send the right chunks (or just an empty chunk), if there's a player staying on that world it won't break and while the others will.

Heres a vid of me from starting the server, joining every worlds to make sure they're actually loaded correctly and not doing anything and just running around in the hub.

Code to create the world.

w := world.Config{
	Dim:      world.Overworld,
	ReadOnly: true,
	Entities: entity.DefaultRegistry,
}.New()

w.SetTickRange(0)
w.SetTime(6000)
w.StopTime()

w.StopWeatherCycle()
w.StopThundering()
w.StopRaining()
w.SetDefaultGameMode(world.GameModeSurvival)
w.SetDifficulty(world.DifficultyNormal)
w.Handle(worlds.NewHandler(false))

// package worlds
// Handler handles world events.
type Handler struct {
	world.NopHandler

	// liquid is true if the world allows liquid flowing.
	liquid bool
}

// NewHandler returns a new world handler.
func NewHandler(liquid bool) *Handler {
	return &Handler{liquid: liquid}
}

// HandleEntitySpawn ...
func (h *Handler) HandleEntitySpawn(e world.Entity) {
	switch en := e.(type) {
	case *entity.EnderPearl:
		en.Handle(&handler.PearlHandler{})
	case *entity.Fireball:
		en.Handle(&handler.FireballHandler{})
	case *entity.TNT:
		en.Handle(&handler.TNTHandler{})
	case *entity.Arrow:
		if p, ok := en.Owner().(*player.Player); ok {
			m, _ := p.HeldItems()
			if t, ok := m.Value("cooldown_release"); ok {
				if s, ok := user.SessionFromPlayer(p); ok {
					if s.HandleItemCooldown(t.(int)) {
						_ = e.Close()
					}
				}
			}
		}
	}
}

// HandleLiquidFlow ...
func (h *Handler) HandleLiquidFlow(ctx *event.Context, _, _ cube.Pos, liquid world.Liquid, _ world.Block) {
	if !h.liquid {
		ctx.Cancel()
		return
	}
	if water, ok := liquid.(block.Water); ok {
		if water.Depth == 8 && water.Still == true {
			ctx.Cancel()
		}
	}
}

// HandleLiquidDecay ...
func (h *Handler) HandleLiquidDecay(ctx *event.Context, _ cube.Pos, _, _ world.Liquid) {
	if !h.liquid {
		ctx.Cancel()
	}
}

// HandleLiquidHarden ...
func (h *Handler) HandleLiquidHarden(ctx *event.Context, _ cube.Pos, _, _, _ world.Block) {
	if !h.liquid {
		ctx.Cancel()
	}
}

// HandleSound ...
func (h *Handler) HandleSound(ctx *event.Context, s world.Sound, _ mgl64.Vec3) {
	if _, ok := s.(sound.Attack); ok {
		ctx.Cancel()
	}
}

// HandleFireSpread ...
func (h *Handler) HandleFireSpread(ctx *event.Context, _ cube.Pos, _ cube.Pos) {
	ctx.Cancel()
}

// HandleBlockBurn ...
func (h *Handler) HandleBlockBurn(ctx *event.Context, _ cube.Pos) {
	ctx.Cancel()
}
@ItsZodiaX
Copy link
Contributor Author

Before this happened my server was loading the worlds from disk and this bug didn't occur.

@ItsZodiaX
Copy link
Contributor Author

The structure on each worlds was created using *World.BuildStructure() after the world variable was created on start up.

@ItsZodiaX
Copy link
Contributor Author

I assume that ok here is false after 5 minutes because of this clear chunk cache every 5 minutes. So when i try to join the world after 5 minutes (chunk cache got cleared), df trying to load chunk here which world provider being NopProvider (as my world config). So it just calling provider.LoadChunk() which returning nil. That's why chunks were fine on first 5 minutes because *World.BuildStructure() load chunks into cache.

@ItsZodiaX
Copy link
Contributor Author

Only if there is a way to lock chunks from clearing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants