forked from latticexyz/opcraft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
759668f
commit ea632ae
Showing
32 changed files
with
646 additions
and
571 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npx lint-staged | ||
# npx lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
mod components; | ||
mod models; | ||
mod systems; | ||
mod alias; | ||
mod prototypes; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ages/contracts/src/components/claim.cairo → packages/contracts/src/models/claim.cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ges/contracts/src/components/config.cairo → packages/contracts/src/models/config.cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/contracts/src/components/item.cairo → packages/contracts/src/models/item.cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/contracts/src/components/name.cairo → packages/contracts/src/models/name.cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...s/contracts/src/components/owned_by.cairo → packages/contracts/src/models/owned_by.cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ges/contracts/src/components/recipe.cairo → packages/contracts/src/models/recipe.cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ages/contracts/src/components/stake.cairo → packages/contracts/src/models/stake.cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
mod build; | ||
mod claim; | ||
mod stake; | ||
mod initialization; | ||
mod minecraft; | ||
mod name; | ||
mod occurrence; | ||
mod transfer; | ||
mod mine; | ||
mod init; | ||
mod init2; | ||
mod creative_build; | ||
mod craft; | ||
mod bulk_transfer; | ||
mod bulk_stake; | ||
mod stake; | ||
mod transfer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,121 @@ | ||
#[system] | ||
mod Build { | ||
#[dojo::contract] | ||
mod build_systems { | ||
use comcraft::alias::ID; | ||
use comcraft::components::position::{Position, PositionOccupation, VoxelCoord, VoxelCoordTrait}; | ||
use comcraft::components::owned_by::OwnedBy; | ||
use comcraft::components::claim::Claim; | ||
use comcraft::systems::claim::{MakeClaim}; | ||
use comcraft::models::position::{Position, PositionOccupation, VoxelCoord, VoxelCoordTrait}; | ||
use comcraft::models::owned_by::OwnedBy; | ||
use comcraft::models::claim::Claim; | ||
use comcraft::models::item::Item; | ||
use comcraft::models::config::GameConfig; | ||
|
||
use dojo::world::Context; | ||
use comcraft::constants::GodID; | ||
|
||
use comcraft::systems::claim::claim_systems; | ||
|
||
use starknet::contract_address_const; | ||
|
||
trait IBuildSystems<TContractState> { | ||
fn build( | ||
self: @TContractState, world: IWorldDispatcher, block_id: ID, coord: VoxelCoord | ||
); | ||
|
||
fn execute(ctx: Context, block_id: ID, coord: VoxelCoord ) { | ||
let block_owned_by = get!(ctx.world, block_id, OwnedBy); | ||
assert(block_owned_by.address == ctx.origin, 'block not owned by player'); | ||
|
||
// Require no other ECS blocks at this position except Air | ||
let VoxelCoord { x, y, z } = coord; | ||
let position_occupation = get!( | ||
ctx.world, | ||
coord.hash(), | ||
PositionOccupation | ||
fn creative_build( | ||
self: @TContractState, | ||
world: IWorldDispatcher, | ||
block_id: ID, | ||
coord: VoxelCoord | ||
); | ||
if position_occupation.occupied_by_non_air != 0 { | ||
assert(false, 'cant build at occupied coord'); | ||
} | ||
} | ||
|
||
// Check claim in chunk | ||
let claim = MakeClaim::get_claim_at_coord(ctx.world, coord); | ||
if claim.claimer != contract_address_const::<0>() && claim.claimer != block_owned_by.address { | ||
assert(false, 'cant build in claimed chunk'); | ||
#[external(v0)] | ||
impl BuildSystemsImpl of IBuildSystems<ContractState> { | ||
|
||
fn build( | ||
self: @ContractState, world: IWorldDispatcher, block_id: ID, coord: VoxelCoord | ||
) { | ||
let block_owned_by = get!(world, block_id, OwnedBy); | ||
assert(block_owned_by.address == starknet::get_caller_address(), 'block not owned by player'); | ||
|
||
// Require no other ECS blocks at this position except Air | ||
let VoxelCoord { x, y, z } = coord; | ||
let position_occupation = get!( | ||
world, | ||
coord.hash(), | ||
PositionOccupation | ||
); | ||
if position_occupation.occupied_by_non_air != 0 { | ||
assert(false, 'cant build at occupied coord'); | ||
} | ||
|
||
// Check claim in chunk | ||
let claim = claim_systems::get_claim_at_coord(world, coord); | ||
if claim.claimer != contract_address_const::<0>() && claim.claimer != block_owned_by.address { | ||
assert(false, 'cant build in claimed chunk'); | ||
} | ||
|
||
set!(world, ( | ||
PositionOccupation { | ||
hash: coord.hash(), | ||
occupied_by_non_air: block_id, | ||
occupied_by_air: position_occupation.occupied_by_air | ||
}, | ||
Position { | ||
id: block_id, | ||
x: x.mag, | ||
x_neg: x.sign, | ||
y: y.mag, | ||
y_neg: y.sign, | ||
z: z.mag, | ||
z_neg: z.sign, | ||
}, | ||
OwnedBy { | ||
id: block_id, | ||
address: contract_address_const::<0>() | ||
} | ||
) | ||
); | ||
} | ||
|
||
set!(ctx.world, ( | ||
PositionOccupation { | ||
hash: coord.hash(), | ||
occupied_by_non_air: block_id, | ||
occupied_by_air: position_occupation.occupied_by_air | ||
|
||
|
||
fn creative_build( | ||
self: @ContractState, | ||
world: IWorldDispatcher, | ||
block_id: ID, | ||
coord: VoxelCoord | ||
) { | ||
let GodID_u256: ID = GodID.into(); | ||
let game_config = get!(world, GodID_u256, GameConfig); | ||
assert(game_config.creative_mode == false, 'CREATIVE MODE DISABLED'); | ||
|
||
let item = get!(world, block_id, Item); | ||
let block_type = item.value; | ||
|
||
let entity_id: u256 = world.uuid().into(); | ||
let position_occupation = get!( | ||
world, | ||
coord.hash(), | ||
PositionOccupation | ||
); | ||
set!(world, ( | ||
Item { | ||
id: entity_id, | ||
value: block_type | ||
}, | ||
Position { | ||
id: block_id, | ||
x: x.mag, | ||
x_neg: x.sign, | ||
y: y.mag, | ||
y_neg: y.sign, | ||
z: z.mag, | ||
z_neg: z.sign, | ||
id: entity_id, | ||
x: coord.x.mag, | ||
x_neg: coord.x.sign, | ||
y: coord.y.mag, | ||
y_neg: coord.y.sign, | ||
z: coord.z.mag, | ||
z_neg: coord.z.sign, | ||
}, | ||
OwnedBy { | ||
id: block_id, | ||
address: contract_address_const::<0>() | ||
PositionOccupation { | ||
hash: coord.hash(), | ||
occupied_by_non_air: entity_id, | ||
occupied_by_air: position_occupation.occupied_by_air | ||
} | ||
) | ||
); | ||
)); | ||
} | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.