当前位置: 首页>>代码示例>>Java>>正文


Java TileEntityChest.getStackInSlot方法代码示例

本文整理汇总了Java中net.minecraft.tileentity.TileEntityChest.getStackInSlot方法的典型用法代码示例。如果您正苦于以下问题:Java TileEntityChest.getStackInSlot方法的具体用法?Java TileEntityChest.getStackInSlot怎么用?Java TileEntityChest.getStackInSlot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.minecraft.tileentity.TileEntityChest的用法示例。


在下文中一共展示了TileEntityChest.getStackInSlot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getEmptySpace

import net.minecraft.tileentity.TileEntityChest; //导入方法依赖的package包/类
private int getEmptySpace( final TileEntityChest chest, final ItemStack stack ) {
	int temp = -1;

	for ( int i = 0; i < chest.getSizeInventory(); i++ ) {
		final ItemStack stack2 = chest.getStackInSlot( i );

		if ( temp < 0 && (stack2 == null || stack2.stackSize == 0) ) {
			temp = i;
		} else if ( stack2 != null && stack.getItem() == stack2.getItem() && stack2.stackSize > 0
				&& stack2.stackSize + stack.stackSize <= stack.getMaxStackSize() && !stack2.isItemDamaged()
				&& !stack.isItemDamaged() && stack.getItemDamage() == stack2.getItemDamage() ) {
			stack.stackSize += stack2.stackSize;
			return i;
		}
	}

	return temp;
}
 
开发者ID:allaryin,项目名称:FairyFactions,代码行数:19,代码来源:FairyJob.java

示例2: addInformation

import net.minecraft.tileentity.TileEntityChest; //导入方法依赖的package包/类
@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4)
{
	if(!(Keyboard.isKeyDown(42) || Keyboard.isKeyDown(54)))
		list.add("Press SHIFT to see the content.");
	else
	{
		boolean hasItems = false;
		TileEntityChest chest = new TileEntityChest();
		chest.readFromNBT(stack.getTagCompound());
		for(int i = 0; i<chest.getSizeInventory(); i++)
		{
			ItemStack itemStack = chest.getStackInSlot(i);
			if(itemStack != null)
			{
				list.add(itemStack.stackSize + "x" + itemStack.getDisplayName());
				hasItems = true;
			}
			
		}
		if(!hasItems)
			list.add("Empty");
	}
}
 
开发者ID:DjGiannuzz,项目名称:HatChest,代码行数:26,代码来源:ItemHatChest.java

示例3: getStackInSlot

