Skip to content

Commit

Permalink
tag stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
oq-x committed Aug 13, 2024
1 parent 20c9dfd commit 651e65b
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 28 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ zeppelin-mem-profile
zeppelin.exe
/zeppelin
/world_old
server.properties
server.properties
/q
data.qfg
5 changes: 2 additions & 3 deletions net/io/compress/gzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/4kills/go-libdeflate/v2"
"github.com/zeppelinmc/zeppelin/net/io/buffers"
"github.com/zeppelinmc/zeppelin/net/io/util"
)

// Decompress gunzip. The data returned is only safe to use until the next operation
Expand All @@ -18,7 +17,7 @@ func DecompressGzip(data io.Reader, compressedLength int, decompressedLength *in
compressedBuffer.Grow(compressedLength)
}

if _, err := compressedBuffer.ReadFrom(util.NewReaderMaxxer(data, compressedLength)); err != nil {
if _, err := data.Read(compressedBuffer.Bytes()[:compressedLength]); err != nil {
return nil, err
}

Expand Down Expand Up @@ -53,7 +52,7 @@ func CompressGzip(decompressedData io.Reader, decompressedLength int, compressed
decompressedBuffer.Grow(decompressedLength)
}

if _, err := decompressedBuffer.ReadFrom(util.NewReaderMaxxer(decompressedData, decompressedLength)); err != nil {
if _, err := decompressedData.Read(decompressedBuffer.Bytes()[:decompressedLength]); err != nil {
return nil, err
}

Expand Down
5 changes: 2 additions & 3 deletions net/io/compress/zlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/4kills/go-libdeflate/v2"
"github.com/zeppelinmc/zeppelin/net/io/buffers"
"github.com/zeppelinmc/zeppelin/net/io/util"
)

// Decompress zlib. If decompressedLength is provided, the data returned will only be safe to use until the next operation
Expand All @@ -19,7 +18,7 @@ func DecompressZlib(data io.Reader, compressedLength int, decompressedLength *in
compressedBuffer.Grow(compressedLength)
}

if _, err := compressedBuffer.ReadFrom(util.NewReaderMaxxer(data, compressedLength)); err != nil {
if _, err := data.Read(compressedBuffer.Bytes()[:compressedLength]); err != nil {
return nil, err
}

Expand Down Expand Up @@ -54,7 +53,7 @@ func CompressZlib(decompressedData io.Reader, decompressedLength int, compressed
decompressedBuffer.Grow(decompressedLength)
}

if _, err := decompressedBuffer.ReadFrom(util.NewReaderMaxxer(decompressedData, decompressedLength)); err != nil {
if _, err := decompressedData.Read(decompressedBuffer.Bytes()[:decompressedLength]); err != nil {
return nil, err
}

Expand Down
36 changes: 35 additions & 1 deletion net/packet/play/updateTags.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,39 @@ func (u *UpdateTags) Encode(w io.Writer) error {
}

func (u *UpdateTags) Decode(r io.Reader) error {
return nil //TODO
var length int32
if _, err := r.VarInt(&length); err != nil {
return err
}
u.Tags = make(map[string]map[string][]int32, length)

for i := int32(0); i < length; i++ {
var registry string
if err := r.String(&registry); err != nil {
return err
}
var length int32
if _, err := r.VarInt(&length); err != nil {
return err
}

u.Tags[registry] = make(map[string][]int32, length)
for i := int32(0); i < length; i++ {
var tagName string
if err := r.String(&tagName); err != nil {
return err
}
var count int32
if _, err := r.VarInt(&count); err != nil {
return err
}
u.Tags[registry][tagName] = make([]int32, count)
for i := int32(0); i < count; i++ {
if _, err := r.VarInt(&u.Tags[registry][tagName][i]); err != nil {
return err
}
}
}
}
return nil
}
10 changes: 10 additions & 0 deletions server/session/std/handler/useItemOn.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package handler

import (
"math"
"slices"

"github.com/zeppelinmc/zeppelin/net"
"github.com/zeppelinmc/zeppelin/net/metadata"
"github.com/zeppelinmc/zeppelin/net/packet"
"github.com/zeppelinmc/zeppelin/net/packet/play"
"github.com/zeppelinmc/zeppelin/server/registry"
"github.com/zeppelinmc/zeppelin/server/session/std"
"github.com/zeppelinmc/zeppelin/server/world/block"
"github.com/zeppelinmc/zeppelin/server/world/block/pos"
Expand Down Expand Up @@ -53,6 +55,8 @@ func handleUseItemOn(s *std.StandardSession, pk packet.Packet) {
return
}

currentBlockName, _ := b.Encode()

var blockX, blockY, blockZ = use.BlockX, use.BlockY, use.BlockZ
yaw, _ := s.Player().Rotation()

Expand Down Expand Up @@ -80,6 +84,12 @@ func handleUseItemOn(s *std.StandardSession, pk packet.Packet) {
axis, facing = "x", "east"
}

replaceable := slices.Index(std.Tags.Tags["minecraft:block"]["minecraft:replaceable"], registry.Block.Get(currentBlockName)) != -1

if replaceable {
blockX, blockY, blockZ = use.BlockX, use.BlockY, use.BlockZ
}

currentBlock, err := dimension.Block(blockX, blockY, blockZ)
if err == nil {
name, _ := currentBlock.Encode()
Expand Down
5 changes: 3 additions & 2 deletions server/session/std/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,12 @@ func (session *StandardSession) Configure() error {
session.registryIndexes[packet.RegistryId] = slices.Clone(packet.Indexes)
}
configuration.RegistryPacketsMutex.Unlock()
if err := session.WritePacket(updateTags); err != nil {

if err := session.WritePacket(configuration.FinishConfiguration{}); err != nil {
return err
}

if err := session.WritePacket(configuration.FinishConfiguration{}); err != nil {
if err := session.WritePacket(Tags); err != nil {
return err
}
return nil
Expand Down
Binary file removed server/session/std/tags.bin
Binary file not shown.
13 changes: 2 additions & 11 deletions server/session/std/tags.go

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion server/world/chunk/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ func (chunk *Chunk) Encode(biomeIndexes []string) *play.ChunkDataUpdateLight {
case blockBitsPerEntry == 0:
stateId, _ := section.BlockStateId(blockPalette[0])
w.VarInt(stateId)

case blockBitsPerEntry >= 4 && blockBitsPerEntry <= 8:
w.VarInt(int32(len(blockPalette)))
for _, e := range blockPalette {
Expand Down
12 changes: 6 additions & 6 deletions server/world/level/region/region_dec.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package region

import (
"bufio"
"bytes"
"fmt"
"io"
Expand Down Expand Up @@ -119,7 +118,7 @@ func (r *File) GetChunk(x, z int32) (*chunk.Chunk, error) {
return nil, fmt.Errorf("chunk %d %d not found", x, z)
}

var rawReader = bufio.NewReader(util.NewReaderAtMaxxer(r.reader, int(length), int64(offset)+5))
var rawReader = util.NewReaderAtMaxxer(r.reader, int(length), int64(offset)+5)

var data []byte

Expand All @@ -143,10 +142,11 @@ func (r *File) GetChunk(x, z int32) (*chunk.Chunk, error) {
return nil, fmt.Errorf("invalid compression method %d", compression)
}

var anvil = anvilChunks.Get().(*anvilChunk)
defer anvilChunks.Put(anvil)
//var anvil = anvilChunks.Get().(*anvilChunk)
//defer anvilChunks.Put(anvil)
var anvil anvilChunk

if err := nbt.Unmarshal(data, anvil); err != nil {
if err := nbt.Unmarshal(data, &anvil); err != nil {
return nil, err
}

Expand Down Expand Up @@ -174,7 +174,7 @@ func (r *File) GetChunk(x, z int32) (*chunk.Chunk, error) {
blocks[i] = b
}

r.chunks[hash].Sections[i] = section.New(sec.Y, blocks, slices.Clone(sec.BlockStates.Data), sec.Biomes.Palette, slices.Clone(sec.Biomes.Data), *(*[]byte)(unsafe.Pointer(&sec.SkyLight)), *(*[]byte)(unsafe.Pointer(&sec.BlockLight)))
r.chunks[hash].Sections[i] = section.New(sec.Y, blocks, sec.BlockStates.Data, sec.Biomes.Palette, sec.Biomes.Data, *(*[]byte)(unsafe.Pointer(&sec.SkyLight)), *(*[]byte)(unsafe.Pointer(&sec.BlockLight)))
}
if emptySections == len(r.chunks[hash].Sections) && r.generateEmpty && r.generator != nil {
r.chunks[hash] = new(chunk.Chunk)
Expand Down

0 comments on commit 651e65b

Please sign in to comment.