github.com/df-mc/dragonfly@v0.9.13/server/block/wood.go (about) 1 package block 2 3 import ( 4 "github.com/df-mc/dragonfly/server/block/cube" 5 "github.com/df-mc/dragonfly/server/item" 6 "github.com/df-mc/dragonfly/server/world" 7 "github.com/go-gl/mathgl/mgl64" 8 "time" 9 ) 10 11 // Wood is a block that has the log's "bark" texture on all six sides. It comes in 8 types: oak, spruce, birch, jungle, 12 // acacia, dark oak, crimson, and warped. 13 // Stripped wood is a variant obtained by using an axe on the wood. 14 type Wood struct { 15 solid 16 bass 17 18 // Wood is the type of wood. 19 Wood WoodType 20 // Stripped specifies if the wood is stripped or not. 21 Stripped bool 22 // Axis is the axis which the wood block faces. 23 Axis cube.Axis 24 } 25 26 // FlammabilityInfo ... 27 func (w Wood) FlammabilityInfo() FlammabilityInfo { 28 if !w.Wood.Flammable() { 29 return newFlammabilityInfo(0, 0, false) 30 } 31 return newFlammabilityInfo(5, 5, true) 32 } 33 34 // BreakInfo ... 35 func (w Wood) BreakInfo() BreakInfo { 36 hardness := 2.0 37 if w.Wood == CrimsonWood() || w.Wood == WarpedWood() { 38 hardness = 0.3 39 } 40 return newBreakInfo(hardness, alwaysHarvestable, axeEffective, oneOf(w)) 41 } 42 43 // SmeltInfo ... 44 func (Wood) SmeltInfo() item.SmeltInfo { 45 return newSmeltInfo(item.NewStack(item.Charcoal{}, 1), 0.15) 46 } 47 48 // FuelInfo ... 49 func (Wood) FuelInfo() item.FuelInfo { 50 return newFuelInfo(time.Second * 15) 51 } 52 53 // UseOnBlock ... 54 func (w Wood) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, wo *world.World, user item.User, ctx *item.UseContext) (used bool) { 55 pos, face, used = firstReplaceable(wo, pos, face, w) 56 if !used { 57 return 58 } 59 w.Axis = face.Axis() 60 61 place(wo, pos, w, user, ctx) 62 return placed(ctx) 63 } 64 65 // Strip ... 66 func (w Wood) Strip() (world.Block, bool) { 67 return Wood{Axis: w.Axis, Wood: w.Wood, Stripped: true}, !w.Stripped 68 } 69 70 // EncodeItem ... 71 func (w Wood) EncodeItem() (name string, meta int16) { 72 switch w.Wood { 73 case OakWood(), SpruceWood(), BirchWood(), JungleWood(), AcaciaWood(), DarkOakWood(): 74 if w.Stripped { 75 return "minecraft:wood", int16(8 + w.Wood.Uint8()) 76 } 77 return "minecraft:wood", int16(w.Wood.Uint8()) 78 case CrimsonWood(), WarpedWood(): 79 if w.Stripped { 80 return "minecraft:stripped_" + w.Wood.String() + "_hyphae", 0 81 } 82 return "minecraft:" + w.Wood.String() + "_hyphae", 0 83 default: 84 if w.Stripped { 85 return "minecraft:stripped_" + w.Wood.String() + "_wood", 0 86 } 87 return "minecraft:" + w.Wood.String() + "_wood", 0 88 } 89 } 90 91 // EncodeBlock ... 92 func (w Wood) EncodeBlock() (name string, properties map[string]any) { 93 switch w.Wood { 94 case OakWood(), SpruceWood(), BirchWood(), JungleWood(), AcaciaWood(), DarkOakWood(): 95 return "minecraft:wood", map[string]any{"wood_type": w.Wood.String(), "pillar_axis": w.Axis.String(), "stripped_bit": boolByte(w.Stripped)} 96 case CrimsonWood(), WarpedWood(): 97 if w.Stripped { 98 return "minecraft:stripped_" + w.Wood.String() + "_hyphae", map[string]any{"pillar_axis": w.Axis.String()} 99 } 100 return "minecraft:" + w.Wood.String() + "_hyphae", map[string]any{"pillar_axis": w.Axis.String()} 101 default: 102 if w.Stripped { 103 return "minecraft:stripped_" + w.Wood.String() + "_wood", map[string]any{"pillar_axis": w.Axis.String()} 104 } 105 return "minecraft:" + w.Wood.String() + "_wood", map[string]any{"pillar_axis": w.Axis.String(), "stripped_bit": uint8(0)} 106 } 107 } 108 109 // allWood returns a list of all possible wood states. 110 func allWood() (wood []world.Block) { 111 for _, w := range WoodTypes() { 112 for axis := cube.Axis(0); axis < 3; axis++ { 113 wood = append(wood, Wood{Axis: axis, Stripped: true, Wood: w}) 114 wood = append(wood, Wood{Axis: axis, Stripped: false, Wood: w}) 115 } 116 } 117 return 118 }