func (p *playerModelComponent) SetCurrentItem(item *ItemStack) { if p.heldModel != nil { p.heldModel.Free() } if item == nil { return } mdl := getModel(item.Type.Name()) if mdl == nil { return } var blk Block if bt, ok := item.Type.(*blockItem); ok { blk = bt.block } mode := "thirdperson" var out []*render.StaticVertex if mdl.builtIn == builtInGenerated { out, p.heldMat = genStaticModelFromItem(mdl, blk, mode) } else if mdl.builtIn == builtInFalse { out, p.heldMat = staticModelFromItem(mdl, blk, mode) } p.heldModel = render.NewStaticModel([][]*render.StaticVertex{ out, }) p.heldModel.Radius = 3 }
func (b *blockBreakComponent) Update() { if b.model != nil { b.model.Free() } bounds := chunkMap.Block(b.Location.X, b.Location.Y, b.Location.Z).CollisionBounds() tex := render.GetTexture(fmt.Sprintf("blocks/destroy_stage_%d", b.stage)) var verts []*render.StaticVertex for _, bo := range bounds { // Slightly bigger than the block to prevent clipping bo = bo.Grow(0.01, 0.01, 0.01) verts = appendBox(verts, bo.Min.X(), bo.Min.Y(), bo.Min.Z(), bo.Max.X()-bo.Min.X(), bo.Max.Y()-bo.Min.Y(), bo.Max.Z()-bo.Min.Z(), [6]render.TextureInfo{ tex, tex, tex, tex, tex, tex, }) } b.model = render.NewStaticModel([][]*render.StaticVertex{verts}) b.model.Matrix[0] = mgl32.Translate3D( float32(b.Location.X), -float32(b.Location.Y), float32(b.Location.Z), ) }
func esPlayerModelAdd(p *playerModelComponent, pl PlayerComponent) { uuid := pl.UUID() info := Client.playerList.info[uuid] if info == nil { Client.network.SignalClose(errors.New("missing player info")) return } skin := info.skin p.skin = info.skinHash cape := info.cape p.cape = info.capeHash if p.skin != "" { render.RefSkin(p.skin) } if p.cape != "" { render.RefSkin(p.cape) } var hverts []*render.StaticVertex if p.hasHead { hverts = appendBox(hverts, -4/16.0, 0, -4/16.0, 8/16.0, 8/16.0, 8/16.0, [6]render.TextureInfo{ direction.North: skin.Sub(8, 8, 8, 8), direction.South: skin.Sub(24, 8, 8, 8), direction.East: skin.Sub(0, 8, 8, 8), direction.West: skin.Sub(16, 8, 8, 8), direction.Up: skin.Sub(8, 0, 8, 8), direction.Down: skin.Sub(16, 0, 8, 8), }) hverts = appendBox(hverts, -4.2/16.0, -.2/16.0, -4.2/16.0, 8.4/16.0, 8.4/16.0, 8.4/16.0, [6]render.TextureInfo{ direction.North: skin.Sub(8+32, 8, 8, 8), direction.South: skin.Sub(24+32, 8, 8, 8), direction.East: skin.Sub(0+32, 8, 8, 8), direction.West: skin.Sub(16+32, 8, 8, 8), direction.Up: skin.Sub(8+32, 0, 8, 8), direction.Down: skin.Sub(16+32, 0, 8, 8), }) } var cverts []*render.StaticVertex if p.cape != "" { cverts = appendBox(cverts, -5/16.0, -16/16.0, 0, 10/16.0, 16/16.0, 1/16.0, [6]render.TextureInfo{ direction.North: cape.Sub(11, 1, 10, 16), direction.South: cape.Sub(1, 1, 10, 16), direction.West: cape.Sub(0, 1, 1, 16), direction.East: cape.Sub(21, 1, 1, 16), direction.Up: cape.Sub(1, 0, 10, 1), direction.Down: cape.Sub(11, 0, 10, 1), }) } bverts := appendBox(nil, -4/16.0, -6/16.0, -2/16.0, 8/16.0, 12/16.0, 4/16.0, [6]render.TextureInfo{ direction.North: skin.Sub(20, 20, 8, 12), direction.South: skin.Sub(32, 20, 8, 12), direction.West: skin.Sub(16, 20, 4, 12), direction.East: skin.Sub(28, 20, 4, 12), direction.Up: skin.Sub(20, 16, 8, 4), direction.Down: skin.Sub(28, 16, 8, 4), }) bverts = appendBox(bverts, -4.2/16.0, -6.2/16.0, -2.2/16.0, 8.4/16.0, 12.4/16.0, 4.4/16.0, [6]render.TextureInfo{ direction.North: skin.Sub(20, 20+16, 8, 12), direction.South: skin.Sub(32, 20+16, 8, 12), direction.West: skin.Sub(16, 20+16, 4, 12), direction.East: skin.Sub(28, 20+16, 4, 12), direction.Up: skin.Sub(20, 16+16, 8, 4), direction.Down: skin.Sub(28, 16+16, 8, 4), }) var lverts [4][]*render.StaticVertex for i, off := range [][4]int{ {0, 16, 0, 32}, {16, 48, 0, 48}, {32, 48, 48, 48}, {40, 16, 40, 32}, } { ox, oy := off[0], off[1] lverts[i] = appendBox(nil, -2/16.0, -12/16.0, -2/16.0, 4/16.0, 12/16.0, 4/16.0, [6]render.TextureInfo{ direction.North: skin.Sub(ox+4, oy+4, 4, 12), direction.South: skin.Sub(ox+12, oy+4, 4, 12), direction.West: skin.Sub(ox+0, oy+4, 4, 12), direction.East: skin.Sub(ox+8, oy+4, 4, 12), direction.Up: skin.Sub(ox+4, oy, 4, 4), direction.Down: skin.Sub(ox+8, oy, 4, 4), }) ox, oy = off[2], off[3] lverts[i] = appendBox(lverts[i], -2.2/16.0, -12.2/16.0, -2.2/16.0, 4.4/16.0, 12.4/16.0, 4.4/16.0, [6]render.TextureInfo{ direction.North: skin.Sub(ox+4, oy+4, 4, 12), direction.South: skin.Sub(ox+12, oy+4, 4, 12), direction.West: skin.Sub(ox+0, oy+4, 4, 12), direction.East: skin.Sub(ox+8, oy+4, 4, 12), direction.Up: skin.Sub(ox+4, oy, 4, 4), direction.Down: skin.Sub(ox+8, oy, 4, 4), }) } var nverts []*render.StaticVertex if p.hasNameTag { nverts = createNameTag(info.name) } model := render.NewStaticModel([][]*render.StaticVertex{ playerModelHead: hverts, playerModelBody: bverts, playerModelLegRight: lverts[0], playerModelLegLeft: lverts[1], playerModelArmRight: lverts[2], playerModelArmLeft: lverts[3], playerModelCape: cverts, playerModelNameTag: nverts, }) p.model = model model.Radius = 3 }
func (s *signComponent) create() { const yS = (6.0 / 16.0) / 4.0 const xS = yS / 16.0 var verts []*render.StaticVertex for i, line := range s.lines { if line.Value == nil { continue } format.ConvertLegacy(line) // Hijack ui.Formatted's component parsing to split // up components into ui.Text elements. // TODO(Think) Move this into some common place for // easier reuse in other places? wrap := &format.TextComponent{} wrap.Color = format.Black wrap.Extra = []format.AnyComponent{line} f := ui.NewFormatted(format.Wrap(wrap), 0, 0) offset := 0.0 for _, txt := range f.Text { str := txt.Value() for _, r := range str { tex := render.CharacterTexture(r) if tex == nil { continue } s := render.SizeOfCharacter(r) if r == ' ' { offset += (s + 2) * xS continue } for _, v := range faceVertices[direction.North].verts { vert := &render.StaticVertex{ X: float32(v.X)*float32(s*xS) - float32(offset+s*xS) + float32(f.Width*xS*0.5), Y: float32(v.Y)*yS - yS*float32(i-1), Z: -.6 / 16.0, Texture: tex, TextureX: float64(v.TOffsetX), TextureY: float64(v.TOffsetY), R: byte(txt.R()), G: byte(txt.G()), B: byte(txt.B()), A: 255, } verts = append(verts, vert) } offset += (s + 2) * xS } } } wood := render.GetTexture("blocks/planks_oak") // The backboard verts = appendBoxExtra(verts, -0.5, -4/16.0, -0.5/16.0, 1.0, 8/16.0, 1/16.0, [6]render.TextureInfo{ direction.Up: wood.Sub(0, 0, 16, 2), direction.Down: wood.Sub(0, 0, 16, 2), direction.East: wood.Sub(0, 0, 2, 12), direction.West: wood.Sub(0, 0, 2, 12), direction.North: wood.Sub(0, 4, 16, 12), direction.South: wood.Sub(0, 4, 16, 12), }, [6][2]float64{ direction.Up: {1.5, 1.0}, direction.Down: {1.5, 1.0}, direction.East: {1.0, 1.0}, direction.West: {1.0, 1.0}, direction.North: {1.5, 1.0}, direction.South: {1.5, 1.0}, }) if s.hasStand { // Stand log := render.GetTexture("blocks/log_oak") verts = appendBox(verts, -0.5/16.0, -0.25-9/16.0, -0.5/16.0, 1/16.0, 9/16.0, 1/16.0, [6]render.TextureInfo{ direction.Up: log.Sub(0, 0, 2, 2), direction.Down: log.Sub(0, 0, 2, 2), direction.East: log.Sub(0, 0, 2, 12), direction.West: log.Sub(0, 0, 2, 12), direction.North: log.Sub(0, 0, 2, 12), direction.South: log.Sub(0, 0, 2, 12), }) } s.model = render.NewStaticModel([][]*render.StaticVertex{ verts, }) s.model.Radius = 2 x, y, z := s.position.X, s.position.Y, s.position.Z s.model.X, s.model.Y, s.model.Z = -float32(x)-0.5, -float32(y)-0.5, float32(z)+0.5 s.model.Matrix[0] = mgl32.Translate3D( float32(x)+0.5, -float32(y)-0.5, float32(z)+0.5, ).Mul4(mgl32.Rotate3DY(float32(s.rotation)).Mat4()). Mul4(mgl32.Translate3D(float32(s.ox), float32(-s.oy), float32(s.oz))) }
func (s *skullComponent) create() { var skin render.TextureInfo if s.SkullType == skullPlayer && s.OwnerSkin != nil { skin = s.OwnerSkin } else { switch s.SkullType { case skullPlayer: skin = render.RelativeTexture(render.GetTexture("entity/steve"), 64, 64) case skullZombie: skin = render.RelativeTexture(render.GetTexture("entity/zombie/zombie"), 64, 64) case skullSkeleton: skin = render.RelativeTexture(render.GetTexture("entity/skeleton/skeleton"), 64, 32) case skullWitherSkeleton: skin = render.RelativeTexture(render.GetTexture("entity/skeleton/wither_skeleton"), 64, 32) case skullCreeper: skin = render.RelativeTexture(render.GetTexture("entity/creeper/creeper"), 64, 32) } } var hverts []*render.StaticVertex // Base layer hverts = appendBox(hverts, -4/16.0, 0, -4/16.0, 8/16.0, 8/16.0, 8/16.0, [6]render.TextureInfo{ direction.North: skin.Sub(8, 8, 8, 8), direction.South: skin.Sub(24, 8, 8, 8), direction.East: skin.Sub(0, 8, 8, 8), direction.West: skin.Sub(16, 8, 8, 8), direction.Up: skin.Sub(8, 0, 8, 8), direction.Down: skin.Sub(16, 0, 8, 8), }) // Hat layer hverts = appendBox(hverts, -4.2/16.0, -.2/16.0, -4.2/16.0, 8.4/16.0, 8.4/16.0, 8.4/16.0, [6]render.TextureInfo{ direction.North: skin.Sub(8+32, 8, 8, 8), direction.South: skin.Sub(24+32, 8, 8, 8), direction.East: skin.Sub(0+32, 8, 8, 8), direction.West: skin.Sub(16+32, 8, 8, 8), direction.Up: skin.Sub(8+32, 0, 8, 8), direction.Down: skin.Sub(16+32, 0, 8, 8), }) s.model = render.NewStaticModel([][]*render.StaticVertex{ hverts, }) model := s.model model.Radius = 2 x, y, z := s.position.X, s.position.Y, s.position.Z model.X, model.Y, model.Z = -float32(x)-0.5, -float32(y), float32(z)+0.5 mat := mgl32.Translate3D(float32(x)+0.5, -float32(y), float32(z)+0.5) if s.Facing == direction.Up { mat = mat.Mul4(mgl32.Rotate3DY(-(math.Pi / 8) * float32(s.Rotation)).Mat4()) } else { ang := float32(0) switch s.Facing { case direction.South: ang = math.Pi case direction.East: ang = math.Pi / 2 case direction.West: ang = -math.Pi / 2 } mat = mat.Mul4(mgl32.Rotate3DY(ang).Mat4()) mat = mat.Mul4(mgl32.Translate3D(0, -4/16.0, 4/16.0)) } model.Matrix[0] = mat }