save

package
v1.16.5-pre.0...-185f6e5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 21, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BitStorage

type BitStorage struct {
	// contains filtered or unexported fields
}

BitStorage implement the compacted data array used in chunk storage. https://wiki.vg/Chunk_Format This implement the format since Minecraft 1.16

func NewBitStorage

func NewBitStorage(bits, size int, arrl []uint64) (b *BitStorage)

NewBitStorage create a new BitStorage. bits is the number of bits per value. size is the number of values. arrl is optional data for initializing. It's length must match the bits and size if it's not nil.

func (*BitStorage) Get

func (b *BitStorage) Get(i int) int

Get gets [i] value.

func (*BitStorage) Set

func (b *BitStorage) Set(i, v int)

Set sets v into [i]

func (*BitStorage) Swap

func (b *BitStorage) Swap(i, v int) (old int)

Swap sets v into [i], and return the previous [i] value.

type Block

type Block struct {
	Name       string
	Properties map[string]interface{}
}

type BlockState

type BlockState interface {
}

type Chunk

type Chunk struct {
	Palette     []Block
	Y           byte
	BlockLight  []byte
	BlockStates []int64
	SkyLight    []byte
}

type Column

type Column struct {
	DataVersion int
	Level       struct {
		Heightmaps map[string][]int64
		Structures struct {
			References map[string][]int64
			Starts     map[string]struct {
				ID string `nbt:"id"`
			}
		}
		// Entities
		// LiquidTicks
		// PostProcessing
		Sections []Chunk
		// TileEntities
		// TileTicks
		InhabitedTime int64
		IsLightOn     byte `nbt:"isLightOn"`
		LastUpdate    int64
		Status        string
		PosX          int32 `nbt:"xPos"`
		PosZ          int32 `nbt:"zPos"`
		Biomes        []int32
	}
}

Column is 16* chunk

Example (Send)
r, err := region.Open("/path/to/r.0.0.mca")
if err != nil {
	panic(err)
}
chunkPos := [2]int{0, 0}
data, err := r.ReadSector(chunkPos[0], chunkPos[1])
if err != nil {
	panic(err)
}

var c Column
if err := c.Load(data); err != nil {
	panic(err)
}

var buf bytes.Buffer
var PrimaryBitMask pk.VarInt
for _, v := range c.Level.Sections {
	if int8(v.Y) >= 0 && int8(v.Y) < 16 {
		PrimaryBitMask |= 1 << v.Y

		bpb := len(v.BlockStates) * 64 / (16 * 16 * 16)
		hasPalette := pk.Boolean(bpb >= 9)
		paletteLength := pk.VarInt(len(v.Palette))
		dataArrayLength := pk.VarInt(len(v.BlockStates))
		dataArray := (*[]pk.Long)(unsafe.Pointer(&v.BlockStates))
		_, err := pk.Tuple{
			pk.Short(0),          // Block count
			pk.UnsignedByte(bpb), // Bits Per Block
			hasPalette, pk.Opt{
				Has: &hasPalette,
				Field: pk.Tuple{
					paletteLength, pk.Ary{
						Len: &paletteLength,
						Ary: nil, // TODO: We need translate v.Palette (with type of []Block) to state ID
					},
				},
			}, // Palette
			dataArrayLength, pk.Ary{
				Len: &dataArrayLength,
				Ary: dataArray,
			}, // Data Array
		}.WriteTo(&buf)
		if err != nil {
			panic(err)
		}
	}
}

size := pk.VarInt(buf.Len())
bal := pk.VarInt(len(c.Level.Biomes))
_ = pk.Marshal(
	packetid.WorldParticles,
	pk.Int(chunkPos[0]),        // Chunk X
	pk.Int(chunkPos[1]),        // Chunk Y
	pk.Boolean(true),           // Full chunk
	PrimaryBitMask,             // PrimaryBitMask
	pk.NBT(c.Level.Heightmaps), // Heightmaps
	bal, pk.Ary{
		Len: bal,                                              // Biomes array length
		Ary: *(*[]pk.VarInt)(unsafe.Pointer(&c.Level.Biomes)), // Biomes
	},
	size, pk.Ary{
		Len: size,                      // Size
		Ary: pk.ByteArray(buf.Bytes()), // Data
	},
	pk.VarInt(0), // Block entities array length
)
Output:

