github.com/df-mc/dragonfly@v0.9.13/server/block/stairs.go (about) 1 package block 2 3 import ( 4 "github.com/df-mc/dragonfly/server/block/cube" 5 "github.com/df-mc/dragonfly/server/block/model" 6 "github.com/df-mc/dragonfly/server/item" 7 "github.com/df-mc/dragonfly/server/world" 8 "github.com/df-mc/dragonfly/server/world/sound" 9 "github.com/go-gl/mathgl/mgl64" 10 "time" 11 ) 12 13 // Stairs are blocks that allow entities to walk up blocks without jumping. 14 type Stairs struct { 15 transparent 16 sourceWaterDisplacer 17 18 // Block is the block to use for the type of stair. 19 Block world.Block 20 // UpsideDown specifies if the stairs are upside down. If set to true, the full side is at the top part 21 // of the block. 22 UpsideDown bool 23 // Facing is the direction that the full side of the stairs is facing. 24 Facing cube.Direction 25 } 26 27 // UseOnBlock handles the directional placing of stairs and makes sure they are properly placed upside down 28 // when needed. 29 func (s Stairs) UseOnBlock(pos cube.Pos, face cube.Face, clickPos mgl64.Vec3, w *world.World, user item.User, ctx *item.UseContext) (used bool) { 30 pos, face, used = firstReplaceable(w, pos, face, s) 31 if !used { 32 return 33 } 34 s.Facing = user.Rotation().Direction() 35 if face == cube.FaceDown || (clickPos[1] > 0.5 && face != cube.FaceUp) { 36 s.UpsideDown = true 37 } 38 39 place(w, pos, s, user, ctx) 40 return placed(ctx) 41 } 42 43 // Model ... 44 func (s Stairs) Model() world.BlockModel { 45 return model.Stair{Facing: s.Facing, UpsideDown: s.UpsideDown} 46 } 47 48 // BreakInfo ... 49 func (s Stairs) BreakInfo() BreakInfo { 50 hardness, blastResistance, harvestable, effective := 2.0, 30.0, pickaxeHarvestable, pickaxeEffective 51 52 switch block := s.Block.(type) { 53 // TODO: Copper 54 // TODO: Blackstone 55 // TODO: Deepslate 56 case Planks: 57 harvestable = alwaysHarvestable 58 effective = axeEffective 59 blastResistance = 15.0 60 case Prismarine: 61 hardness = 1.5 62 case Purpur: 63 hardness = 1.5 64 case Quartz: 65 hardness = 0.8 66 blastResistance = 4 67 case Sandstone: 68 if block.Type != SmoothSandstone() { 69 hardness = 0.8 70 blastResistance = 4 71 } 72 case Stone: 73 hardness = 1.5 74 case StoneBricks: 75 if block.Type == NormalStoneBricks() { 76 hardness = 1.5 77 } 78 } 79 return newBreakInfo(hardness, harvestable, effective, oneOf(s)).withBlastResistance(blastResistance) 80 } 81 82 // Instrument ... 83 func (s Stairs) Instrument() sound.Instrument { 84 if _, ok := s.Block.(Planks); ok { 85 return sound.Bass() 86 } 87 return sound.BassDrum() 88 } 89 90 // FlammabilityInfo ... 91 func (s Stairs) FlammabilityInfo() FlammabilityInfo { 92 if w, ok := s.Block.(Planks); ok && w.Wood.Flammable() { 93 return newFlammabilityInfo(5, 20, true) 94 } 95 return newFlammabilityInfo(0, 0, false) 96 } 97 98 // FuelInfo ... 99 func (s Stairs) FuelInfo() item.FuelInfo { 100 if w, ok := s.Block.(Planks); ok && w.Wood.Flammable() { 101 return newFuelInfo(time.Second * 15) 102 } 103 return item.FuelInfo{} 104 } 105 106 // EncodeItem ... 107 func (s Stairs) EncodeItem() (name string, meta int16) { 108 return "minecraft:" + encodeStairsBlock(s.Block) + "_stairs", 0 109 } 110 111 // EncodeBlock ... 112 func (s Stairs) EncodeBlock() (name string, properties map[string]any) { 113 return "minecraft:" + encodeStairsBlock(s.Block) + "_stairs", map[string]any{"upside_down_bit": s.UpsideDown, "weirdo_direction": toStairsDirection(s.Facing)} 114 } 115 116 // toStairDirection converts a facing to a stair's direction for Minecraft. 117 func toStairsDirection(v cube.Direction) int32 { 118 return int32(3 - v) 119 } 120 121 // SideClosed ... 122 func (s Stairs) SideClosed(pos, side cube.Pos, w *world.World) bool { 123 return s.Model().FaceSolid(pos, pos.Face(side), w) 124 } 125 126 // allStairs returns all states of stairs. 127 func allStairs() (stairs []world.Block) { 128 f := func(facing cube.Direction, upsideDown bool) { 129 for _, s := range StairsBlocks() { 130 stairs = append(stairs, Stairs{Facing: facing, UpsideDown: upsideDown, Block: s}) 131 } 132 } 133 for i := cube.Direction(0); i <= 3; i++ { 134 f(i, true) 135 f(i, false) 136 } 137 return 138 }