Skip to content

Commit 22cb9c5

Browse files
vdrgdhvanipa
andauthored
Bucket + Tilling (#109)
* Basic bucket and tilling implementation * Add bucket and tilling tests * sync types from client * add recipes --------- Co-authored-by: Dhvani Patel <[email protected]>
1 parent b756946 commit 22cb9c5

17 files changed

+642
-16
lines changed

packages/experience/worlds.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"31337": {
3-
"address": "0x5c7683256E64E7AAB1D9bFF8EFB277A76eABCc76"
3+
"address": "0xFFe5f79996916818e7fAC23516DdB69f36882dCe"
44
}
55
}

packages/world/IWorld.abi.json

+39
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,19 @@
705705
"outputs": [],
706706
"stateMutability": "nonpayable"
707707
},
708+
{
709+
"type": "function",
710+
"name": "fillBucket",
711+
"inputs": [
712+
{
713+
"name": "waterCoord",
714+
"type": "uint96",
715+
"internalType": "Vec3"
716+
}
717+
],
718+
"outputs": [],
719+
"stateMutability": "nonpayable"
720+
},
708721
{
709722
"type": "function",
710723
"name": "getAllRandomSpawnCoords",
@@ -3051,6 +3064,19 @@
30513064
],
30523065
"stateMutability": "view"
30533066
},
3067+
{
3068+
"type": "function",
3069+
"name": "till",
3070+
"inputs": [
3071+
{
3072+
"name": "coord",
3073+
"type": "uint96",
3074+
"internalType": "Vec3"
3075+
}
3076+
],
3077+
"outputs": [],
3078+
"stateMutability": "nonpayable"
3079+
},
30543080
{
30553081
"type": "function",
30563082
"name": "transfer",
@@ -3407,6 +3433,19 @@
34073433
"outputs": [],
34083434
"stateMutability": "nonpayable"
34093435
},
3436+
{
3437+
"type": "function",
3438+
"name": "wetFarmland",
3439+
"inputs": [
3440+
{
3441+
"name": "coord",
3442+
"type": "uint96",
3443+
"internalType": "Vec3"
3444+
}
3445+
],
3446+
"outputs": [],
3447+
"stateMutability": "nonpayable"
3448+
},
34103449
{
34113450
"type": "function",
34123451
"name": "worldVersion",

packages/world/IWorld.abi.json.d.ts

+39
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,19 @@ declare const abi: [
705705
"outputs": [],
706706
"stateMutability": "nonpayable"
707707
},
708+
{
709+
"type": "function",
710+
"name": "fillBucket",
711+
"inputs": [
712+
{
713+
"name": "waterCoord",
714+
"type": "uint96",
715+
"internalType": "Vec3"
716+
}
717+
],
718+
"outputs": [],
719+
"stateMutability": "nonpayable"
720+
},
708721
{
709722
"type": "function",
710723
"name": "getAllRandomSpawnCoords",
@@ -3051,6 +3064,19 @@ declare const abi: [
30513064
],
30523065
"stateMutability": "view"
30533066
},
3067+
{
3068+
"type": "function",
3069+
"name": "till",
3070+
"inputs": [
3071+
{
3072+
"name": "coord",
3073+
"type": "uint96",
3074+
"internalType": "Vec3"
3075+
}
3076+
],
3077+
"outputs": [],
3078+
"stateMutability": "nonpayable"
3079+
},
30543080
{
30553081
"type": "function",
30563082
"name": "transfer",
@@ -3407,6 +3433,19 @@ declare const abi: [
34073433
"outputs": [],
34083434
"stateMutability": "nonpayable"
34093435
},
3436+
{
3437+
"type": "function",
3438+
"name": "wetFarmland",
3439+
"inputs": [
3440+
{
3441+
"name": "coord",
3442+
"type": "uint96",
3443+
"internalType": "Vec3"
3444+
}
3445+
],
3446+
"outputs": [],
3447+
"stateMutability": "nonpayable"
3448+
},
34103449
{
34113450
"type": "function",
34123451
"name": "worldVersion",

packages/world/script/AdminScript.s.sol

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ contract AdminScript is Script {
5656
world.adminAddToInventory(playerEntityId, ObjectTypes.Thermoblaster, 1);
5757
world.adminAddToInventory(playerEntityId, ObjectTypes.SpawnTile, 1);
5858
world.adminAddToInventory(playerEntityId, ObjectTypes.Bed, 1);
59+
world.adminAddToInventory(playerEntityId, ObjectTypes.Bucket, 1);
60+
world.adminAddToInventory(playerEntityId, ObjectTypes.WaterBucket, 1);
61+
world.adminAddToolToInventory(playerEntityId, ObjectTypes.WoodenHoe);
5962
world.adminAddToolToInventory(playerEntityId, ObjectTypes.SilverPick);
6063

6164
vm.stopBroadcast();

packages/world/script/InitObjects.sol

+16
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,10 @@ contract InitObjects {
532532
ObjectTypes.NeptuniumOre,
533533
ObjectTypeMetadataData({ stackable: 99, maxInventorySlots: 0, mass: 100, energy: 0, canPassThrough: false })
534534
);
535+
ObjectTypeMetadata.set(
536+
ObjectTypes.WetFarmland,
537+
ObjectTypeMetadataData({ stackable: 99, maxInventorySlots: 0, mass: 100, energy: 0, canPassThrough: false })
538+
);
535539
ObjectTypeMetadata.set(
536540
ObjectTypes.ForceField,
537541
ObjectTypeMetadataData({ stackable: 99, maxInventorySlots: 0, mass: 100, energy: 0, canPassThrough: false })
@@ -572,6 +576,10 @@ contract InitObjects {
572576
ObjectTypes.WoodenWhacker,
573577
ObjectTypeMetadataData({ stackable: 1, maxInventorySlots: 0, mass: 18750, energy: 0, canPassThrough: false })
574578
);
579+
ObjectTypeMetadata.set(
580+
ObjectTypes.WoodenHoe,
581+
ObjectTypeMetadataData({ stackable: 1, maxInventorySlots: 0, mass: 18750, energy: 0, canPassThrough: false })
582+
);
575583
ObjectTypeMetadata.set(
576584
ObjectTypes.StonePick,
577585
ObjectTypeMetadataData({ stackable: 1, maxInventorySlots: 0, mass: 100000, energy: 0, canPassThrough: false })
@@ -636,6 +644,14 @@ contract InitObjects {
636644
ObjectTypes.NeptuniumBar,
637645
ObjectTypeMetadataData({ stackable: 99, maxInventorySlots: 0, mass: 0, energy: 0, canPassThrough: false })
638646
);
647+
ObjectTypeMetadata.set(
648+
ObjectTypes.Bucket,
649+
ObjectTypeMetadataData({ stackable: 1, maxInventorySlots: 0, mass: 0, energy: 0, canPassThrough: false })
650+
);
651+
ObjectTypeMetadata.set(
652+
ObjectTypes.WaterBucket,
653+
ObjectTypeMetadataData({ stackable: 1, maxInventorySlots: 0, mass: 0, energy: 0, canPassThrough: false })
654+
);
639655
ObjectTypeMetadata.set(
640656
ObjectTypes.ChipBattery,
641657
ObjectTypeMetadataData({ stackable: 99, maxInventorySlots: 0, mass: 0, energy: 0, canPassThrough: false })

packages/world/script/InitRecipes.sol

+60
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,36 @@ contract InitRecipes {
774774
outputAmounts
775775
);
776776
}
777+
{
778+
ObjectTypeId stationObjectTypeId = ObjectTypes.Null;
779+
ObjectTypeId[] memory inputTypes = new ObjectTypeId[](1);
780+
inputTypes[0] = ObjectTypes.AnyLog;
781+
uint16[] memory inputAmounts = new uint16[](1);
782+
inputAmounts[0] = 4;
783+
ObjectTypeId[] memory outputTypes = new ObjectTypeId[](1);
784+
outputTypes[0] = ObjectTypes.WoodenHoe;
785+
uint16[] memory outputAmounts = new uint16[](1);
786+
outputAmounts[0] = 1;
787+
788+
uint16[] memory _inputTypes;
789+
assembly ("memory-safe") {
790+
_inputTypes := inputTypes
791+
}
792+
793+
uint16[] memory _outputTypes;
794+
assembly ("memory-safe") {
795+
_outputTypes := outputTypes
796+
}
797+
798+
Recipes.set(
799+
keccak256(abi.encode(stationObjectTypeId, inputTypes, inputAmounts, outputTypes, outputAmounts)),
800+
stationObjectTypeId,
801+
_inputTypes,
802+
inputAmounts,
803+
_outputTypes,
804+
outputAmounts
805+
);
806+
}
777807
{
778808
ObjectTypeId stationObjectTypeId = ObjectTypes.Workbench;
779809
ObjectTypeId[] memory inputTypes = new ObjectTypeId[](2);
@@ -1147,6 +1177,36 @@ contract InitRecipes {
11471177
_outputTypes := outputTypes
11481178
}
11491179

1180+
Recipes.set(
1181+
keccak256(abi.encode(stationObjectTypeId, inputTypes, inputAmounts, outputTypes, outputAmounts)),
1182+
stationObjectTypeId,
1183+
_inputTypes,
1184+
inputAmounts,
1185+
_outputTypes,
1186+
outputAmounts
1187+
);
1188+
}
1189+
{
1190+
ObjectTypeId stationObjectTypeId = ObjectTypes.Null;
1191+
ObjectTypeId[] memory inputTypes = new ObjectTypeId[](1);
1192+
inputTypes[0] = ObjectTypes.SilverBar;
1193+
uint16[] memory inputAmounts = new uint16[](1);
1194+
inputAmounts[0] = 3;
1195+
ObjectTypeId[] memory outputTypes = new ObjectTypeId[](1);
1196+
outputTypes[0] = ObjectTypes.Bucket;
1197+
uint16[] memory outputAmounts = new uint16[](1);
1198+
outputAmounts[0] = 1;
1199+
1200+
uint16[] memory _inputTypes;
1201+
assembly ("memory-safe") {
1202+
_inputTypes := inputTypes
1203+
}
1204+
1205+
uint16[] memory _outputTypes;
1206+
assembly ("memory-safe") {
1207+
_outputTypes := outputTypes
1208+
}
1209+
11501210
Recipes.set(
11511211
keccak256(abi.encode(stationObjectTypeId, inputTypes, inputAmounts, outputTypes, outputAmounts)),
11521212
stationObjectTypeId,

packages/world/src/Constants.sol

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ uint128 constant PLAYER_CRAFT_ENERGY_COST = 100;
4545
uint128 constant PLAYER_DROP_ENERGY_COST = 100;
4646
uint128 constant PLAYER_PICKUP_ENERGY_COST = 100;
4747
uint128 constant PLAYER_TRANSFER_ENERGY_COST = 100;
48+
uint128 constant PLAYER_TILL_ENERGY_COST = 100;
4849

4950
uint256 constant MAX_COAL = 10_000_000;
5051
uint256 constant MAX_SILVER = 5_000_000;

packages/world/src/ObjectTypeLib.sol

+4
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ library ObjectTypeLib {
9898
objectTypeId == ObjectTypes.SilverWhacker;
9999
}
100100

101+
function isHoe(ObjectTypeId objectTypeId) internal pure returns (bool) {
102+
return objectTypeId == ObjectTypes.WoodenHoe;
103+
}
104+
101105
function isMachine(ObjectTypeId objectTypeId) internal pure returns (bool) {
102106
return objectTypeId == ObjectTypes.ForceField;
103107
}

packages/world/src/ObjectTypes.sol

+18-14
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ library ObjectTypes {
185185
ObjectTypeId constant GoldOre = ObjectTypeId.wrap(Block | 269);
186186
ObjectTypeId constant DiamondOre = ObjectTypeId.wrap(Block | 270);
187187
ObjectTypeId constant NeptuniumOre = ObjectTypeId.wrap(Block | 271);
188+
ObjectTypeId constant WetFarmland = ObjectTypeId.wrap(Block | 272);
188189
ObjectTypeId constant ForceField = ObjectTypeId.wrap(Block | 600);
189190
ObjectTypeId constant Chest = ObjectTypeId.wrap(Block | 601);
190191
ObjectTypeId constant SmartChest = ObjectTypeId.wrap(Block | 602);
@@ -199,18 +200,19 @@ library ObjectTypes {
199200
ObjectTypeId constant WoodenPick = ObjectTypeId.wrap(Tool | 0);
200201
ObjectTypeId constant WoodenAxe = ObjectTypeId.wrap(Tool | 1);
201202
ObjectTypeId constant WoodenWhacker = ObjectTypeId.wrap(Tool | 2);
202-
ObjectTypeId constant StonePick = ObjectTypeId.wrap(Tool | 3);
203-
ObjectTypeId constant StoneAxe = ObjectTypeId.wrap(Tool | 4);
204-
ObjectTypeId constant StoneWhacker = ObjectTypeId.wrap(Tool | 5);
205-
ObjectTypeId constant SilverPick = ObjectTypeId.wrap(Tool | 6);
206-
ObjectTypeId constant SilverAxe = ObjectTypeId.wrap(Tool | 7);
207-
ObjectTypeId constant SilverWhacker = ObjectTypeId.wrap(Tool | 8);
208-
ObjectTypeId constant GoldPick = ObjectTypeId.wrap(Tool | 9);
209-
ObjectTypeId constant GoldAxe = ObjectTypeId.wrap(Tool | 10);
210-
ObjectTypeId constant DiamondPick = ObjectTypeId.wrap(Tool | 11);
211-
ObjectTypeId constant DiamondAxe = ObjectTypeId.wrap(Tool | 12);
212-
ObjectTypeId constant NeptuniumPick = ObjectTypeId.wrap(Tool | 13);
213-
ObjectTypeId constant NeptuniumAxe = ObjectTypeId.wrap(Tool | 14);
203+
ObjectTypeId constant WoodenHoe = ObjectTypeId.wrap(Tool | 3);
204+
ObjectTypeId constant StonePick = ObjectTypeId.wrap(Tool | 4);
205+
ObjectTypeId constant StoneAxe = ObjectTypeId.wrap(Tool | 5);
206+
ObjectTypeId constant StoneWhacker = ObjectTypeId.wrap(Tool | 6);
207+
ObjectTypeId constant SilverPick = ObjectTypeId.wrap(Tool | 7);
208+
ObjectTypeId constant SilverAxe = ObjectTypeId.wrap(Tool | 8);
209+
ObjectTypeId constant SilverWhacker = ObjectTypeId.wrap(Tool | 9);
210+
ObjectTypeId constant GoldPick = ObjectTypeId.wrap(Tool | 10);
211+
ObjectTypeId constant GoldAxe = ObjectTypeId.wrap(Tool | 11);
212+
ObjectTypeId constant DiamondPick = ObjectTypeId.wrap(Tool | 12);
213+
ObjectTypeId constant DiamondAxe = ObjectTypeId.wrap(Tool | 13);
214+
ObjectTypeId constant NeptuniumPick = ObjectTypeId.wrap(Tool | 14);
215+
ObjectTypeId constant NeptuniumAxe = ObjectTypeId.wrap(Tool | 15);
214216

215217
// ------------------------------------------------------------
216218
// Item
@@ -219,8 +221,10 @@ library ObjectTypes {
219221
ObjectTypeId constant SilverBar = ObjectTypeId.wrap(Item | 1);
220222
ObjectTypeId constant Diamond = ObjectTypeId.wrap(Item | 2);
221223
ObjectTypeId constant NeptuniumBar = ObjectTypeId.wrap(Item | 3);
222-
ObjectTypeId constant ChipBattery = ObjectTypeId.wrap(Item | 4);
223-
ObjectTypeId constant Chip = ObjectTypeId.wrap(Item | 5);
224+
ObjectTypeId constant Bucket = ObjectTypeId.wrap(Item | 4);
225+
ObjectTypeId constant WaterBucket = ObjectTypeId.wrap(Item | 5);
226+
ObjectTypeId constant ChipBattery = ObjectTypeId.wrap(Item | 6);
227+
ObjectTypeId constant Chip = ObjectTypeId.wrap(Item | 7);
224228

225229
// ------------------------------------------------------------
226230
// Misc

packages/world/src/codegen/world/IBucketSystem.sol

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/world/src/codegen/world/IFarmingSystem.sol

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/world/src/codegen/world/IWorld.sol

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)