Skip to content

Commit

Permalink
fixed chest system(that was sooo long)
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed May 2, 2023
1 parent 4872b32 commit 07f1ec7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
5 changes: 1 addition & 4 deletions eggtoast_factorit/api/inventory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,15 @@ inv = {
mouseclick = function(x,y,b)
if b == 1 then
if mouseOn.is then

if not selected.is then
if mouseOn.trash then
else
if crafteruse then
if not (plr.inventory[(mouseOn.y-1)*8+mouseOn.x].id==nil) then
for i = 1,#obj.list[plr.craftopeni].nbt.inv do
if obj.list[plr.craftopeni].nbt.inv[i].id == nil then
_G[string.gsub(obj.list[plr.craftopeni].id,"plcd","").."put"](i,mouseOn.x,mouseOn.y,plr.craftopeni)
goto inventorymouseclickend
end
end
end
if mecharmuse then
if plr.inventory[(mouseOn.y-1)*8+mouseOn.x].id==nil then else
if obj.list[plr.craftopeni].nbt.inv.id==nil then
Expand Down
1 change: 1 addition & 0 deletions eggtoast_factorit/api/misc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ misc = {
plr.inventory = file.plr.inv
plr.x = file.plr.posx
plr.y = file.plr.posy
chest.loadsave()
end
},
filer={
Expand Down
14 changes: 11 additions & 3 deletions eggtoast_factorit/api/obj.lua
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ obj={
"minerplcd",
"chestplcd",
"crafterplcd",
"crafttable",
"crafttableplcd",
"mecharmplcd"
},
hasslot={
Expand All @@ -153,7 +153,10 @@ obj={
slot1bothio={
"chestplcd"
},

interactableinv={
"crafttableplcd",
"chestplcd"
},
--type related stuff

nature = {
Expand All @@ -166,7 +169,7 @@ obj={
{inv={{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil}},timer=60,ore=nil},
{inv={{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil}},invslt2={id=nil},timer=120,recipe=nil,craftopen=false},
{inv={id=nil},timer=30,machine1=nil,machine2=nil,},
{inv={{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil},{id=nil}}},
{inv={}},
{craftopen=false}
},
tick=function (dt)
Expand All @@ -178,7 +181,12 @@ obj={
_G[string.gsub(obj.list[i].id,"plcd","")].tick(i)
end
local mx,my = mouse.getPos()
local px = plr.x
local py = plr.y
local ox,oy = cam:cameraCoords(obj.list[i].x,obj.list[i].y)
if table.contains(obj.plctag.interactableinv,obj.list[i].id) then
_G[obj.plctag.guiname[indexOf(obj.plctag.withgui,obj.list[i].id)]].tick(i)
end
if mx > ox and my > oy and mx < ox+objwidth*1.3 and my < oy+objheight*1.3 then
local isdownspace = false
if joymode then
Expand Down
30 changes: 20 additions & 10 deletions eggtoast_factorit/machine/chest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,46 @@ local craftbenchx = {
265,
300
}
chestlist = {}
chest = {
loadsave= function ()
chestlist={}
for i = 1,#obj.list do
if obj.list[i].id == "chestplcd" then
chestlist[i]=obj.list[i].nbt.inv
end
end
end,
draw = function (i)
if inv.open and (i==plr.craftopeni) and plr.craftopen and crafteruse then
for y = 1,5 do
for x = 1,6 do
love.graphics.setColor(1,1,1)
love.graphics.rectangle("fill",craftbenchx[x]+5,craftbenchy[y],30,30)
if not (obj.list[i].nbt.inv[(y-1)*6+x]==nil) then
love.graphics.draw(gr.texture.gettex(obj.list[i].nbt.inv[(y-1)*6+x].id),craftbenchx[x]+5,craftbenchy[y],0,0.065)
if not (chestlist[i][(y-1)*6+x]==nil) then
love.graphics.draw(gr.texture.gettex(chestlist[i][(y-1)*6+x].id),craftbenchx[x]+5,craftbenchy[y],0,0.065)
end
end
end
love.graphics.print(lang.gettxt("item.chest.name"),60,223,0,1,1)
end
end,
tick = function (i)
if not (table.haskey(chestlist,i)) then
chestlist[i]={}
end
if mouse.ison(1) and inv.open and (i==plr.craftopeni) then
for y = 1,5 do
for x = 1,6 do
local mx,my = mouse.getPos()
if (mx>craftbenchx[x]+5) and (mx<craftbenchx[x]+5+30) and (my>craftbenchy[y]) and (my<craftbenchy[y]+30) then
item.give(obj.list[i].nbt.inv[(y-1)*6+x])
obj.list[i].nbt.inv[(y-1)*6+x]={id=nil}
item.give(chestlist[i][(y-1)*6+x])
chestlist[i][(y-1)*6+x]={id=nil}
end
end
end
end
obj.list[i].nbt.inv=chestlist[i]
end,
toggleopen = function(i)
if obj.list[i].nbt.craftopen==true then
Expand All @@ -62,11 +75,8 @@ chest = {
end
}
chestput = function (z,x,y)
for i = 1,#obj.list[plr.craftopeni].nbt.inv do
if obj.list[plr.craftopeni].nbt.inv[i].id==nil then
obj.list[plr.craftopeni].nbt.inv[i] = plr.inventory[(y-1)*8+x]
plr.inventory[(y-1)*8+x]={id=nil}
break
end
if #chestlist[plr.craftopeni]~=30 then
table.insert(chestlist[plr.craftopeni],plr.inventory[(y-1)*8+x])
plr.inventory[(y-1)*8+x]={id=nil}
end
end

0 comments on commit 07f1ec7

Please sign in to comment.