The Meaning of Life, the Universe, and Everything.
Location:
Budapest
Join Date:
8/14/2012
Posts:
58
Minecraft:
FBalazs379
Member Details
Hi,
I'm developing a custom tileentity with a guiless inventory. You can put items on it's top side and get them out of there. I have two problems here. The first and more important problem is that i can't get the world to spawn the item when the player interacts with the block. I call world.spawnEntity on the server side with an EntityItem filled with the ItemStack. On client, the item pops up and disappears instantly, without me getting the item in the player inventory. The corresponding code looks like this:
public boolean onPlayerRightClickOnTop(EntityPlayer player, float hitX, float hitZ) {
if (world.isRemote) {
return false;
}
int i = hitX > 0.33f ? (hitX > 0.66f ? 2 : 1) : 0;
int j = hitZ > 0.33f ? (hitZ > 0.66f ? 2 : 1) : 0;
ItemStack activeStack = player.getHeldItemMainhand();
if (player.isSneaking()) {
if (!inventory[i][j].isEmpty()) {
EntityItem entityItem = new EntityItem(world, pos.getX() + hitX, pos.getY() + 1.2, pos.getZ() + hitZ, inventory[i][j]);
world.spawnEntity(entityItem);
inventory[i][j].setCount(0);
sendDataToClients();
return true;
} else if (!activeStack.isEmpty()) {
inventory[i][j] = activeStack.copy();
activeStack.setCount(0);
sendDataToClients();
return true;
}
} else if (!activeStack.isEmpty()) {
if (inventory[i][j].isEmpty()) {
inventory[i][j] = activeStack.splitStack(1);
sendDataToClients();
return true;
} else if (inventory[i][j].isItemEqual(activeStack)
&& inventory[i][j].getCount() < inventory[i][j].getMaxStackSize()) {
inventory[i][j].setCount(inventory[i][j].getCount()+1);
activeStack.splitStack(1);
sendDataToClients();
return true;
}
}
return false;
}
My second problem is that the items rendered on the block look totally dark, no lightning at all. I tried it with and without the lightning related lines, but i noticed no change. The rendering code is like this:
@Override
public void render(TileEntityCraftingPillar te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
super.render(te, x, y, z, partialTicks, destroyStage, alpha);
EntityItem entityItem = new EntityItem(getWorld());
entityItem.hoverStart = 0;
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
if (!te.getItemStackAt(i, j).isEmpty()) {
GlStateManager.pushMatrix();
GlStateManager.translate(x + 1./6 + 1./3*i, y + 1, z + 1./6 + 1./3*j);
//GlStateManager.translate(-x, -y, -z);
GlStateManager.scale(0.33, 0.33, 0.33);
GlStateManager.pushAttrib();
RenderHelper.enableStandardItemLighting();
entityItem.setItem(te.getItemStackAt(i, j));
Minecraft.getMinecraft().getRenderManager().doRenderEntity(entityItem,
0, 0, 0, 0, 0, false);
//RenderEntityItem
//Minecraft.getMinecraft().getRenderItem().renderItem(te.getItemStackAt(i, j), ItemCameraTransforms.TransformType.FIXED);
RenderHelper.disableStandardItemLighting();
GlStateManager.popAttrib();
GlStateManager.popMatrix();
}
}
}
}
The Meaning of Life, the Universe, and Everything.
Location:
Budapest
Join Date:
8/14/2012
Posts:
58
Minecraft:
FBalazs379
Member Details
I fixed the item spawning problem. I passed the itemstacks reference contained by the inventory in the entity's constructor, so when i set the amount to zero in the inventory, the entity's amount also changed to zero so it disappeared. The code will soon be available on GitHub. The rendering problem still exists.
Hi,
I'm developing a custom tileentity with a guiless inventory. You can put items on it's top side and get them out of there. I have two problems here. The first and more important problem is that i can't get the world to spawn the item when the player interacts with the block. I call world.spawnEntity on the server side with an EntityItem filled with the ItemStack. On client, the item pops up and disappears instantly, without me getting the item in the player inventory. The corresponding code looks like this:
My second problem is that the items rendered on the block look totally dark, no lightning at all. I tried it with and without the lightning related lines, but i noticed no change. The rendering code is like this:
Screenshot of the rendering result:
The GitHub project can be found here.
Thank you for your help in advance!
The code can be found here.
I fixed the item spawning problem. I passed the itemstacks reference contained by the inventory in the entity's constructor, so when i set the amount to zero in the inventory, the entity's amount also changed to zero so it disappeared. The code will soon be available on GitHub. The rendering problem still exists.