Fixed stackSize tooltip being "1" and added inventory clear method

This commit is contained in:
Calclavia 2014-01-12 13:07:18 +08:00
parent 05241e740e
commit f581ade242
3 changed files with 119 additions and 29 deletions

View file

@ -1,10 +1,14 @@
package resonantinduction.archaic.engineering; package resonantinduction.archaic.engineering;
import java.util.Random;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon; import net.minecraft.util.Icon;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -36,6 +40,67 @@ public class BlockEngineeringTable extends BlockRI
setTextureName("crafting_table"); setTextureName("crafting_table");
} }
@Override
public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player)
{
if (!world.isRemote)
{
dropEntireInventory(world, x, y, z, 0, 0);
}
}
@Override
public void dropEntireInventory(World world, int x, int y, int z, int par5, int par6)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity != null)
{
if (tileEntity instanceof IInventory)
{
IInventory inventory = (IInventory) tileEntity;
// PREVENTS OUTPUT FROM DROPPING!
for (int var6 = 0; var6 < inventory.getSizeInventory() - 1; ++var6)
{
ItemStack var7 = inventory.getStackInSlot(var6);
if (var7 != null)
{
Random random = new Random();
float var8 = random.nextFloat() * 0.8F + 0.1F;
float var9 = random.nextFloat() * 0.8F + 0.1F;
float var10 = random.nextFloat() * 0.8F + 0.1F;
while (var7.stackSize > 0)
{
int var11 = random.nextInt(21) + 10;
if (var11 > var7.stackSize)
{
var11 = var7.stackSize;
}
var7.stackSize -= var11;
EntityItem var12 = new EntityItem(world, (x + var8), (y + var9), (z + var10), new ItemStack(var7.itemID, var11, var7.getItemDamage()));
if (var7.hasTagCompound())
{
var12.getEntityItem().setTagCompound((NBTTagCompound) var7.getTagCompound().copy());
}
float var13 = 0.05F;
var12.motionX = ((float) random.nextGaussian() * var13);
var12.motionY = ((float) random.nextGaussian() * var13 + 0.2F);
var12.motionZ = ((float) random.nextGaussian() * var13);
world.spawnEntityInWorld(var12);
}
}
}
}
}
}
@Override @Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int hitSide, float hitX, float hitY, float hitZ) public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int hitSide, float hitX, float hitY, float hitZ)
{ {
@ -49,7 +114,6 @@ public class BlockEngineeringTable extends BlockRI
{ {
if (!world.isRemote) if (!world.isRemote)
{ {
ItemStack current = player.inventory.getCurrentItem(); ItemStack current = player.inventory.getCurrentItem();
Vector2 hitVector = new Vector2(hitX, hitZ); Vector2 hitVector = new Vector2(hitX, hitZ);
@ -77,12 +141,29 @@ public class BlockEngineeringTable extends BlockRI
{ {
if (ControlKeyModifer.isControlDown(player)) if (ControlKeyModifer.isControlDown(player))
{ {
tile.craftingMatrix[slotID] = current; if (checkStack == null)
{
tile.craftingMatrix[slotID] = current;
}
else
{
tile.craftingMatrix[slotID].stackSize += current.stackSize;
current.stackSize = 0;
}
current = null; current = null;
} }
else else
{ {
tile.craftingMatrix[slotID] = current.splitStack(1); if (checkStack == null)
{
tile.craftingMatrix[slotID] = current.splitStack(1);
}
else
{
tile.craftingMatrix[slotID].stackSize++;
current.stackSize--;
}
} }
if (current == null || current.stackSize <= 0) if (current == null || current.stackSize <= 0)
@ -90,6 +171,7 @@ public class BlockEngineeringTable extends BlockRI
player.inventory.setInventorySlotContents(player.inventory.currentItem, null); player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
} }
didInsert = true;
} }
} }
@ -112,14 +194,19 @@ public class BlockEngineeringTable extends BlockRI
} }
else if (hitSide != 0) else if (hitSide != 0)
{ {
ItemStack output = tile.getStackInSlot(9); if (!world.isRemote)
while (output != null && ControlKeyModifer.isControlDown(player))
{ {
InventoryUtility.dropItemStack(world, new Vector3(player), output, 0); ItemStack output = tile.getStackInSlot(9);
tile.onPickUpFromSlot(player, 9, output); boolean firstLoop = true;
tile.setInventorySlotContents(9, null);
output = tile.getStackInSlot(9); while (output != null && (firstLoop || ControlKeyModifer.isControlDown(player)))
{
InventoryUtility.dropItemStack(world, new Vector3(player), output, 0);
tile.onPickUpFromSlot(player, 9, output);
tile.setInventorySlotContents(9, null);
output = tile.getStackInSlot(9);
firstLoop = false;
}
} }
} }
} }

View file

