Skip to content

Commit 9a89cfa

Browse files
committed
teamug, pine needle syrup, bush and bush sapling class, blackberry bush created
1 parent 7e7a84d commit 9a89cfa

File tree

13 files changed

+361
-28
lines changed

13 files changed

+361
-28
lines changed

src/render/model/DodoModel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ public override void render(MatrixStack mat, Entity e, float apos, float aspeed,
4949
// set leg movement
5050
float cs = Meth.clamp(aspeed, 0, 1);
5151
float lr = MathF.Sin(apos * 10) * 20f * cs * Meth.phiF;
52-
rightLeg.rotation = new Vector3(lr, 0, 0);
53-
leftLeg.rotation = new Vector3(-lr, 0, 0);
54-
rightfoot.rotation = new Vector3(lr, 0, 0);
55-
leftfoot.rotation = new Vector3(-lr, 0, 0);
52+
rightLeg.rotation = new Vector3(0, 0, lr);
53+
leftLeg.rotation = new Vector3(0, 0, -lr);
54+
//rightfoot.position = new Vector3(0, 0, cs);
55+
//leftfoot.position = new Vector3(0, 0, -cs);
5656

5757

5858

-633 Bytes
Loading
260 Bytes
Loading

src/world/block/Block.data.cs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ public partial class Block {
9696
public static Block PINE_SAPLING;
9797

9898
public static Block PALM_LOG;
99+
public static Block PALM_PLANKS;
100+
public static Block PALM_STAIRS;
101+
public static Block PALM_SLAB;
99102
public static Block PALM_LEAVES;
100103
public static Block PALM_SAPLING;
101104
public static Block BANANAFRUIT;
@@ -181,6 +184,7 @@ public partial class Block {
181184
public static Block MUSHROOM_RED;
182185
public static Block MUSHROOM_GREEN;
183186
public static Block BLACKBERRY_BUSH;
187+
public static Block BLACKBERRY_BUSH_SAPLING;
184188

185189
public static Crop CROP_WHEAT;
186190
public static Block FERN_GREEN;
@@ -827,6 +831,23 @@ public static void preLoad() {
827831
log[PALM_LOG.id] = true;
828832
PALM_LOG.setFlammable(5);
829833

834+
PALM_PLANKS = register("palmPlanks", new Block("Palm Planks"));
835+
PALM_PLANKS.setTex(uv("blocks.png", 18, 2));
836+
renderType[PALM_PLANKS.id] = RenderType.CUBE;
837+
PALM_PLANKS.material(Material.WOOD);
838+
PALM_PLANKS.setFlammable(30);
839+
840+
PALM_STAIRS = register("palmStairs", new Stairs("Palm Stairs"));
841+
PALM_STAIRS.setTex(cubeUVs(18, 2));
842+
PALM_STAIRS.partialBlock();
843+
PALM_STAIRS.material(Material.WOOD);
844+
PALM_STAIRS.setFlammable(30);
845+
846+
PALM_SLAB = register("palmSlab", new Slabs("Palm Slab"));
847+
PALM_SLAB.setTex(cubeUVs(8, 2));
848+
PALM_SLAB.material(Material.WOOD);
849+
PALM_SLAB.setFlammable(30);
850+
830851
PALM_LEAVES = register("palmLeaves", new Leaves("Palm Leaves"));
831852
PALM_LEAVES.setTex(uv("blocks.png", 17, 2));
832853
registerLeafTexture("blocks.png", 17, 2);
@@ -846,8 +867,6 @@ public static void preLoad() {
846867
PALM_SAPLING.setFlammable(60);
847868

848869
BANANAFRUIT = register("bananafruit", new Leaves("Banana"));
849-
//BANANAFRUIT.setTex(grassUVs(16, 7, 17, 7, 18, 7));
850-
//BANANAFRUIT.setModel(BlockModel.makeCube(BANANAFRUIT));
851870
BANANAFRUIT.setTex(crossUVs(17, 7));
852871
BANANAFRUIT.setModel(BlockModel.makeGrass(BANANAFRUIT));
853872
BANANAFRUIT.transparency();
@@ -947,8 +966,7 @@ public static void preLoad() {
947966
MUSHROOM_GREEN.setFlammable(60);
948967
MUSHROOM_GREEN.light(10);
949968

950-
951-
BLACKBERRY_BUSH = register("blackberryBush", new Block("Blackberry Bush"));
969+
BLACKBERRY_BUSH = register("blackberryBush", new Bush("Blackberry Bush"));
952970
BLACKBERRY_BUSH.setTex(crossUVs(19, 8));
953971
BLACKBERRY_BUSH.setModel(BlockModel.makeGrass(BLACKBERRY_BUSH));
954972
BLACKBERRY_BUSH.transparency();
@@ -957,6 +975,15 @@ public static void preLoad() {
957975
BLACKBERRY_BUSH.itemLike();
958976
BLACKBERRY_BUSH.setFlammable(60);
959977

978+
BLACKBERRY_BUSH_SAPLING = register("blackberryBushSapling", new BushSapling("Blackberry Bush Sapling", BLACKBERRY_BUSH));
979+
BLACKBERRY_BUSH_SAPLING.setTex(crossUVs(18, 8));
980+
BLACKBERRY_BUSH_SAPLING.setModel(BlockModel.makeGrass(BLACKBERRY_BUSH_SAPLING));
981+
BLACKBERRY_BUSH_SAPLING.transparency();
982+
BLACKBERRY_BUSH_SAPLING.noCollision();
983+
BLACKBERRY_BUSH_SAPLING.waterTransparent();
984+
BLACKBERRY_BUSH_SAPLING.itemLike();
985+
986+
960987
ICE = register("ice", new Block("Ice"));
961988
ICE.setTex(uv("blocks.png", 16, 0));
962989
renderType[ICE.id] = RenderType.CUBE;

src/world/block/Bush.cs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
using BlockGame.main;
2+
using BlockGame.util;
3+
using BlockGame.world.entity;
4+
using BlockGame.world.item;
5+
6+
namespace BlockGame.world.block;
7+
8+
#pragma warning disable CS8618
9+
public class Bush : Block {
10+
public Item? fruit;
11+
public Item? seed;
12+
13+
public Bush(string name, Item? fruit = null, Item? seed = null) : base(name) {
14+
this.fruit = fruit;
15+
this.seed = seed;
16+
}
17+
18+
protected override void onRegister(int id) {
19+
transparency();
20+
tick();
21+
material(Material.ORGANIC);
22+
setHardness(0.25);
23+
optionalTool[id] = true;
24+
// only broken by a scythe!
25+
tool[id] = ToolType.SCYTHE;
26+
tier[id] = MaterialTier.WOOD;
27+
}
28+
29+
public override bool canPlace(World world, int x, int y, int z, Placement info) {
30+
// bushes can be placed on grass, dirt, or snow grass
31+
if (y <= 0 || !world.inWorld(x, y - 1, z)) {
32+
return false;
33+
}
34+
35+
var below = world.getBlock(x, y - 1, z);
36+
return below == GRASS.id || below == DIRT.id || below == SNOW_GRASS.id;
37+
}
38+
39+
public override void update(World world, int x, int y, int z) {
40+
if (world.inWorld(x, y - 1, z) && world.getBlock(x, y - 1, z) == 0) {
41+
world.setBlock(x, y, z, AIR.id);
42+
}
43+
}
44+
45+
public override void getDrop(List<ItemStack> drops, World world, int x, int y, int z, byte metadata, bool canBreak) {
46+
if (canBreak && seed != null) {
47+
// broken with scythe: drop seeds
48+
drops.Add(new ItemStack(seed, 1, 0));
49+
}
50+
// broken without scythe: nothing
51+
}
52+
53+
public override void scheduledUpdate(World world, int x, int y, int z) {
54+
// bush regrowth: reset harvested flag after cooldown
55+
if (fruit != null) {
56+
var metadata = world.getBlockMetadata(x, y, z);
57+
world.setMetadata(x, y, z, (byte)(metadata & ~1));
58+
}
59+
}
60+
61+
public override bool onUse(World world, int x, int y, int z, Player player) {
62+
// only fruit-bearing bushes can be harvested
63+
if (fruit == null) {
64+
return false;
65+
}
66+
67+
// check if player is holding a scythe
68+
var held = player.inventory.getSelected();
69+
if (held == ItemStack.EMPTY || held.getItem() is not Tool tool || tool.type != ToolType.SCYTHE) {
70+
return false;
71+
}
72+
73+
// check if already harvested (metadata bit 0)
74+
var metadata = world.getBlockMetadata(x, y, z);
75+
if ((metadata & 1) != 0) {
76+
// already harvested, cooldown active
77+
return true;
78+
}
79+
80+
// harvest: give fruit, mark as harvested, schedule regrowth
81+
int fruitCount = Game.random.Next(1, 3);
82+
player.inventory.addItem(new ItemStack(fruit, fruitCount, 0));
83+
84+
// set metadata bit to mark as harvested
85+
world.setMetadata(x, y, z, (byte)(metadata | 1));
86+
87+
// schedule regrowth after full day-night cycle
88+
world.scheduleBlockUpdate(new Molten.Vector3I(x, y, z), World.TICKS_PER_DAY);
89+
90+
// damage scythe
91+
held.damageItem(player, 1);
92+
player.inventory.setStack(player.inventory.selected, held);
93+
94+
return true;
95+
}
96+
}

src/world/block/BushSapling.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using BlockGame.util;
2+
using BlockGame.world.entity;
3+
4+
namespace BlockGame.world.block;
5+
6+
/** small bush that grows into a mature bush */
7+
public class BushSapling : Block {
8+
private readonly Block matureBush;
9+
private const int GROWTH_CHANCE = 20;
10+
11+
public BushSapling(string name, Block matureBush) : base(name) {
12+
this.matureBush = matureBush;
13+
}
14+
15+
protected override void onRegister(int id) {
16+
transparency();
17+
tick(); // enable random ticking
18+
material(Material.ORGANIC);
19+
setHardness(0.1);
20+
noCollision();
21+
itemLike();
22+
}
23+
24+
public override bool canPlace(World world, int x, int y, int z, Placement info) {
25+
// can be placed on grass, dirt, or snow grass
26+
if (y <= 0 || !world.inWorld(x, y - 1, z)) {
27+
return false;
28+
}
29+
30+
var below = world.getBlock(x, y - 1, z);
31+
return below == GRASS.id || below == DIRT.id || below == SNOW_GRASS.id;
32+
}
33+
34+
public override void update(World world, int x, int y, int z) {
35+
// break if no ground below
36+
if (world.inWorld(x, y - 1, z) && world.getBlock(x, y - 1, z) == 0) {
37+
world.setBlock(x, y, z, AIR.id);
38+
}
39+
}
40+
41+
public override void randomUpdate(World world, int x, int y, int z) {
42+
// grow into mature bush with 1/20 chance
43+
if (world.random.Next(GROWTH_CHANCE) == 0) {
44+
world.setBlock(x, y, z, matureBush.id);
45+
// set mature bush metadata to 2 (mature, ready to harvest)
46+
world.setMetadata(x, y, z, 2);
47+
}
48+
}
49+
50+
public override void getDrop(List<ItemStack> drops, World world, int x, int y, int z, byte metadata, bool canBreak) {
51+
// drop the mature bush's seeds when broken
52+
if (matureBush is Bush bush && bush.seed != null && canBreak) {
53+
drops.Add(new ItemStack(bush.seed, 1, 0));
54+
}
55+
}
56+
}

src/world/block/Grass.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ public override void update(World world, int x, int y, int z) {
1212
}
1313

1414
public override void getDrop(List<ItemStack> drops, World world, int x, int y, int z, byte metadata, bool canBreak) {
15-
// 12.5% total drop chance, split 50-50 between wheat and carrot seeds
15+
// 12.5% total seeds drop chance: wheat 40%, carrot 40%, strawberry 20%
1616
if (canBreak && world.random.NextDouble() < 0.125) {
17-
if (world.random.NextDouble() < 0.5) {
17+
var rng = world.random.NextDouble();
18+
if (rng < 0.4) {
1819
drops.Add(new ItemStack(Item.WHEAT_SEEDS, 1, 0));
19-
} else {
20+
} else if (rng < 0.8) {
2021
drops.Add(new ItemStack(Item.CARROT_SEEDS, 1, 0));
22+
} else {
23+
drops.Add(new ItemStack(Item.STRAWBERRY_SEEDS, 1, 0));
2124
}
2225
}
2326
}

src/world/block/Leaves.cs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,36 @@ public override void getDrop(List<ItemStack> drops, World world, int x, int y, i
5252
if (id == MAHOGANY_LEAVES.id && Game.random.Next(15) == 0) {
5353
drops.Add(new ItemStack(MAHOGANY_SAPLING.item, 1, 0));
5454
}
55-
// mahogany: 1 in 10 chance to drop apple
55+
// mahogany: 1 in 10 chance to drop pineapple
5656
if (id == MAHOGANY_LEAVES.id && Game.random.Next(10) == 0) {
5757
drops.Add(new ItemStack(Item.PINEAPPLE, 1, 0));
5858
}
5959

60+
// mahogany: 1 in 10 chance to drop tea seeds
61+
if (id == MAHOGANY_LEAVES.id && Game.random.Next(10) == 0) {
62+
drops.Add(new ItemStack(Item.TEA_SEEDS, 1, 0));
63+
}
64+
6065
// PINE: 1 in 15 chance to drop sapling
6166
if (id == PINE_LEAVES.id && Game.random.Next(15) == 0) {
6267
drops.Add(new ItemStack(PINE_SAPLING.item, 1, 0));
6368
}
6469

65-
// palm: 1 in 10 chance to drop banana
66-
if (id == PALM_LEAVES.id && Game.random.Next(10) == 0) {
67-
drops.Add(new ItemStack(Item.BANANA, 1, 0));
68-
}
69-
// palm: 1 in 15 chance to drop sapling
70+
// palm: 1 in 10 chance to drop sapling
7071
if (id == PALM_LEAVES.id && Game.random.Next(15) == 0) {
7172
drops.Add(new ItemStack(PALM_SAPLING.item, 1, 0));
7273
}
7374

75+
// bananafruit: when broken with scythe, drop 1-2 bananas; without scythe, drop nothing
76+
if (id == BANANAFRUIT.id) {
77+
if (canBreak) {
78+
// broken with scythe: drop 1-2 bananas
79+
drops.Add(new ItemStack(Item.BANANA, Game.random.Next(1, 3), 0));
80+
}
81+
// broken without scythe: nothing
82+
return;
83+
}
84+
7485
if (canBreak) {
7586
drops.Add(new ItemStack(getItem(), 1, 0));
7687
}
@@ -84,6 +95,14 @@ public override void randomUpdate(World world, int x, int y, int z) {
8495
}
8596
}
8697

98+
public override void scheduledUpdate(World world, int x, int y, int z) {
99+
// bananafruit regrowth: reset harvested flag after cooldown
100+
if (id == BANANAFRUIT.id) {
101+
var metadata = world.getBlockMetadata(x, y, z);
102+
world.setMetadata(x, y, z, (byte)(metadata & ~1));
103+
}
104+
}
105+
87106
/** BFS to find if leaf is connected to a log within DECAY_DIST */
88107
private static bool isConnectedToLog(World world, int sx, int sy, int sz) {
89108
queue.Clear();

src/world/block/Sapling.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ public static bool canSurvive(World world, int x, int y, int z) {
151151

152152
return nearest;
153153
}
154+
155+
/*public override void getDrop(List<ItemStack> drops, World world, int x, int y, int z, byte metadata, bool canBreak) {
156+
if (id == BUSH_SAPLING.id) {
157+
return;
158+
}
159+
else {
160+
base.getDrop(drops, world, x, y, z, metadata, canBreak);
161+
}
162+
}*/
154163
}
155164

156165
/** Tree types for saplings */
@@ -160,5 +169,6 @@ public enum SaplingType {
160169
MAHOGANY,
161170
PINE,
162171
PALM,
163-
REDWOOD
172+
REDWOOD,
173+
BUSH
164174
}

0 commit comments

Comments
 (0)