func (*Column) Load

func (c *Column) Load(data []byte) (err error)

Load read column data from []byte

type Item

type Item struct {
	Count byte
	Slot  byte
	ID    string                 `nbt:"id"`
	Tag   map[string]interface{} `nbt:"tag"`
}

type Level

type Level struct {
	Data struct {
		DataVersion int32
		NBTVersion  int32 `nbt:"version"`
		Version     struct {
			ID       int32 `nbt:"Id"`
			Name     string
			Snapshot byte
		}
		GameType         int32
		Difficulty       byte
		DifficultyLocked byte
		HardCore         byte `nbt:"hardcore"`
		Initialized      byte `nbt:"initialized"`
		AllowCommands    byte `nbt:"allowCommands"`

		MapFeatures      byte
		LevelName        string
		GeneratorName    string `nbt:"generatorName"`
		GeneratorVersion int32  `nbt:"generatorVersion"`
		RandomSeed       int64

		SpawnX, SpawnY, SpawnZ int32

		BorderCenterX, BorderCenterZ float64
		BorderDamagePerBlock         float64
		BorderSafeZone               float64
		BorderSize                   float64
		BorderSizeLerpTarget         float64
		BorderSizeLerpTime           int64
		BorderWarningBlocks          float64
		BorderWarningTime            float64

		GameRules map[string]string
		DataPacks struct {
			Enabled, Disabled []string
		}
		DimensionData struct {
			TheEnd struct {
				DragonFight struct {
					Gateways         []int32
					DragonKilled     byte
					PreviouslyKilled byte
				}
			} `nbt:"1"`
		}

		Raining          byte  `nbt:"raining"`
		Thundering       byte  `nbt:"thundering"`
		RainTime         int32 `nbt:"rainTime"`
		ThunderTime      int32 `nbt:"thunderTime"`
		ClearWeatherTime int32 `nbt:"clearWeatherTime"`

		Time       int64
		DayTime    int64
		LastPlayed int64
	}
}

func ReadLevel

func ReadLevel(r io.Reader) (data Level, err error)

type PlayerData

type PlayerData struct {
	DataVersion int32

	Dimension    int32
	Pos          [3]float64
	Motion       [3]float64
	Rotation     [2]float32
	FallDistance float32
	FallFlying   byte
	OnGround     byte

	UUID                uuid.UUID `nbt:"-"`
	UUIDLeast, UUIDMost int64

	PlayerGameType  int32 `nbt:"playerGameType"`
	Air             int16
	DeathTime       int16
	Fire            int16
	HurtTime        int16
	Health          float32
	HurtByTimestamp int32
	PortalCooldown  int32

	Invulnerable     byte
	SeenCredits      byte `nbt:"seenCredits"`
	SelectedItemSlot int32
	Score            int32
	AbsorptionAmount float32

	Inventory, EnderItems []Item

	XpLevel int32
	XpP     float32
	XpTotal int32
	XpSeed  int32

	FoodExhaustionLevel float32 `nbt:"foodExhaustionLevel"`
	FoodLevel           int32   `nbt:"foodLevel"`
	FoodSaturationLevel float32 `nbt:"foodSaturationLevel"`
	FoodTickTimer       int32   `nbt:"foodTickTimer"`

	Attributes []struct {
		Base float64
		Name string
	}

	Abilities struct {
		FlySpeed     float32 `nbt:"flySpeed"`
		WalkSpeed    float32 `nbt:"walkSpeed"`
		Flying       byte    `nbt:"flying"`
		InstantBuild byte    `nbt:"instabuild"`
		Invulnerable byte    `nbt:"invulnerable"`
		MayBuild     byte    `nbt:"mayBuild"`
		MayFly       byte    `nbt:"mayfly"`
	} `nbt:"abilities"`

	RecipeBook struct {
		IsFilteringCraftable        byte `nbt:"isFilteringCraftable"`
		IsFurnaceFilteringCraftable byte `nbt:"isFurnaceFilteringCraftable"`
		IsFurnaceGUIOpen            byte `nbt:"isFurnaceGuiOpen"`
		IsGUIOpen                   byte `nbt:"isGuiOpen"`
	} `nbt:"recipeBook"`
}

func ReadPlayerData

func ReadPlayerData(r io.Reader) (data PlayerData, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL