Jump to content

Issues getting the inventory of minecarts


ghostwolf_

Recommended Posts

 hey guys im trying to get items from a minecart with an inventory, by default a hopper cart or chest cart but could also be any carts added by mods that extends EntityMinecart and have item capability.

 

however after retrieving the inventory the inventory is always returned empty, IItemHandler.getStackInSlot(slot) is always air even though the entire cart is filled with items,

this is the update function that is trying to access the carts inventory, my testing setup has been attached as an image.

@Override
	public void update() {
		if (getWorld().isRemote) {
			EntityMinecart cart = this.getCartInfront(EntityMinecart.class);
			if (cart != null) {
			IItemHandler cartInv = cart.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, getPullFacing());
			if (cartInv != null) {
				System.out.println( cartInv.getSlots());
				for (int i = 0; i < cartInv.getSlots(); i++) {
					System.out.println(cartInv.getStackInSlot(i));
				}
				if (! this.invIsEmpty(cartInv)) {
					System.out.println("moving items");
					moveItems(cartInv);
				} else {
					//cart is empty
					if (emitWhenCartEmpty) {
						this.isEmittingRedstone = true;
					}
				}
			} else {
				//cart has no iventory
				if (emitWhenCartEmpty) {
					this.isEmittingRedstone = true;
				}
			}
		}
		}
	}

 

this is the console output

 

5
[19:22:10] [main/INFO] [STDOUT]: [ghostwolf.steampunkrevolution.tileentities.TileEntityUnloader:update:33]: 1xtile.air@0
[19:22:10] [main/INFO] [STDOUT]: [ghostwolf.steampunkrevolution.tileentities.TileEntityUnloader:update:33]: 1xtile.air@0
[19:22:10] [main/INFO] [STDOUT]: [ghostwolf.steampunkrevolution.tileentities.TileEntityUnloader:update:33]: 1xtile.air@0
[19:22:10] [main/INFO] [STDOUT]: [ghostwolf.steampunkrevolution.tileentities.TileEntityUnloader:update:33]: 1xtile.air@0
[19:22:10] [main/INFO] [STDOUT]: [ghostwolf.steampunkrevolution.tileentities.TileEntityUnloader:update:33]: 1xtile.air@0
5
[19:22:10] [main/INFO] [STDOUT]: [ghostwolf.steampunkrevolution.tileentities.TileEntityUnloader:update:33]: 1xtile.air@0
[19:22:10] [main/INFO] [STDOUT]: [ghostwolf.steampunkrevolution.tileentities.TileEntityUnloader:update:33]: 1xtile.air@0
[19:22:10] [main/INFO] [STDOUT]: [ghostwolf.steampunkrevolution.tileentities.TileEntityUnloader:update:33]: 1xtile.air@0
[19:22:10] [main/INFO] [STDOUT]: [ghostwolf.steampunkrevolution.tileentities.TileEntityUnloader:update:33]: 1xtile.air@0
[19:22:10] [main/INFO] [STDOUT]: [ghostwolf.steampunkrevolution.tileentities.TileEntityUnloader:update:33]: 1xtile.air@0
5
[19:22:11] [main/INFO] [STDOUT]: [ghostwolf.steampunkrevolution.tileentities.TileEntityUnloader:update:33]: 1xtile.air@0
[19:22:11] [main/INFO] [STDOUT]: [ghostwolf.steampunkrevolution.tileentities.TileEntityUnloader:update:33]: 1xtile.air@0
[19:22:11] [main/INFO] [STDOUT]: [ghostwolf.steampunkrevolution.tileentities.TileEntityUnloader:update:33]: 1xtile.air@0
[19:22:11] [main/INFO] [STDOUT]: [ghostwolf.steampunkrevolution.tileentities.TileEntityUnloader:update:33]: 1xtile.air@0
[19:22:11] [main/INFO] [STDOUT]: [ghostwolf.steampunkrevolution.tileentities.TileEntityUnloader:update:33]: 1xtile.air@0

 

