Skip to content

Commit d7debcb

Browse files
committed
give cmd works
1 parent 1b83515 commit d7debcb

4 files changed

Lines changed: 21 additions & 3 deletions

File tree

mods/clonecraft/clonecraft.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ func _makeOL() -> void:
170170

171171

172172
func registerPhase() -> void:
173+
CMDprocessor.registerCommand(load("res://mods/clonecraft/cmd/give.gd").new())
173174
man.quickUniformBlock(MODID, "stone", "Stone", Vector2(0, 0), mat1)
174175
man.quickUniformBlock(MODID, "dirt", "Dirt", Vector2(1, 0), mat1, 1, 1, "shovel")
175176
canGrass.append("clonecraft:dirt")

mods/clonecraft/cmd/give.gd

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ func getCommandInvocation() -> String:
77

88
func getCommandArgList(index:int) -> Array:
99
if index == -1:
10-
return ["<String ID>", "[Int Count]", "[String Player]"]
10+
return ["<String ID>", "[Int Count]", "[String Player]", "[Dict Metadata]"]
1111
elif index == 0:
1212
return ItemManager.items.keys()
1313
elif index == 1:
@@ -38,5 +38,21 @@ func exectue(args:Array) -> Variant:
3838
else:
3939
CMDprocessor.throw("cmd.error.arg_invalid")
4040
return false
41+
c = int(args[1])
4142

42-
return true
43+
44+
if l > 2:
45+
p = WorldControl.getPlayer(str(args[2]))
46+
if p == null:
47+
CMDprocessor.throw("cmd.error.player_not_found")
48+
return false
49+
else:
50+
p = WorldControl.getPlayer(WorldControl.localUsername)
51+
52+
# TODO implement metadata arg
53+
54+
if l > 4:
55+
CMDprocessor.throw("cmd.error.too_many_args")
56+
return false
57+
58+
return p.inventory.addItem(ItemManager.ItemStack.new(str(args[0]), c))

scripts/itemManager.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ItemStack extends RefCounted:
2020
var count:int
2121
## Generic data storage. Can contain anything.
2222
var metadata:Dictionary
23-
23+
## a
2424
func _init(iid:StringName, icount:int, imetadata:Dictionary = {}):
2525
itemID = iid
2626
count = icount

scripts/worldControl.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func saveworld():
5757
var jsave := JSON.stringify(_p.save(), " ")
5858
if !DirAccess.dir_exists_absolute(worldpath + "/playerdata/"):
5959
DirAccess.make_dir_absolute(worldpath + "/playerdata/")
60+
# TODO un-hardcode this
6061
var playsavepath := worldpath + "/playerdata/__localplayer__.json"
6162
var f := FileAccess.open(playsavepath, FileAccess.WRITE)
6263
f.store_string(jsave)

0 commit comments

Comments
 (0)