@ -65,7 +65,7 @@ public class RenderEngineeringTable extends TileEntitySpecialRenderer
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240);
this.renderItem(tileEntity.worldObj, ForgeDirection.UP, tile.craftingMatrix[i], new Vector3(), 0, 0); this.renderItem(tileEntity.worldObj, ForgeDirection.UP, tile.craftingMatrix[i], new Vector3(), 0, 0);
GL11.glPopMatrix(); GL11.glPopMatrix();
System.out.println(tile.craftingMatrix[i].stackSize);
if (isLooking) if (isLooking)
RenderUtility.renderFloatingText("" + tile.craftingMatrix[i].stackSize, (float) translation.x, (float) translation.y - 2f, (float) translation.z); RenderUtility.renderFloatingText("" + tile.craftingMatrix[i].stackSize, (float) translation.x, (float) translation.y - 2f, (float) translation.z);
} }
@ -238,7 +238,7 @@ System.out.println(tile.craftingMatrix[i].stackSize);
{ {
if (itemStack != null) if (itemStack != null)
{ {
EntityItem entityitem = new EntityItem(world, 0.0D, 0.0D, 0.0D, itemStack); EntityItem entityitem = new EntityItem(world, 0.0D, 0.0D, 0.0D, itemStack.copy());
entityitem.getEntityItem().stackSize = 1; entityitem.getEntityItem().stackSize = 1;
entityitem.hoverStart = 0.0F; entityitem.hoverStart = 0.0F;
GL11.glPushMatrix(); GL11.glPushMatrix();

View file

@ -104,6 +104,7 @@ public class TileEngineeringTable extends TileAdvanced implements IPacketReceive
if (slot < CRAFTING_MATRIX_END) if (slot < CRAFTING_MATRIX_END)
{ {
this.craftingMatrix[slot] = itemStack; this.craftingMatrix[slot] = itemStack;
System.out.println(worldObj.isRemote+"SET"+this.craftingMatrix[slot]);
} }
else else
{ {
@ -238,7 +239,7 @@ public class TileEngineeringTable extends TileAdvanced implements IPacketReceive
@Override @Override
public void onInventoryChanged() public void onInventoryChanged()
{ {
if (!this.worldObj.isRemote) if (!worldObj.isRemote)
{ {
this.output[craftingOutputSlot] = null; this.output[craftingOutputSlot] = null;
@ -261,23 +262,25 @@ public class TileEngineeringTable extends TileAdvanced implements IPacketReceive
didCraft = true; didCraft = true;
} }
PacketDispatcher.sendPacketToAllPlayers(this.getDescriptionPacket()); worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
} }
} }
@Override @Override
public void onPickUpFromSlot(EntityPlayer entityPlayer, int s, ItemStack itemStack) public void onPickUpFromSlot(EntityPlayer entityPlayer, int s, ItemStack itemStack)
{ {
if (itemStack != null) if (!worldObj.isRemote)
{ {
if (itemStack != null)
Pair<ItemStack, ItemStack[]> idealRecipeItem = this.getCraftingManager().getIdealRecipe(itemStack);
if (idealRecipeItem != null)
{ {
this.getCraftingManager().consumeItems(idealRecipeItem.right().clone()); Pair<ItemStack, ItemStack[]> idealRecipeItem = this.getCraftingManager().getIdealRecipe(itemStack);
}
if (idealRecipeItem != null)
{
this.getCraftingManager().consumeItems(idealRecipeItem.right().clone());
}
}
} }
} }
@ -314,18 +317,18 @@ public class TileEngineeringTable extends TileAdvanced implements IPacketReceive
{ {
super.readFromNBT(nbt); super.readFromNBT(nbt);
NBTTagList var2 = nbt.getTagList("Items"); NBTTagList nbtList = nbt.getTagList("Items");
this.craftingMatrix = new ItemStack[9]; this.craftingMatrix = new ItemStack[9];
this.output = new ItemStack[1]; this.output = new ItemStack[1];
for (int i = 0; i < var2.tagCount(); ++i) for (int i = 0; i < nbtList.tagCount(); ++i)
{ {
NBTTagCompound var4 = (NBTTagCompound) var2.tagAt(i); NBTTagCompound stackTag = (NBTTagCompound) nbtList.tagAt(i);
byte id = var4.getByte("Slot"); byte id = stackTag.getByte("Slot");
if (id >= 0 && id < this.getSizeInventory()) if (id >= 0 && id < this.getSizeInventory())
{ {
this.setInventorySlotContents(id, ItemStack.loadItemStackFromNBT(var4)); this.setInventorySlotContents(id, ItemStack.loadItemStackFromNBT(stackTag));
} }
} }
@ -338,7 +341,7 @@ public class TileEngineeringTable extends TileAdvanced implements IPacketReceive
{ {
super.writeToNBT(nbt); super.writeToNBT(nbt);
NBTTagList var2 = new NBTTagList(); NBTTagList nbtList = new NBTTagList();
for (int i = 0; i < this.getSizeInventory(); ++i) for (int i = 0; i < this.getSizeInventory(); ++i)
{ {
@ -347,11 +350,11 @@ public class TileEngineeringTable extends TileAdvanced implements IPacketReceive
NBTTagCompound var4 = new NBTTagCompound(); NBTTagCompound var4 = new NBTTagCompound();
var4.setByte("Slot", (byte) i); var4.setByte("Slot", (byte) i);
this.getStackInSlot(i).writeToNBT(var4); this.getStackInSlot(i).writeToNBT(var4);
var2.appendTag(var4); nbtList.appendTag(var4);
} }
} }
nbt.setTag("Items", var2); nbt.setTag("Items", nbtList);
nbt.setBoolean("searchInventories", this.searchInventories); nbt.setBoolean("searchInventories", this.searchInventories);
} }