if anyone has any idea what might be causing this or where im messing up my code it would be a big help.

 

- thanks ghostwolf

 

2017-12-15_19.21.57.png

2017-12-15_19.21.59.png

Link to comment
Share on other sites

40 minutes ago, ghostwolf_ said:

getWorld().isRemote

 

40 minutes ago, ghostwolf_ said:

IItemHandler cartInv = cart.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, getPullFacing());

Capability data is only saved on the server (meaning client doesn't know anything)

Edited by Matryoshika

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Link to comment
Share on other sites

55 minutes ago, Matryoshika said:

 

Capability data is only saved on the server (meaning client doesn't know anything)

 doesnt the if statement at the start of the function ensure that it is being run on the server to ensure that that isnt an issue?

if (getWorld().isRemote) {

 

it does return a capability and its slots, in my case a hopper with 5 slots fine, its just that the stored items dont transfer properly, or am i just messing up something obvious?

Link to comment
Share on other sites

World::isRemote returns true for Client

 

Capabilities still exist on the client, it's just that no data is saved = null values (tile.air is an empty stack aka null)

  • Like 1

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Link to comment
Share on other sites

Just now, Matryoshika said:

World::isRemote returns true for Client

 

Capabilities still exist on the client, it's just that no data is saved = null values (tile.air is an empty stack aka null)

sigh.. im a retard. i missed the ! that i use on every other update function. no wonder shit didnt work.

Link to comment
Share on other sites

well thanks its working fine now, but i ran into another issue. i cant get my block model to rotate on the x-axis,

 

{
  "forge_marker": 1,
  "defaults": {
    "model": "steampunkrevolution:unloader",
    "textures": {
		"front": "minecraft:blocks/coal_block"
	}
  },
  "variants": {
    "normal": [{}],
    "inventory": [{}],
    "facing": {
      "north": {"y": 270},
      "south": {"y": 90},
      "west": {"y": 180},
      "east": {},
      "up": { "x": -90},
      "down": {"x": 90}
    },
    "enabled": {
	"true": {},
	"false": {}
	}
  }
}

 

this is the blockstate file, the facing is set correct (checked via the F3 menu and it moves items from the cart above it when set to up).

 

but the model doesnt rotate towards up

 

{ "source": "[120, -38, 99, 98, 17, -56, -51, -52, 75, 77, 46, 74, 76, 43, 81, 53, 118, 76, -52, 44, -78, 103, -112, 71, 22, 41, 46, -55, -49, 75, -75, 47, 75, 44, -54, 76, -52, 43, -79, 5, -13, 24, -60, -111, 21, 100, 22, -27, -25, -59, 39, -27, -28, 39, 103, -37, -93, 74, 36, -25, 39, -26, -64, 36, 24, 26, 56, 66, -127, 32, 107, -43, -86, -107, 40, 120, 106, -40, -54, -84, 9, 108, -88, 24, 36, -122, -90, 14, -90, 119, 106, 104, 104, 24, 6, -114, -1, -118, -118, -79, -88, -127, -103, 3, 98, -101, -110, -120, 7, -115, 126, 96, -72, 96, -47, 31, -118, 3, -93, -22, -121, -122, 51, 40, 124, -80, -24, -113, 65, -61, -88, -6, -127, 122, 96, 113, 51, -92, -11, 83, 26, 126, 67, 61, -3, 80, -104, 127, 40, -51, -65, 0, 46, -94, -85, -38]",
"textures": {"1398723388": "minecraft:blocks/hopper_outside",
"1695556649": "#front",
"761770141": "minecraft:blocks/nether_brick",
"particle": "minecraft:blocks/nether_brick"},
"elements": [
{ "from": [1,0,1], "to": [15,0,5], "faces": { "down":  { "uv": [1,11,15,15], "texture": "#1398723388", "cullface": "down" } } },
{ "from": [1,0,5], "to": [5,0,11], "faces": { "down":  { "uv": [1,5,5,11], "texture": "#1398723388", "cullface": "down" } } },
{ "from": [1,0,11], "to": [15,0,15], "faces": { "down":  { "uv": [1,1,15,5], "texture": "#1398723388", "cullface": "down" } } },
{ "from": [11,0,5], "to": [15,0,11], "faces": { "down":  { "uv": [11,5,15,11], "texture": "#1398723388", "cullface": "down" } } },
{ "from": [1,16,1], "to": [15,16,5], "faces": { "up":  { "uv": [1,1,15,5], "texture": "#1398723388", "cullface": "up" } } },
{ "from": [1,16,5], "to": [5,16,11], "faces": { "up":  { "uv": [1,5,5,11], "texture": "#1398723388", "cullface": "up" } } },
{ "from": [1,16,11], "to": [15,16,15], "faces": { "up":  { "uv": [1,11,15,15], "texture": "#1398723388", "cullface": "up" } } },
{ "from": [11,16,5], "to": [15,16,11], "faces": { "up":  { "uv": [11,5,15,11], "texture": "#1398723388", "cullface": "up" } } },
{ "from": [1,1,0], "to": [15,5,0], "faces": { "north":  { "uv": [1,11,15,15], "texture": "#1398723388", "cullface": "north" } } },
{ "from": [1,5,0], "to": [5,11,0], "faces": { "north":  { "uv": [11,5,15,11], "texture": "#1398723388", "cullface": "north" } } },
{ "from": [1,11,0], "to": [15,15,0], "faces": { "north":  { "uv": [1,1,15,5], "texture": "#1398723388", "cullface": "north" } } },
{ "from": [11,5,0], "to": [15,11,0], "faces": { "north":  { "uv": [1,5,5,11], "texture": "#1398723388", "cullface": "north" } } },
{ "from": [1,1,16], "to": [15,5,16], "faces": { "south":  { "uv": [1,11,15,15], "texture": "#1398723388", "cullface": "south" } } },
{ "from": [1,5,16], "to": [5,11,16], "faces": { "south":  { "uv": [1,5,5,11], "texture": "#1398723388", "cullface": "south" } } },
{ "from": [1,11,16], "to": [15,15,16], "faces": { "south":  { "uv": [1,1,15,5], "texture": "#1398723388", "cullface": "south" } } },
{ "from": [11,5,16], "to": [15,11,16], "faces": { "south":  { "uv": [11,5,15,11], "texture": "#1398723388", "cullface": "south" } } },
{ "from": [0,1,1], "to": [0,15,5], "faces": { "west":  { "uv": [1,1,5,15], "texture": "#1398723388", "cullface": "west" } } },
{ "from": [0,1,5], "to": [0,5,11], "faces": { "west":  { "uv": [5,11,11,15], "texture": "#1398723388", "cullface": "west" } } },
{ "from": [0,1,11], "to": [0,15,15], "faces": { "west":  { "uv": [11,1,15,15], "texture": "#1398723388", "cullface": "west" } } },
{ "from": [0,11,5], "to": [0,15,11], "faces": { "west":  { "uv": [5,1,11,5], "texture": "#1398723388", "cullface": "west" } } },
{ "from": [16,1,1], "to": [16,15,2], "faces": { "east":  { "uv": [14,1,15,15], "texture": "#1398723388", "cullface": "east" } } },
{ "from": [16,1,2], "to": [16,2,14], "faces": { "east":  { "uv": [2,14,14,15], "texture": "#1398723388", "cullface": "east" } } },
{ "from": [16,14,2], "to": [16,15,14], "faces": { "east":  { "uv": [2,1,14,2], "texture": "#1398723388", "cullface": "east" } } },
{ "from": [16,1,14], "to": [16,15,15], "faces": { "east":  { "uv": [1,1,2,15], "texture": "#1398723388", "cullface": "east" } } },
{ "from": [15,2,2], "to": [16,2,14], "faces": { "up":  { "uv": [15,2,16,14], "texture": "#1398723388" } } },
{ "from": [15,14,2], "to": [16,14,14], "faces": { "down":  { "uv": [15,2,16,14], "texture": "#1398723388" } } },
{ "from": [15,2,2], "to": [16,14,2], "faces": { "south":  { "uv": [15,2,16,14], "texture": "#1398723388" } } },
{ "from": [15,2,14], "to": [16,14,14], "faces": { "north":  { "uv": [0,2,1,14], "texture": "#1398723388" } } },
{ "from": [15,2,2], "to": [15,14,14], "faces": { "east":  { "uv": [2,2,14,14], "texture": "#1695556649" } } },
{ "from": [1,6,6], "to": [1,10,10], "faces": { "west":  { "uv": [6,6,10,10], "texture": "#1695556649" } } },
{ "from": [6,15,6], "to": [10,15,10], "faces": { "up":  { "uv": [6,6,10,10], "texture": "#1695556649" } } },
{ "from": [6,1,6], "to": [10,1,10], "faces": { "down":  { "uv": [6,6,10,10], "texture": "#1695556649" } } },
{ "from": [6,6,15], "to": [10,10,15], "faces": { "south":  { "uv": [6,6,10,10], "texture": "#1695556649" } } },
{ "from": [6,6,1], "to": [10,10,1], "faces": { "north":  { "uv": [6,6,10,10], "texture": "#1695556649" } } },
{ "from": [0,0,0], "to": [16,0,1], "faces": { "down":  { "uv": [0,15,16,16], "texture": "#761770141", "cullface": "down" } } },
{ "from": [0,0,1], "to": [1,0,15], "faces": { "down":  { "uv": [0,1,1,15], "texture": "#761770141", "cullface": "down" } } },
{ "from": [15,0,1], "to": [16,0,15], "faces": { "down":  { "uv": [15,1,16,15], "texture": "#761770141", "cullface": "down" } } },
{ "from": [0,0,15], "to": [16,0,16], "faces": { "down":  { "uv": [0,0,16,1], "texture": "#761770141", "cullface": "down" } } },
{ "from": [5,0,6], "to": [6,0,10], "faces": { "down":  { "uv": [5,6,6,10], "texture": "#761770141", "cullface": "down" } } },
{ "from": [10,0,6], "to": [11,0,10], "faces": { "down":  { "uv": [10,6,11,10], "texture": "#761770141", "cullface": "down" } } },
{ "from": [5,0,5], "to": [11,0,6], "faces": { "down":  { "uv": [5,10,11,11], "texture": "#761770141", "cullface": "down" } } },
{ "from": [5,0,10], "to": [11,0,11], "faces": { "down":  { "uv": [5,5,11,6], "texture": "#761770141", "cullface": "down" } } },
{ "from": [0,16,0], "to": [16,16,1], "faces": { "up":  { "uv": [0,0,16,1], "texture": "#761770141", "cullface": "up" } } },
{ "from": [0,16,1], "to": [1,16,15], "faces": { "up":  { "uv": [0,1,1,15], "texture": "#761770141", "cullface": "up" } } },
{ "from": [15,16,1], "to": [16,16,15], "faces": { "up":  { "uv": [15,1,16,15], "texture": "#761770141", "cullface": "up" } } },
{ "from": [0,16,15], "to": [16,16,16], "faces": { "up":  { "uv": [0,15,16,16], "texture": "#761770141", "cullface": "up" } } },
{ "from": [5,16,6], "to": [6,16,10], "faces": { "up":  { "uv": [5,6,6,10], "texture": "#761770141", "cullface": "up" } } },
{ "from": [10,16,6], "to": [11,16,10], "faces": { "up":  { "uv": [10,6,11,10], "texture": "#761770141", "cullface": "up" } } },
{ "from": [5,16,5], "to": [11,16,6], "faces": { "up":  { "uv": [5,5,11,6], "texture": "#761770141", "cullface": "up" } } },
{ "from": [5,16,10], "to": [11,16,11], "faces": { "up":  { "uv": [5,10,11,11], "texture": "#761770141", "cullface": "up" } } },
{ "from": [0,0,0], "to": [16,1,0], "faces": { "north":  { "uv": [0,15,16,16], "texture": "#761770141", "cullface": "north" } } },
{ "from": [0,1,0], "to": [1,15,0], "faces": { "north":  { "uv": [15,1,16,15], "texture": "#761770141", "cullface": "north" } } },
{ "from": [15,1,0], "to": [16,15,0], "faces": { "north":  { "uv": [0,1,1,15], "texture": "#761770141", "cullface": "north" } } },
{ "from": [0,15,0], "to": [16,16,0], "faces": { "north":  { "uv": [0,0,16,1], "texture": "#761770141", "cullface": "north" } } },
{ "from": [5,6,0], "to": [6,10,0], "faces": { "north":  { "uv": [10,6,11,10], "texture": "#761770141", "cullface": "north" } } },
{ "from": [10,6,0], "to": [11,10,0], "faces": { "north":  { "uv": [5,6,6,10], "texture": "#761770141", "cullface": "north" } } },
{ "from": [5,5,0], "to": [11,6,0], "faces": { "north":  { "uv": [5,10,11,11], "texture": "#761770141", "cullface": "north" } } },
{ "from": [5,10,0], "to": [11,11,0], "faces": { "north":  { "uv": [5,5,11,6], "texture": "#761770141", "cullface": "north" } } },
{ "from": [0,0,16], "to": [16,1,16], "faces": { "south":  { "uv": [0,15,16,16], "texture": "#761770141", "cullface": "south" } } },
{ "from": [0,1,16], "to": [1,15,16], "faces": { "south":  { "uv": [0,1,1,15], "texture": "#761770141", "cullface": "south" } } },
{ "from": [15,1,16], "to": [16,15,16], "faces": { "south":  { "uv": [15,1,16,15], "texture": "#761770141", "cullface": "south" } } },
{ "from": [0,15,16], "to": [16,16,16], "faces": { "south":  { "uv": [0,0,16,1], "texture": "#761770141", "cullface": "south" } } },
{ "from": [5,6,16], "to": [6,10,16], "faces": { "south":  { "uv": [5,6,6,10], "texture": "#761770141", "cullface": "south" } } },
{ "from": [10,6,16], "to": [11,10,16], "faces": { "south":  { "uv": [10,6,11,10], "texture": "#761770141", "cullface": "south" } } },
{ "from": [5,5,16], "to": [11,6,16], "faces": { "south":  { "uv": [5,10,11,11], "texture": "#761770141", "cullface": "south" } } },
{ "from": [5,10,16], "to": [11,11,16], "faces": { "south":  { "uv": [5,5,11,6], "texture": "#761770141", "cullface": "south" } } },
{ "from": [0,0,0], "to": [0,16,1], "faces": { "west":  { "uv": [0,0,1,16], "texture": "#761770141", "cullface": "west" } } },
{ "from": [0,0,1], "to": [0,1,15], "faces": { "west":  { "uv": [1,15,15,16], "texture": "#761770141", "cullface": "west" } } },
{ "from": [0,15,1], "to": [0,16,15], "faces": { "west":  { "uv": [1,0,15,1], "texture": "#761770141", "cullface": "west" } } },
{ "from": [0,0,15], "to": [0,16,16], "faces": { "west":  { "uv": [15,0,16,16], "texture": "#761770141", "cullface": "west" } } },
{ "from": [0,5,6], "to": [0,6,10], "faces": { "west":  { "uv": [6,10,10,11], "texture": "#761770141", "cullface": "west" } } },
{ "from": [0,10,6], "to": [0,11,10], "faces": { "west":  { "uv": [6,5,10,6], "texture": "#761770141", "cullface": "west" } } },
{ "from": [0,5,5], "to": [0,11,6], "faces": { "west":  { "uv": [5,5,6,11], "texture": "#761770141", "cullface": "west" } } },
{ "from": [0,5,10], "to": [0,11,11], "faces": { "west":  { "uv": [10,5,11,11], "texture": "#761770141", "cullface": "west" } } },
{ "from": [16,0,0], "to": [16,16,1], "faces": { "east":  { "uv": [15,0,16,16], "texture": "#761770141", "cullface": "east" } } },
{ "from": [16,0,1], "to": [16,1,15], "faces": { "east":  { "uv": [1,15,15,16], "texture": "#761770141", "cullface": "east" } } },
{ "from": [16,15,1], "to": [16,16,15], "faces": { "east":  { "uv": [1,0,15,1], "texture": "#761770141", "cullface": "east" } } },
{ "from": [16,0,15], "to": [16,16,16], "faces": { "east":  { "uv": [0,0,1,16], "texture": "#761770141", "cullface": "east" } } },
{ "from": [6,6,0], "to": [6,10,1], "faces": { "east":  { "uv": [15,6,16,10], "texture": "#761770141" } } },
{ "from": [6,0,6], "to": [6,1,10], "faces": { "east":  { "uv": [6,15,10,16], "texture": "#761770141" } } },
{ "from": [6,15,6], "to": [6,16,10], "faces": { "east":  { "uv": [6,0,10,1], "texture": "#761770141" } } },
{ "from": [6,6,15], "to": [6,10,16], "faces": { "east":  { "uv": [0,6,1,10], "texture": "#761770141" } } },
{ "from": [10,6,0], "to": [10,10,1], "faces": { "west":  { "uv": [0,6,1,10], "texture": "#761770141" } } },
{ "from": [10,0,6], "to": [10,1,10], "faces": { "west":  { "uv": [6,15,10,16], "texture": "#761770141" } } },
{ "from": [10,15,6], "to": [10,16,10], "faces": { "west":  { "uv": [6,0,10,1], "texture": "#761770141" } } },
{ "from": [10,6,15], "to": [10,10,16], "faces": { "west":  { "uv": [15,6,16,10], "texture": "#761770141" } } },
{ "from": [6,6,0], "to": [10,6,1], "faces": { "up":  { "uv": [6,0,10,1], "texture": "#761770141" } } },
{ "from": [0,6,6], "to": [1,6,10], "faces": { "up":  { "uv": [0,6,1,10], "texture": "#761770141" } } },
{ "from": [6,6,15], "to": [10,6,16], "faces": { "up":  { "uv": [6,15,10,16], "texture": "#761770141" } } },
{ "from": [6,10,0], "to": [10,10,1], "faces": { "down":  { "uv": [6,15,10,16], "texture": "#761770141" } } },
{ "from": [0,10,6], "to": [1,10,10], "faces": { "down":  { "uv": [0,6,1,10], "texture": "#761770141" } } },
{ "from": [6,10,15], "to": [10,10,16], "faces": { "down":  { "uv": [6,0,10,1], "texture": "#761770141" } } },
{ "from": [6,0,6], "to": [10,1,6], "faces": { "south":  { "uv": [6,15,10,16], "texture": "#761770141" } } },
{ "from": [0,6,6], "to": [1,10,6], "faces": { "south":  { "uv": [0,6,1,10], "texture": "#761770141" } } },
{ "from": [6,15,6], "to": [10,16,6], "faces": { "south":  { "uv": [6,0,10,1], "texture": "#761770141" } } },
{ "from": [6,0,10], "to": [10,1,10], "faces": { "north":  { "uv": [6,15,10,16], "texture": "#761770141" } } },
{ "from": [0,6,10], "to": [1,10,10], "faces": { "north":  { "uv": [15,6,16,10], "texture": "#761770141" } } },
{ "from": [6,15,10], "to": [10,16,10], "faces": { "north":  { "uv": [6,0,10,1], "texture": "#761770141" } } }
],
"display": { "thirdperson": { "rotation": [ 10, -45, 170 ], "translation": [ 0, 1.5, -2.75 ], "scale": [ 0.375, 0.375, 0.375 ] } }, "parent": "block/cube_all" }

 

this is the model im using.

 

im fairly new to modding so im not too familiar with the model and block states files, but setting the facing to n,s,w,e works fine and rotates like its supposed to, but rotating up and down doesnt work.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.