Jump to content


Photo

Minecraft Inventory Problems


  • Please log in to reply
6 replies to this topic

#1 StrangeOne101

StrangeOne101

    GMC Member

  • GMC Member
  • 97 posts
  • Version:GM8

Posted 09 December 2011 - 07:23 AM

Hello Everyone.

Today, I'm working on a project of a minecraft inventory. It's all going well apart from now I have a bit of a problem. Also take note that this isn't the whole thing, it's just starting off basic so I can get the hang of it. Anyway, the inventory won't make any items. Telling you all the code will take up a lot of space so I've uploaded my .gmk

Download Link

If anybody could help me, it would be much appreciated. :smile:

Edited by StrangeOne101, 09 December 2011 - 07:24 AM.

  • 0

#2 FoxInABox

FoxInABox

    GMC Member

  • GMC Member
  • 5399 posts
  • Version:GM:Studio

Posted 09 December 2011 - 09:45 AM

I remember you from an earlier mc post.. atm it seems you do not change the variables when dropping items into your grid, but I can try to put some ligth on a method you can use to find out what item to create:

let's say we placed two planks at 1,1 and 1,2:
000
010
010

but later we have a case where we place them at 2,0 and 2,1:
001
001
000

what we must do is to run a code to find the area that is beeing used, so after running that code it will just search that area that is:
1
1
and we then turn that into a string where | is line seperatior, so then we know that:
"1|1" should turn into a stick:

same with a bowl:
000
101
010

101 // are beeing used
010

"1 1| 1 " // I put spaces instead of your -1

does this code make any sence?
var i,j,imin,imax;

// find the min and max area to check
imin=4; imax=noone; // variables that hold max and min search area
jmin=4; jmax=noone;

for(i=0;i<=2;i+=1)
for(j=0;j<=2;j+=1)
if slot[i,j]!=-1{ // when you find a empty slot then log the min and max i and j
  imin=min(i,imin); imax=max(i,imax);
  jmin=min(j,jmin); jmax=max(j,jmax);
}

s=''

// loop thru it and fill in the string
if imin!=4
for(i=imin;i<=imax;i+=1){ // use  the min and max in the loop to just search the area we found item data in
  if s!='' s+='|';
  for(j=jmin;j<=jmax;j+=1){
    if slot[i,j]=-1 s+='   ' else s+=string_replace_all(string_format(slot[i,j],3,0),' ','0')
  }
}

that is the idea behind it .. so then you can have a switch statement to find out what the result will be:
switch(s){
case "001|001": result=280; break; // I made all the characters 3 digits, since minecraft used that many
case "001   001|   001   ": result=281; break;
}
280 and 281 are the mc indexes for stick and bowl ^^

hope that made any sence.

Edited by FoxInABox, 09 December 2011 - 09:46 AM.

  • 0

#3 StrangeOne101

StrangeOne101

    GMC Member

  • GMC Member
  • 97 posts
  • Version:GM8

Posted 09 December 2011 - 05:50 PM

Thanks for the reply. The outcome makes sense, but there are two things I don't get.

1. How will I read different numbers for different items.
2. What about things like a pickaxe?

333
020
020

When it create the string, it'll be like: "333| 2 | 2 ". What about when I need items that have a code over 9? If it were diamond, it could be:

212121
020
020

And the string would be: "212121| 2 | 2 ".

How do I fix this?
  • 0

#4 FoxInABox

FoxInABox

    GMC Member

  • GMC Member
  • 5399 posts
  • Version:GM:Studio

Posted 09 December 2011 - 07:30 PM

1. well, when I drop something over the inventory, I usally delete the item object .. and just move the number I have given it into the slot .. and create when dropping outside of it

it can be as simple as putting something like:
nr = 10;
in the create event of the item:

then the inventory can have an array that contains the name of all items, or a list of sprites (tho' one could use the index as the image_index aswell):
item_name[10]="Tree chunk";
item_sprite[10]=spr_treechunk;

if you got a code that tell if you are over a slot and what slot positions you are over, then when you release the drag button:
if over_slot { // if over slot 
  slot[over_x,over_y] = nr; // put it in the slot cordinates
  instance_destroy() // and destroy item
}
ofc you need some code to accually find those..

then the inventory know the index and can find the sprite and name of it by:
for(a=0;a<3;a+=1)
for(b=0;b<3;b+=1)
  if slot[a,b]!=-1{
    draw_sprite(item_sprite[slot[a,b]] ,0,a*16,b*16)
    draw_text(item_name[slot[a,b]] ,a*16,b*16)
  }
but yeah, there are many ways to do this. but it's good to build parts of it yourself so you know what it does.

2. did you read the part where I said I made them 3 digits long:
switch(s){
case "001|001": result=280; break; // I made all the characters 3 digits, since minecraft used that many
case "001   001|   001   ": result=281; break;
}
the first one was just to not confuse too mutch ^^;;

"212121| 2 | 2 " would then be
"021021021| 002 | 002 "
  • 0

#5 StrangeOne101

StrangeOne101

    GMC Member

  • GMC Member
  • 97 posts
  • Version:GM8

Posted 09 December 2011 - 08:05 PM

Ok. I got the second one all right but not so much the first one. I think I got it but I still might need a bit of help installing it. I'll post back here if I have any trouble.

Oh, and thanks for all the help :thanks:
  • 0

#6 StrangeOne101

StrangeOne101

    GMC Member

  • GMC Member
  • 97 posts
  • Version:GM8

Posted 09 December 2011 - 08:14 PM

Actually, I probably will need a bit of help. I not that experienced with Game Maker and I am also quite young. Could you tell me where and how to install it?

Thanks heaps :thanks:
  • 0

#7 StrangeOne101

StrangeOne101

    GMC Member

  • GMC Member
  • 97 posts
  • Version:GM8

Posted 12 December 2011 - 04:54 AM

Bump. It's been 48 hours and I still haven't solved this.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users