Exemplo n.º 1
0
func parseBlockStateVariant(plugin string, js realjson.RawMessage) *model {
	type jsType struct {
		Model  string
		X, Y   float64
		UVLock bool
		Weight *int
	}
	var data jsType
	err := json.Unmarshal(js, &data)
	if err != nil {
		console.Text("%s", err)
		return nil
	}
	var bdata jsModel
	err = loadJSON(plugin, "models/block/"+data.Model+".json", &bdata)
	if err != nil {
		return nil
	}
	bm := parseModel(plugin, &bdata)

	bm.y = data.Y
	bm.x = data.X
	bm.uvLock = data.UVLock
	if data.Weight != nil {
		bm.weight = *data.Weight
	} else {
		bm.weight = 1
	}
	return bm
}
Exemplo n.º 2
0
Arquivo: model.go Projeto: num5/steven
func parseModelList(key pluginKey, v realjson.RawMessage) *blockVariants {
	models := &blockVariants{}
	switch v[0] {
	case '[':
		var list []realjson.RawMessage
		json.Unmarshal(v, &list)
		for _, vv := range list {
			mdl := parseBlockStateVariant(key.Plugin, vv)
			if mdl != nil {
				models.models = append(models.models, precomputeModel(mdl))
			}
		}
	default:
		mdl := parseBlockStateVariant(key.Plugin, v)
		if mdl != nil {
			models.models = append(models.models, precomputeModel(mdl))
		}
	}
	return models
}
Exemplo n.º 3
0
func loadStateModel(key pluginKey) *blockStateModel {
	type jsType struct {
		Variants map[string]realjson.RawMessage
	}

	var data jsType
	err := loadJSON(key.Plugin, fmt.Sprintf("blockstates/%s.json", key.Name), &data)
	if err != nil {
		console.Text("Error loading state %s: %s", key.Name, err)
		return nil
	}
	bs := &blockStateModel{
		variants: map[string]blockVariants{},
	}
	variants := data.Variants
	for k, v := range variants {
		var models blockVariants
		switch v[0] {
		case '[':
			var list []realjson.RawMessage
			json.Unmarshal(v, &list)
			for _, vv := range list {
				mdl := parseBlockStateVariant(key.Plugin, vv)
				if mdl != nil {
					models = append(models, precomputeModel(mdl))
				}
			}
		default:
			mdl := parseBlockStateVariant(key.Plugin, v)
			if mdl != nil {
				models = append(models, precomputeModel(mdl))
			}
		}
		bs.variants[k] = models
	}
	return bs
}
Exemplo n.º 4
0
func loadJSON(plugin, name string, target interface{}) error {
	r, err := resource.Open(plugin, name)
	if err != nil {
		return err
	}
	defer r.Close()
	err = realjson.NewDecoder(r).Decode(target)
	if err != nil {
		// Take the slow path through our preprocessor.
		// Hopefully this can be removed in later minecraft versions.d, err := ioutil.ReadAll(r)
		r.Close()
		r, err = resource.Open(plugin, name)
		if err != nil {
			return err
		}

		d, err := ioutil.ReadAll(r)
		if err != nil {
			return err
		}
		return json.Unmarshal(d, target)
	}
	return err
}