import net.minecraft.tileentity.TileEntityChest; //导入方法依赖的package包/类
@Override
public ItemStack getStackInSlot(int slot)
{
    boolean accessingUpperChest = slot < 27;
    int targetSlot = accessingUpperChest ? slot : slot - 27;
    TileEntityChest chest = getChest(accessingUpperChest);
    return chest != null ? chest.getStackInSlot(targetSlot) : null;
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:9,代码来源:VanillaDoubleChestItemHandler.java

示例4: calculateHoardSize

import net.minecraft.tileentity.TileEntityChest; //导入方法依赖的package包/类
public boolean calculateHoardSize(World world) {
	// Only look for hoards in OverWorld!
	if (world.provider.dimensionId != 0) {
		this.player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chat.wildbill22_draco.hoardsOnlyWorkInOverWorld")));
		return false;
	}
	hoardSize = 0;
	boolean notJustCoins = false;
	this.eggsInHoard.clear();
	int size = hoardList.size();
	for (int i = 0; i < size; i++) {
		TileEntityChest chestEntity = (TileEntityChest) world.getTileEntity(hoardList.get(i).posX, hoardList.get(i).posY, hoardList.get(i).posZ);
		if (chestEntity instanceof TileEntityTemporaryHoard) {
			for (int j = 0; j < chestEntity.getSizeInventory(); j++) {
				ItemStack itemStack = chestEntity.getStackInSlot(j);
				if (itemStack != null) {
					if (itemStack.getItem() != ModItems.goldCoin) {
						notJustCoins = true;
						if (itemStack.getItem() instanceof ItemDragonEgg) {
							this.addEgg(((IDragonEggHandler)itemStack.getItem()).getEggName());
						}
					}
					else {
						hoardSize += itemStack.stackSize;
					}
				}
			}
		}
	}
       LogHelper.info("DragonPlayer load: Player has " + getHoardSize() + " coins.");
       LogHelper.info("DragonPlayer load: Player has " + this.eggsInHoard.size() + " different eggs.");
	if (hoardSize > 0) {
		this.player.addStat(ModStats.firstGoldCoin, 1);
	}
	calculateLevel();
	return notJustCoins;
}
 
开发者ID:DracoAnimus,项目名称:Coding,代码行数:38,代码来源:DragonPlayer.java

示例5: updateEntity

import net.minecraft.tileentity.TileEntityChest; //导入方法依赖的package包/类
@Override
    public void updateEntity() {
        boolean shouldAddBucket = false;
        if (this.worldObj.getBlock(this.xCoord, this.yCoord - 1, this.zCoord) == Blocks.chest && this.fluidLevel >= 1250) {
            TileEntityChest te = (TileEntityChest) this.worldObj.getTileEntity(this.xCoord, this.yCoord - 1, this.zCoord);
            if (this.fluidLevel >= 1250) {
                for (int i = 0; i < 27; i++) {
                    if (te.getStackInSlot(i) != null && te.getStackInSlot(i).getItem() == Items.bucket && te.getStackInSlot(i).stackSize == 1) {
                        te.setInventorySlotContents(i, new ItemStack(ItemHandler.mapleSapBucket));
                        this.fluidLevel -= 1250;
                    } else if (te.getStackInSlot(i) != null && te.getStackInSlot(i).getItem() == Items.bucket && te.getStackInSlot(i).stackSize > 1) {
                        shouldAddBucket = true;
                        te.getStackInSlot(i).stackSize--;
                        int temp = fluidLevel;
                        this.fluidLevel -= 1250;
                        //TODO #TEMP#: For tank debug purposes
                        System.out.println("filling bucket; " + temp + " -> " + fluidLevel);
                    }
                    if (te.getStackInSlot(i) != null && te.getStackInSlot(i).getItem() == ItemHandler.mapleSapBucket && shouldAddBucket && te.getStackInSlot(i).stackSize < 64) {
                        te.getStackInSlot(i).stackSize++;
                        shouldAddBucket = false;
                    } else if (te.getStackInSlot(i) == null && shouldAddBucket) {
                        te.setInventorySlotContents(i, new ItemStack(ItemHandler.mapleSapBucket));
                        shouldAddBucket = false;
                    }
                }
                if (shouldAddBucket) {
                    EntityItem entity = new EntityItem(this.worldObj, this.xCoord, this.yCoord - 1, this.zCoord, new ItemStack(ItemHandler.mapleSapBucket));
                    this.worldObj.spawnEntityInWorld(entity);
//                    this.fluidLevel -= 1250;
                    shouldAddBucket = false;
                }
            }
        }
    }
 
开发者ID:BossLetsPlays,项目名称:WaffleMod,代码行数:36,代码来源:TileEntitySyrupTank.java

示例6: onDeath

import net.minecraft.tileentity.TileEntityChest; //导入方法依赖的package包/类
@Override
public void onDeath(DamageSource source)
{
	super.onDeath(source);
	if(worldObj.isRemote)return;
	
	boolean placeChest = false;
	
	if(!isTitan)return;
	
	
	TileEntityChest chest = getLootChest();
	
	int x = (int)posX;
	int z = (int)posZ;
	for(int y = (int)posY+1; y > 0; y --)
	{
		if(worldObj.getBlockMaterial(x, y, z).isSolid())
		{
			break;
		}
		
		if(tryPlaceChest(x, y, z, chest))
		{
			placeChest = true;
			break;
		}
	}
	
	if(!placeChest)
	{
		for(int a = 0; a < chest.getSizeInventory(); a ++)
		{
			ItemStack drop = chest.getStackInSlot(a);
			if(drop != null)
			this.entityDropItem(drop, 0);
		}
	}
}
 
开发者ID:TheAwesomeGem,项目名称:MineFantasy,代码行数:40,代码来源:EntityMinotaur.java

示例7: dumpFromPlayerToChestEntity

import net.minecraft.tileentity.TileEntityChest; //导入方法依赖的package包/类
public static void dumpFromPlayerToChestEntity(World world, TileEntityChest chest, EntityPlayer player)
	{ 

ItemStack chestItem;
ItemStack invItem;

int START_CHEST = 0; 
int END_CHEST =  START_CHEST + 3*9; 

//inventory and chest has 9 rows by 3 columns, never changes. same as 64 max stack size
for(int islotChest = START_CHEST; islotChest < END_CHEST; islotChest++)
{ 
	chestItem = chest.getStackInSlot(islotChest);

	if(chestItem != null) {   continue; }//  chest slot not empty, skip over it

	for(int islotInv = Const.HOTBAR_SIZE; islotInv < player.inventory.getSizeInventory() - Const.ARMOR_SIZE; islotInv++)
	{
		invItem = player.inventory.getStackInSlot(islotInv);
		
		if(invItem == null)  {continue;}//empty inventory slot
		  
		chest.setInventorySlotContents(islotChest, invItem);
 
				player.inventory.setInventorySlotContents(islotInv,null); 
				break;
			}//close loop on player inventory items 
}//close loop on chest items
	}
 
开发者ID:PrinceOfAmber,项目名称:SamsPowerups,代码行数:30,代码来源:UtilInventory.java

示例8: cleanSlot

import net.minecraft.tileentity.TileEntityChest; //导入方法依赖的package包/类
private void cleanSlot( final TileEntityChest chest, final int p ) {
	if ( chest.getStackInSlot( p ) != null && chest.getStackInSlot( p ).getItem() == null ) {
		chest.setInventorySlotContents( p, (ItemStack) null );
	}
}
 
开发者ID:allaryin,项目名称:FairyFactions,代码行数:6,代码来源:FairyJob.java

示例9: locateStrongholds

import net.minecraft.tileentity.TileEntityChest; //导入方法依赖的package包/类
private void locateStrongholds(EntityPlayer player, int amplifier) {
final NBTCoordinates playerLocation;
TileEntityChest closestChest = null;
float distance;
// Show direction to chests closer than this distance (up to 1000 blocks away with level 10 dragon)
float closestDistance = 10000.0F * amplifier * amplifier; 
boolean foundVillagerSkull = false;

if (player != null){
	playerLocation = new NBTCoordinates((int)player.posX, (int)player.posY, (int)player.posZ);	
	
	for (Object tileEntity : player.worldObj.loadedTileEntityList){
		foundVillagerSkull = false;
		if (tileEntity instanceof TileEntityChest){
			TileEntityChest chestEntity = (TileEntityChest) tileEntity;
			Object chestBlock = player.worldObj.getBlock(chestEntity.xCoord, chestEntity.yCoord, chestEntity.zCoord);
			if (chestBlock instanceof BlockChest && chestEntity.yCoord < 45){
				for (int j = 0; j < chestEntity.getSizeInventory(); j++) {
					ItemStack itemStack = chestEntity.getStackInSlot(j);
					if (itemStack != null) {
						if (itemStack.getItem() == ModItems.villagerSkull) {
							foundVillagerSkull = true;
							break;
						}
					}
				}
				if (foundVillagerSkull) {
					NBTCoordinates chestLocation = new NBTCoordinates(chestEntity.xCoord, chestEntity.yCoord, chestEntity.zCoord);
					distance = chestLocation.getDistanceSquaredToChunkCoordinates(playerLocation);
					if (distance < closestDistance){
						closestDistance = distance;
						closestChest = chestEntity; 
					}
				}
			}
		}
	}
	if (closestChest != null){
		// TODO: Animate with a beeping sound (or flashing) when pointing to chest!
		LogHelper.info("Nearest chest at: " + closestChest.xCoord + "," + closestChest.yCoord + "," + closestChest.zCoord + "!");
		player.addChatMessage(new ChatComponentText(
				StatCollector.translateToLocal("chat.wildbill22_draco.foundPossibleStrongholdChest")));				
		player.addChatMessage(new ChatComponentText(
				StatCollector.translateToLocalFormatted("chat.wildbill22_draco.chestIsLocated", closestChest.xCoord, closestChest.yCoord, closestChest.zCoord)));				
	}
	else { 
		LogHelper.info("No stronghold chests nearby");
		player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chat.wildbill22_draco.noStrongholdChestsNearby")));
	}
}		
  }
 
开发者ID:DracoAnimus,项目名称:Coding,代码行数:52,代码来源:ItemDragonStaff.java

示例10: goldenEye

import net.minecraft.tileentity.TileEntityChest; //导入方法依赖的package包/类
private void goldenEye(EntityPlayer player, int amplifier) {
final NBTCoordinates playerLocation;
TileEntityChest closestChest = null;
float distance;
// Show direction to chests closer than this distance (up to 1000 blocks away with level 10 dragon)
float closestDistance = 10000.0F * amplifier * amplifier; 
boolean foundCoins = false;

if (player != null){
	playerLocation = new NBTCoordinates((int)player.posX, (int)player.posY, (int)player.posZ);	
	
	for (Object tileEntity : player.worldObj.loadedTileEntityList){
		foundCoins = false;
		if (tileEntity instanceof TileEntityChest && !(tileEntity instanceof TileEntityTemporaryHoard)){
			TileEntityChest chestEntity = (TileEntityChest) tileEntity;
			Object chestBlock = player.worldObj.getBlock(chestEntity.xCoord, chestEntity.yCoord, chestEntity.zCoord);
			if (chestBlock instanceof BlockChest){
				for (int j = 0; j < chestEntity.getSizeInventory(); j++) {
					ItemStack itemStack = chestEntity.getStackInSlot(j);
					if (itemStack != null) {
						if (itemStack.getItem() == ModItems.goldCoin) {
							foundCoins = true;
							break;
						}
					}
				}
				if (foundCoins) {
					NBTCoordinates chestLocation = new NBTCoordinates(chestEntity.xCoord, chestEntity.yCoord, chestEntity.zCoord);
					distance = chestLocation.getDistanceSquaredToChunkCoordinates(playerLocation);
					if (distance < closestDistance){
						closestDistance = distance;
						closestChest = chestEntity; 
					}
				}
			}
		}
	}
	if (closestChest != null){
		// TODO: Animate with a beeping sound (or flashing) when pointing to chest!
		LogHelper.info("Nearest chest at: " + closestChest.xCoord + "," + closestChest.yCoord + "," + closestChest.zCoord + "!");
		player.addChatMessage(new ChatComponentText(
				StatCollector.translateToLocalFormatted("chat.wildbill22_draco.foundGoldCoinsAt", closestChest.xCoord, closestChest.yCoord, closestChest.zCoord)));				
	}
	else { 
		LogHelper.info("No gold coins found nearby");
		player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chat.wildbill22_draco.noGoldCoinsFound")));
	}
}		
  }
 
开发者ID:DracoAnimus,项目名称:Coding,代码行数:50,代码来源:ItemDragonStaff.java

示例11: breakBlock

import net.minecraft.tileentity.TileEntityChest; //导入方法依赖的package包/类
public void breakBlock(World p_149749_1_, int p_149749_2_, int p_149749_3_, int p_149749_4_, Block p_149749_5_, int p_149749_6_)
{
    TileEntityChest var7 = (TileEntityChest)p_149749_1_.getTileEntity(p_149749_2_, p_149749_3_, p_149749_4_);

    if (var7 != null)
    {
        for (int var8 = 0; var8 < var7.getSizeInventory(); ++var8)
        {
            ItemStack var9 = var7.getStackInSlot(var8);

            if (var9 != null)
            {
                float var10 = this.field_149955_b.nextFloat() * 0.8F + 0.1F;
                float var11 = this.field_149955_b.nextFloat() * 0.8F + 0.1F;
                EntityItem var14;

                for (float var12 = this.field_149955_b.nextFloat() * 0.8F + 0.1F; var9.stackSize > 0; p_149749_1_.spawnEntityInWorld(var14))
                {
                    int var13 = this.field_149955_b.nextInt(21) + 10;

                    if (var13 > var9.stackSize)
                    {
                        var13 = var9.stackSize;
                    }

                    var9.stackSize -= var13;
                    var14 = new EntityItem(p_149749_1_, (double)((float)p_149749_2_ + var10), (double)((float)p_149749_3_ + var11), (double)((float)p_149749_4_ + var12), new ItemStack(var9.getItem(), var13, var9.getItemDamage()));
                    float var15 = 0.05F;
                    var14.motionX = (double)((float)this.field_149955_b.nextGaussian() * var15);
                    var14.motionY = (double)((float)this.field_149955_b.nextGaussian() * var15 + 0.2F);
                    var14.motionZ = (double)((float)this.field_149955_b.nextGaussian() * var15);

                    if (var9.hasTagCompound())
                    {
                        var14.getEntityItem().setTagCompound((NBTTagCompound)var9.getTagCompound().copy());
                    }
                }
            }
        }

        p_149749_1_.func_147453_f(p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_);
    }

    super.breakBlock(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_, p_149749_6_);
}
 
开发者ID:MinecraftModdedClients,项目名称:Resilience-Client-Source,代码行数:46,代码来源:BlockChest.java

示例12: sortFromPlayerToChestEntity

import net.minecraft.tileentity.TileEntityChest; //导入方法依赖的package包/类
public void sortFromPlayerToChestEntity(World world, TileEntityChest chest, EntityPlayer entityPlayer)
	{ 
		int totalItemsMoved = 0; 
		int totalSlotsFreed = 0;
		 
ItemStack chestItem;
ItemStack invItem;
int room;
int toDeposit;
int chestMax;

//player inventory and the small chest have the same dimensions 

int START_CHEST = 0; 
int END_CHEST =  START_CHEST + 3*9; 

//inventory and chest has 9 rows by 3 columns, never changes. same as 64 max stack size
for(int islotChest = START_CHEST; islotChest < END_CHEST; islotChest++)
{ 
	chestItem = chest.getStackInSlot(islotChest);

	if(chestItem == null)
	{  
		continue;
	}//not an error; empty chest slot
	 
	for(int islotInv = PlayerInventory.START; islotInv < PlayerInventory.END; islotInv++)
			{ 
		invItem = entityPlayer.inventory.getStackInSlot(islotInv);
		
		if(invItem == null) 
		{ 
			continue;
	    }//empty inventory slot
 
				if( invItem.getItem().equals(chestItem.getItem()) && invItem.getItemDamage() ==  chestItem.getItemDamage() )
				{  
					//same item, including damage (block state)
					
					chestMax = chestItem.getItem().getItemStackLimit(chestItem);
					room = chestMax - chestItem.stackSize;
					 
					if(room <= 0) {continue;} // no room, check the next spot
			 
					//so if i have 30 room, and 28 items, i deposit 28.
					//or if i have 30 room and 38 items, i deposit 30
					toDeposit = Math.min(invItem.stackSize,room);
 
					chestItem.stackSize += toDeposit;
					chest.setInventorySlotContents(islotChest, chestItem);

					invItem.stackSize -= toDeposit;

					totalItemsMoved += toDeposit;
					//totalTypesMoved++;
					
					if(invItem.stackSize <= 0)//because of calculations above, should not be below zero
					{
						//item stacks with zero count do not destroy themselves, they show up and have unexpected behavior in game so set to empty
						entityPlayer.inventory.setInventorySlotContents(islotInv,null); 
						
						totalSlotsFreed++;
					}
					else
					{
						//set to new quantity
	  					entityPlayer.inventory.setInventorySlotContents(islotInv, invItem); 
					} 
				}//end if items match   
			}//close loop on player inventory items 
}//close loop on chest items
 
if( totalSlotsFreed > 0) 
{ 
	 
//particles dont work, this only happens on server side (remote==false always)
	//SamsUtilities.spawnParticle(world,EnumParticleTypes.SLIME,chest.getPos().up()); 
}
	}
 
开发者ID:PrinceOfAmber,项目名称:SamsPowerups,代码行数:80,代码来源:SpellChestDeposit.java

示例13: cast

import net.minecraft.tileentity.TileEntityChest; //导入方法依赖的package包/类
@Override
public void cast(World world, EntityPlayer player, BlockPos pos)
{
	TileEntityChest chestTarget = (TileEntityChest)world.getTileEntity(pos);

	if(chestTarget == null)//should never happen, assuming the canPlayerCast was run
	{
		onCastFailure(world,player,pos);
		return;
	}//wrong type of tile entity
	
	//TODO:  make it also work with trapped chests/dispensers/droppers/ etc. set extra flag to identify
	//means not just TileEntityChest
	//chestTarget.getInventoryStackLimit()//=64
	//chestContents.size internally is 27
	ItemStack chestItem;  
	//int chestMax;
	 
	int ROWS = 3;
	int COLS = 9;
	int START_CHEST = 0;
	//int START_INV = 9;//because we are ignoring the item hotbar, we skip the first row this way
	int END_CHEST =  START_CHEST + ROWS * COLS;
	//int END_INV = START_INV + ROWS * COLS;

	ItemStack drop = new ItemStack(ItemRegistry.itemChestSack ,1,0); 
	
	if(drop.getTagCompound() == null)  drop.setTagCompound(new NBTTagCompound());

	int stacks = 0;
	int count = 0;
	
	int[] itemids = new int[END_CHEST - START_CHEST];
	int[] itemqty = new int[END_CHEST - START_CHEST];		
	int[] itemdmg = new int[END_CHEST - START_CHEST];
	
	//inventory and chest has 9 rows by 3 columns, never changes. same as 64 max stack size
	for(int islotChest = START_CHEST; islotChest < END_CHEST; islotChest++)
	{
		//zeroes to avoid nulls, and signify nothing goes there
		itemids[islotChest] = 0;
		itemqty[islotChest] = 0;
		itemids[islotChest] = 0;
		chestItem = chestTarget.getStackInSlot(islotChest);
	
		if(chestItem == null){continue;}//not an error; empty chest slot
		if(chestItem.getTagCompound() != null)
		{
			//probably has an enchantment
			player.dropPlayerItemWithRandomChoice(chestItem, false); 
		}
		else
		{
			stacks++; 
			count += chestItem.stackSize;
			
			itemids[islotChest] = Item.getIdFromItem(chestItem.getItem());
			itemdmg[islotChest] = chestItem.getItemDamage(); 
			itemqty[islotChest] = chestItem.stackSize;
			
		}
		//its either in the bag, or dropped on the player
		chestTarget.setInventorySlotContents(islotChest, null);	
	}
	 
	if(drop.getTagCompound() == null) drop.setTagCompound(new NBTTagCompound());
	
	drop.getTagCompound().setIntArray("itemids", itemids);
	drop.getTagCompound().setIntArray("itemdmg", itemdmg);
	drop.getTagCompound().setIntArray("itemqty", itemqty);
	 
	drop.getTagCompound().setString("count",""+count);
	drop.getTagCompound().setString("stacks",""+stacks);
 	 
	player.entityDropItem(drop, 1); 
		 
	 //the 2 here is just a magic flag it passes to the world to propogate the event

	world.setBlockToAir(pos); 

}
 
开发者ID:PrinceOfAmber,项目名称:SamsPowerups,代码行数:82,代码来源:SpellChestTransport.java

示例14: sortFromPlayerToChestEntity

import net.minecraft.tileentity.TileEntityChest; //导入方法依赖的package包/类
public static void sortFromPlayerToChestEntity(World world, TileEntityChest chest, EntityPlayer player)
	{ 
//source: https://github.com/PrinceOfAmber/SamsPowerups/blob/master/Spells/src/main/java/com/lothrazar/samsmagic/spell/SpellChestDeposit.java#L84

ItemStack chestItem;
ItemStack invItem;
int room;
int toDeposit;
int chestMax;

//player inventory and the small chest have the same dimensions 

int START_CHEST = 0; 
int END_CHEST =  START_CHEST + 3*9; 

//inventory and chest has 9 rows by 3 columns, never changes. same as 64 max stack size
for(int islotChest = START_CHEST; islotChest < END_CHEST; islotChest++)
{ 
	chestItem = chest.getStackInSlot(islotChest);

	if(chestItem == null) {   continue; }//  empty chest slot
	 
	for(int islotInv = Const.HOTBAR_SIZE; islotInv < player.inventory.getSizeInventory() - Const.ARMOR_SIZE; islotInv++)
	{
	 
		invItem = player.inventory.getStackInSlot(islotInv);
		
		if(invItem == null)  {continue;}//empty inventory slot
 
				if( invItem.getItem().equals(chestItem.getItem()) && invItem.getItemDamage() ==  chestItem.getItemDamage() )
				{  
					//same item, including damage (block state)
					
					chestMax = chestItem.getItem().getItemStackLimit(chestItem);
					room = chestMax - chestItem.stackSize;
					 
					if(room <= 0) {continue;} // no room, check the next spot
			 
					//so if i have 30 room, and 28 items, i deposit 28.
					//or if i have 30 room and 38 items, i deposit 30
					toDeposit = Math.min(invItem.stackSize,room);
 
					chestItem.stackSize += toDeposit;
					chest.setInventorySlotContents(islotChest, chestItem);

					invItem.stackSize -= toDeposit;

					if(invItem.stackSize <= 0)//because of calculations above, should not be below zero
					{
						//item stacks with zero count do not destroy themselves, they show up and have unexpected behavior in game so set to empty
						player.inventory.setInventorySlotContents(islotInv,null); 
					}
					else
					{
						//set to new quantity
	  					player.inventory.setInventorySlotContents(islotInv, invItem); 
					} 
				}//end if items match   
			}//close loop on player inventory items 
}//close loop on chest items
	}
 
开发者ID:PrinceOfAmber,项目名称:SamsPowerups,代码行数:62,代码来源:UtilInventory.java

示例15: breakBlock

import net.minecraft.tileentity.TileEntityChest; //导入方法依赖的package包/类
public void breakBlock(World p_149749_1_, int p_149749_2_, int p_149749_3_, int p_149749_4_, Block p_149749_5_, int p_149749_6_)
{
    TileEntityChest tileentitychest = (TileEntityChest)p_149749_1_.getTileEntity(p_149749_2_, p_149749_3_, p_149749_4_);

    if (tileentitychest != null)
    {
        for (int i1 = 0; i1 < tileentitychest.getSizeInventory(); ++i1)
        {
            ItemStack itemstack = tileentitychest.getStackInSlot(i1);

            if (itemstack != null)
            {
                float f = this.field_149955_b.nextFloat() * 0.8F + 0.1F;
                float f1 = this.field_149955_b.nextFloat() * 0.8F + 0.1F;
                EntityItem entityitem;

                for (float f2 = this.field_149955_b.nextFloat() * 0.8F + 0.1F; itemstack.stackSize > 0; p_149749_1_.spawnEntityInWorld(entityitem))
                {
                    int j1 = this.field_149955_b.nextInt(21) + 10;

                    if (j1 > itemstack.stackSize)
                    {
                        j1 = itemstack.stackSize;
                    }

                    itemstack.stackSize -= j1;
                    entityitem = new EntityItem(p_149749_1_, (double)((float)p_149749_2_ + f), (double)((float)p_149749_3_ + f1), (double)((float)p_149749_4_ + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
                    float f3 = 0.05F;
                    entityitem.motionX = (double)((float)this.field_149955_b.nextGaussian() * f3);
                    entityitem.motionY = (double)((float)this.field_149955_b.nextGaussian() * f3 + 0.2F);
                    entityitem.motionZ = (double)((float)this.field_149955_b.nextGaussian() * f3);

                    if (itemstack.hasTagCompound())
                    {
                        entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
                    }
                }
            }
        }

        p_149749_1_.func_147453_f(p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_);
    }

    super.breakBlock(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_, p_149749_6_);
}
 
开发者ID:xtrafrancyz,项目名称:Cauldron,代码行数:46,代码来源:BlockChest.java


注:本文中的net.minecraft.tileentity.TileEntityChest.getStackInSlot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。