Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement blackstone and deepslate blocks and walls #611

Merged
merged 14 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/blockhash/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (b *hashBuilder) ftype(structName, s string, expr ast.Expr, directives map[
return "uint64(" + s + ".Uint8())", 4
case "CoralType":
return "uint64(" + s + ".Uint8())", 3
case "AnvilType", "SandstoneType", "PrismarineType", "StoneBricksType", "NetherBricksType", "FroglightType", "WallConnectionType":
case "AnvilType", "SandstoneType", "PrismarineType", "StoneBricksType", "NetherBricksType", "FroglightType", "WallConnectionType", "BlackstoneType", "DeepslateType":
return "uint64(" + s + ".Uint8())", 2
case "OreType", "FireType", "GrassType":
return "uint64(" + s + ".Uint8())", 1
Expand Down
49 changes: 49 additions & 0 deletions server/block/blackstone.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package block

import (
"github.com/df-mc/dragonfly/server/item"
"github.com/df-mc/dragonfly/server/world"
"math/rand"
)

// Blackstone is a naturally generating block in the nether that can be used to craft stone tools, brewing stands and
// furnaces. Gilded blackstone also has a 10% chance to drop 2-6 golden nuggets.
type Blackstone struct {
solid
bassDrum

// Type is the type of blackstone of the block.
Type BlackstoneType
}

// BreakInfo ...
func (b Blackstone) BreakInfo() BreakInfo {
drops := oneOf(b)
if b.Type == GildedBlackstone() {
drops = func(item.Tool, []item.Enchantment) []item.Stack {
if rand.Float64() < 0.1 {
return []item.Stack{item.NewStack(item.GoldNugget{}, rand.Intn(4)+2)}
}
return []item.Stack{item.NewStack(b, 1)}
}
}
return newBreakInfo(1.5, pickaxeHarvestable, pickaxeEffective, drops).withBlastResistance(30)
}

// EncodeItem ...
func (b Blackstone) EncodeItem() (name string, meta int16) {
return "minecraft:" + b.Type.String(), 0
}

// EncodeBlock ...
func (b Blackstone) EncodeBlock() (string, map[string]any) {
return "minecraft:" + b.Type.String(), nil
}

// allBlackstone returns a list of all blackstone block variants.
func allBlackstone() (s []world.Block) {
for _, t := range BlackstoneTypes() {
s = append(s, Blackstone{Type: t})
}
return
}
68 changes: 68 additions & 0 deletions server/block/blackstone_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package block

// BlackstoneType represents a type of blackstone.
type BlackstoneType struct {
blackstone
}

type blackstone uint8

// NormalBlackstone is the normal variant of blackstone.
func NormalBlackstone() BlackstoneType {
return BlackstoneType{0}
}

// GildedBlackstone is the gilded variant of blackstone.
func GildedBlackstone() BlackstoneType {
return BlackstoneType{1}
}

// PolishedBlackstone is the polished variant of blackstone.
func PolishedBlackstone() BlackstoneType {
return BlackstoneType{2}
}

// ChiseledPolishedBlackstone is the chiseled polished variant of blackstone.
func ChiseledPolishedBlackstone() BlackstoneType {
return BlackstoneType{3}
}

// Uint8 returns the blackstone type as a uint8.
func (s blackstone) Uint8() uint8 {
return uint8(s)
}

// Name ...
func (s blackstone) Name() string {
switch s {
case 0:
return "Blackstone"
case 1:
return "Gilded Blackstone"
case 2:
return "Polished Blackstone"
case 3:
return "Chiseled Polished Blackstone"
}
panic("unknown blackstone type")
}

// String ...
func (s blackstone) String() string {
switch s {
case 0:
return "blackstone"
case 1:
return "gilded_blackstone"
case 2:
return "polished_blackstone"
case 3:
return "chiseled_polished_blackstone"
}
panic("unknown blackstone type")
}

// BlackstoneTypes ...
func BlackstoneTypes() []BlackstoneType {
return []BlackstoneType{NormalBlackstone(), GildedBlackstone(), PolishedBlackstone(), ChiseledPolishedBlackstone()}
}
71 changes: 71 additions & 0 deletions server/block/deepslate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package block

import (
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/item"
"github.com/df-mc/dragonfly/server/world"
"github.com/go-gl/mathgl/mgl64"
)

// Deepslate is similar to stone but is naturally found deep underground around Y0 and below, and is harder to break.
type Deepslate struct {
solid
bassDrum

// Type is the type of deepslate of the block.
Type DeepslateType
// Axis is the axis which the deepslate faces.
Axis cube.Axis
}

TwistedAsylumMC marked this conversation as resolved.
Show resolved Hide resolved
// BreakInfo ...
func (d Deepslate) BreakInfo() BreakInfo {
hardness := 3.5
if d.Type == NormalDeepslate() {
hardness = 3
}
return newBreakInfo(hardness, pickaxeHarvestable, pickaxeEffective, oneOf(d)).withBlastResistance(18)
}

// SmeltInfo ...
func (d Deepslate) SmeltInfo() item.SmeltInfo {
if d.Type == CobbledDeepslate() {
return newSmeltInfo(item.NewStack(Deepslate{}, 1), 0.1)
}
return item.SmeltInfo{}
}

// UseOnBlock ...
func (d Deepslate) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.World, user item.User, ctx *item.UseContext) (used bool) {
pos, face, used = firstReplaceable(w, pos, face, d)
if !used {
return
}
if d.Type == NormalDeepslate() {
d.Axis = face.Axis()
}

place(w, pos, d, user, ctx)
return placed(ctx)
}

// EncodeItem ...
func (d Deepslate) EncodeItem() (name string, meta int16) {
return "minecraft:" + d.Type.String(), 0
}

// EncodeBlock ...
func (d Deepslate) EncodeBlock() (string, map[string]any) {
if d.Type == NormalDeepslate() {
return "minecraft:deepslate", map[string]any{"pillar_axis": d.Axis.String()}
}
return "minecraft:" + d.Type.String(), nil
}

// allDeepslate returns a list of all deepslate block variants.
func allDeepslate() (s []world.Block) {
for _, t := range DeepslateTypes() {
s = append(s, Deepslate{Type: t})
}
return
}
41 changes: 41 additions & 0 deletions server/block/deepslate_bricks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package block

import "github.com/df-mc/dragonfly/server/item"

// DeepslateBricks are a brick variant of deepslate and can spawn in ancient cities.
type DeepslateBricks struct {
solid
bassDrum

// Cracked specifies if the deepslate bricks is its cracked variant.
Cracked bool
}

TwistedAsylumMC marked this conversation as resolved.
Show resolved Hide resolved
// BreakInfo ...
func (d DeepslateBricks) BreakInfo() BreakInfo {
return newBreakInfo(3.5, pickaxeHarvestable, pickaxeEffective, oneOf(d)).withBlastResistance(18)
}

// SmeltInfo ...
func (d DeepslateBricks) SmeltInfo() item.SmeltInfo {
if d.Cracked {
return item.SmeltInfo{}
}
return newSmeltInfo(item.NewStack(DeepslateBricks{Cracked: true}, 1), 0.1)
}

// EncodeItem ...
func (d DeepslateBricks) EncodeItem() (name string, meta int16) {
if d.Cracked {
return "minecraft:cracked_deepslate_bricks", 0
}
return "minecraft:deepslate_bricks", 0
}

// EncodeBlock ...
func (d DeepslateBricks) EncodeBlock() (string, map[string]any) {
if d.Cracked {
return "minecraft:cracked_deepslate_bricks", nil
}
return "minecraft:deepslate_bricks", nil
}
41 changes: 41 additions & 0 deletions server/block/deepslate_tiles.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package block

import "github.com/df-mc/dragonfly/server/item"

// DeepslateTiles are a tiled variant of deepslate and can spawn in ancient cities.
type DeepslateTiles struct {
solid
bassDrum

// Cracked specifies if the deepslate tiles is its cracked variant.
Cracked bool
}

TwistedAsylumMC marked this conversation as resolved.
Show resolved Hide resolved
// BreakInfo ...
func (d DeepslateTiles) BreakInfo() BreakInfo {
return newBreakInfo(3.5, pickaxeHarvestable, pickaxeEffective, oneOf(d)).withBlastResistance(18)
}

// SmeltInfo ...
func (d DeepslateTiles) SmeltInfo() item.SmeltInfo {
if d.Cracked {
return item.SmeltInfo{}
}
return newSmeltInfo(item.NewStack(DeepslateTiles{Cracked: true}, 1), 0.1)
}

// EncodeItem ...
func (d DeepslateTiles) EncodeItem() (name string, meta int16) {
if d.Cracked {
return "minecraft:cracked_deepslate_tiles", 0
}
return "minecraft:deepslate_tiles", 0
}

// EncodeBlock ...
func (d DeepslateTiles) EncodeBlock() (string, map[string]any) {
if d.Cracked {
return "minecraft:cracked_deepslate_tiles", nil
}
return "minecraft:deepslate_tiles", nil
}
68 changes: 68 additions & 0 deletions server/block/deepslate_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package block

// DeepslateType represents a type of deepslate.
type DeepslateType struct {
deepslate
}

type deepslate uint8

// NormalDeepslate is the normal variant of deepslate.
func NormalDeepslate() DeepslateType {
return DeepslateType{0}
}

// CobbledDeepslate is the cobbled variant of deepslate.
func CobbledDeepslate() DeepslateType {
return DeepslateType{1}
}

// PolishedDeepslate is the polished variant of deepslate.
func PolishedDeepslate() DeepslateType {
return DeepslateType{2}
}

// ChiseledDeepslate is the chiseled variant of deepslate.
func ChiseledDeepslate() DeepslateType {
return DeepslateType{3}
}

// Uint8 returns the deepslate type as a uint8.
func (s deepslate) Uint8() uint8 {
return uint8(s)
}

// Name ...
func (s deepslate) Name() string {
switch s {
case 0:
return "Deepslate"
case 1:
return "Cobbled Deepslate"
case 2:
return "Polished Deepslate"
case 3:
return "Chiseled Deepslate"
}
panic("unknown deepslate type")
}

// String ...
func (s deepslate) String() string {
switch s {
case 0:
return "deepslate"
case 1:
return "cobbled_deepslate"
case 2:
return "polished_deepslate"
case 3:
return "chiseled_deepslate"
}
panic("unknown deepslate type")
}

// DeepslateTypes ...
func DeepslateTypes() []DeepslateType {
return []DeepslateType{NormalDeepslate(), CobbledDeepslate(), PolishedDeepslate(), ChiseledDeepslate()}
}
31 changes: 0 additions & 31 deletions server/block/gilded_blackstone.go

This file was deleted.