本文整理汇总了Java中net.minecraft.tileentity.TileEntityChest.setInventorySlotContents方法的典型用法代码示例。如果您正苦于以下问题:Java TileEntityChest.setInventorySlotContents方法的具体用法?Java TileEntityChest.setInventorySlotContents怎么用?Java TileEntityChest.setInventorySlotContents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.tileentity.TileEntityChest
的用法示例。
在下文中一共展示了TileEntityChest.setInventorySlotContents方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: postAddition
import net.minecraft.tileentity.TileEntityChest; //导入方法依赖的package包/类
@Override
public void postAddition(World world, BlockPos pos, Random random) {
pos = pos.subtract(originAddition);
world.setBlockState(pos, Blocks.CHEST.getDefaultState().withProperty(BlockChest.FACING, EnumFacing.HORIZONTALS[random.nextInt(4)]), 3);
if(world instanceof WorldServer && world.getTileEntity(pos) != null)
{
TileEntityChest chest = (TileEntityChest)world.getTileEntity(pos);
chest.setInventorySlotContents(13, HarshenUtils.getItemsFromLootTable(world, HarshenLootTables.shrine).get(0));
for(ItemStack stack : HarshenUtils.getItemsFromLootPool(world, HarshenLootTables.shrine, "extras"))
for(int count = 0; count < stack.getCount(); count++)
{
int slot = new Random().nextInt(27);
while(chest.getStackInSlot(slot).getItem() != Item.getItemFromBlock(Blocks.AIR))
slot = new Random().nextInt(27);
ItemStack stack1 = stack.copy();
stack1.setCount(1);
chest.setInventorySlotContents(slot, stack1);
}
}
}
示例2: generateChestContents
import net.minecraft.tileentity.TileEntityChest; //导入方法依赖的package包/类
/** Generate chest contents */
public static void generateChestContents(Random random, List<WeightedRandomChestContent> listIn, TileEntityChest dispenser, int max)
{
for (int i = 0; i < max; ++i)
{
WeightedRandomChestContent weightedrandomchestcontent = WeightedRandom.getRandomItem(random, listIn);
int j = weightedrandomchestcontent.minStackSize + random.nextInt(weightedrandomchestcontent.maxStackSize - weightedrandomchestcontent.minStackSize + 1);
if (weightedrandomchestcontent.theItemId.getMaxStackSize() >= j)
{
ItemStack itemstack1 = weightedrandomchestcontent.theItemId.copy();
itemstack1.stackSize = j;
dispenser.setInventorySlotContents(random.nextInt(dispenser.getSizeInventory()), itemstack1);
}
else
{
for (int k = 0; k < j; ++k)
{
ItemStack itemstack = weightedrandomchestcontent.theItemId.copy();
itemstack.stackSize = 1;
dispenser.setInventorySlotContents(random.nextInt(dispenser.getSizeInventory()), itemstack);
}
}
}
}
示例3: checkRemoteStorage
import net.minecraft.tileentity.TileEntityChest; //导入方法依赖的package包/类
public void checkRemoteStorage() {
if (remoteX != 0 && remoteY != 0 && remoteZ != 0 && !inventory.get(itemTradeSlot).isEmpty()) {
for (int i = itemStorageSlot1; i <= itemStorageSlot9; i++) {
if (inventory.get(i).isEmpty()) {
loadRemoteChunk(remoteX, remoteY, remoteZ);
TileEntity te = world.getTileEntity(new BlockPos(remoteX, remoteY, remoteZ));
if (te != null && te instanceof TileEntityChest) {
TileEntityChest chest = (TileEntityChest) te;
for (int j = 0; j < chest.getSizeInventory(); j++) {
if (inventory.get(i).isEmpty() && !chest.getStackInSlot(j).isEmpty()
&& chest.getStackInSlot(j).getItem() == inventory.get(itemTradeSlot).getItem()) {
inventory.set(i, chest.getStackInSlot(j));
chest.setInventorySlotContents(j, ItemStack.EMPTY);
checkSellingInventory();
}
}
}
}
}
}
}
示例4: convert
import net.minecraft.tileentity.TileEntityChest; //导入方法依赖的package包/类
@Override
public boolean convert(EntityPlayer player, World world, int x, int y, int z)
{
TileEntityChest chest = (TileEntityChest)world.getTileEntity(x, y, z);
NBTTagCompound tag = new NBTTagCompound();
int newMeta = world.getBlockMetadata(x, y, z);
chest.writeToNBT(tag);
for(int i = 0; i < chest.getSizeInventory(); i++)
{
chest.setInventorySlotContents(i, null);
}
world.setBlock(x, y, z, SCContent.keypadChest, newMeta, 3);
world.setBlockMetadataWithNotify(x, y, z, newMeta, 3);
((IOwnable) world.getTileEntity(x, y, z)).getOwner().set(player.getCommandSenderName(), player.getUniqueID().toString());
((TileEntityChest)world.getTileEntity(x, y, z)).readFromNBT(tag);
return true;
}
示例5: fill_chest
import net.minecraft.tileentity.TileEntityChest; //导入方法依赖的package包/类
void fill_chest(TileEntityChest chest, Random rand)
{
chest.setInventorySlotContents(rand.nextInt(chest.getSizeInventory() - 1), new ItemStack(Blocks.enchanting_table, 1));
for (int i = 0; i < 6 + rand.nextInt(10); i++)
{
chest.setInventorySlotContents(rand.nextInt(chest.getSizeInventory() - 1), getRandomItemStack(rand));
}
}
示例6: collectGoodies
import net.minecraft.tileentity.TileEntityChest; //导入方法依赖的package包/类
private boolean collectGoodies( final TileEntityChest chest, final World world ) {
int count = 0;
for ( int i = 0; i < goodies.size() && count < 3; i++ ) {
final EntityItem entity = (EntityItem) goodies.get( i );
final ItemStack stack = entity.getEntityItem();
final int emptySpace = getEmptySpace( chest, stack );
if ( emptySpace >= 0 ) {
chest.setInventorySlotContents( emptySpace, stack );
entity.setDead();
count++;
}
}
if ( count > 0 ) {
world.playSoundAtEntity( fairy, "random.pop", 0.4F,
((fairy.getRNG().nextFloat() - fairy.getRNG().nextFloat()) * 0.7F + 1.0F) * 2.0F );
fairy.armSwing( !fairy.didSwing );
fairy.attackTime = 1;
// if(fairy.flymode() && fairy.flyTime > 0) {
// fairy.flyTime = 0;
// }
return true;
}
return false;
}
示例7: createChest
import net.minecraft.tileentity.TileEntityChest; //导入方法依赖的package包/类
private boolean createChest(World world, int signX, int signY, int signZ, Random random) {
int x = signX + random.nextInt(this.maxChestDist) - random.nextInt(this.maxChestDist);
int y = signY - random.nextInt(10);
int z = signZ + random.nextInt(this.maxChestDist) - random.nextInt(this.maxChestDist);
for (int i = 0; i < 10; ++i) {
if ((world.getBlock(x, y, z).isNormalCube()) && (world.getBlock(x, y + 1, z).isNormalCube()) && (world.getBlock(x - 1, y, z).isNormalCube()) && (world.getBlock(x + 1, y, z).isNormalCube()) && (world.getBlock(x, y, z - 1).isNormalCube()) && (world.getBlock(x, y, z + 1).isNormalCube())) {
world.setBlock(x, y, z, Blocks.chest);
TileEntityChest tileentitychest = (TileEntityChest) world.getTileEntity(x, y, z);
if (tileentitychest == null) {
break;
}
for (int a = 0; a < 5; ++a) {
ItemStack itemstack = getLoot(random);
if (itemstack == null)
continue;
tileentitychest.setInventorySlotContents(random.nextInt(tileentitychest.getSizeInventory()), itemstack);
}
return true;
}
if (world.getBlock(x, y, z) == Blocks.water) {
x = signX + random.nextInt(this.maxChestDist) - random.nextInt(this.maxChestDist);
y = signY;
z = signZ + random.nextInt(this.maxChestDist) - random.nextInt(this.maxChestDist);
} else {
y -= 3;
}
}
return false;
}
示例8: 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;
}
}
}
}
示例9: 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
}
示例10: generateScrolls
import net.minecraft.tileentity.TileEntityChest; //导入方法依赖的package包/类
public static void generateScrolls(Random random, TileEntityChest chest, int element, int fortune){
int numScrolls = 1;
switch(fortune){
case 1:
numScrolls = 0 + random.nextInt(2);
break;
case 2:
numScrolls = 0 + random.nextInt(3);
break;
case 3:
numScrolls = 1 + random.nextInt(2);
break;
case 4:
numScrolls = 2 + random.nextInt(3);
break;
case 5:
numScrolls = 3 + random.nextInt(2);
break;
}
for(int i = 0; i < numScrolls; i++){
int slot = random.nextInt(27);
int randomNext = random.nextInt(100);
int level = 0;
if(randomNext > 0){
level = 0;
if(randomNext > 70){
level = 1;
if(randomNext > 95){
level = 2;
}
}
}
chest.setInventorySlotContents(slot, getRandomScroll(random, element, level));
}
}
示例11: 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 );
}
}
示例12: updateTick
import net.minecraft.tileentity.TileEntityChest; //导入方法依赖的package包/类
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
if (!world.isRemote) {
int i = pos.getX();
int j = pos.getY();
int k = pos.getZ();
WarsMod.generateBlock(world, i, j + 1, k, Blocks.CHEST);
TileEntityChest chest2 = new TileEntityChest();
BlockPos chestPos = new BlockPos(i, j + 1, k);
world.setTileEntity(chestPos, chest2);
Random random = new Random();
for (int slot = 0; slot < 1; slot++) {
int num = random.nextInt(30);
if (num == 1) {
chest2.setInventorySlotContents(slot, new ItemStack(Items.CHICKEN));
}
if (num == 2) {
chest2.setInventorySlotContents(slot, new ItemStack(WarsItems.magicPotato));
}
if (num == 3) {
chest2.setInventorySlotContents(slot, new ItemStack(Items.BEEF));
}
if (num == 4) {
chest2.setInventorySlotContents(slot, new ItemStack(Items.ENDER_PEARL));
}
if (num == 5) {
chest2.setInventorySlotContents(slot, new ItemStack(Items.BEEF));
}
if (num == 6) {
chest2.setInventorySlotContents(slot, new ItemStack(WarsItems.battleBurger));
}
if (num == 7) {
chest2.setInventorySlotContents(slot, new ItemStack(WarsItems.longBannana));
}
if (num == 8) {
chest2.setInventorySlotContents(slot, new ItemStack(WarsItems.workWaffel));
}
if (num == 9) {
chest2.setInventorySlotContents(slot, new ItemStack(WarsItems.shadowFlesh));
}
if (num == 10) {
chest2.setInventorySlotContents(slot, new ItemStack(WarsItems.warCheese));
}
if (num == 11) {
chest2.setInventorySlotContents(slot, new ItemStack(Items.FISH));
}
if (num == 12) {
chest2.setInventorySlotContents(slot, new ItemStack(Items.MELON));
}
if (num == 13) {
chest2.setInventorySlotContents(slot, new ItemStack(Items.ROTTEN_FLESH));
}
if (num == 14) {
chest2.setInventorySlotContents(slot, new ItemStack(Items.PORKCHOP));
}
if (num == 15) {
chest2.setInventorySlotContents(slot, new ItemStack(Items.SPIDER_EYE));
}
if (num == 16) {
chest2.setInventorySlotContents(slot, new ItemStack(Items.COOKIE));
}
if (num == 17) {
chest2.setInventorySlotContents(slot, new ItemStack(WarsItems.antidote));
}
WarsMod.generateBlock(world, i, j + 1, k, Blocks.STONE);
WarsMod.generateBlock(world, i, j + 1, k, Blocks.AIR);
}
}
}
示例13: GenSkyblock
import net.minecraft.tileentity.TileEntityChest; //导入方法依赖的package包/类
public GenSkyblock(EntityPlayer player, int i, int j, int k) {
ResinresinLoader skyBlock = new ResinresinLoader("skyBlock.resinresin");
skyBlock.generate(player.worldObj, i + -9, j, k + -9, true);
WarsMod.generateBlock(player.worldObj, i + 2, j + 65, k + -1, Blocks.SAND);
WarsMod.generateBlock(player.worldObj, i + 1, j + 65, k + -1, Blocks.SAND);
WarsMod.generateBlock(player.worldObj, i, j + 65, k + -1, Blocks.SAND);
WarsMod.generateBlock(player.worldObj, i + 3, j + 67, k + -2, Blocks.CHEST);
TileEntityChest chest2 = new TileEntityChest();
BlockPos chestPos1 = new BlockPos(i + 3, j + 67, k + -2);
player.worldObj.setTileEntity(chestPos1, chest2);
TileEntityChest tileentitychest = (TileEntityChest)player.worldObj.getTileEntity(chestPos1);
if (tileentitychest != null && tileentitychest.getSizeInventory() > 0) {
ItemStack itemstack = new ItemStack(Items.STRING, 12);
tileentitychest.setInventorySlotContents(0, itemstack);
ItemStack itemstack1 = new ItemStack(Items.BUCKET, 1);
tileentitychest.setInventorySlotContents(1, itemstack1);
ItemStack itemstack2 = new ItemStack(Items.BONE, 1);
tileentitychest.setInventorySlotContents(2, itemstack2);
ItemStack itemstack3 = new ItemStack(Items.REEDS, 1);
tileentitychest.setInventorySlotContents(3, itemstack3);
ItemStack itemstack4 = new ItemStack(Blocks.RED_MUSHROOM, 1);
tileentitychest.setInventorySlotContents(9, itemstack4);
ItemStack itemstack5 = new ItemStack(Blocks.ICE, 2);
tileentitychest.setInventorySlotContents(10, itemstack5);
ItemStack itemstack6 = new ItemStack(Items.PUMPKIN_SEEDS, 1);
tileentitychest.setInventorySlotContents(11, itemstack6);
ItemStack itemstack7 = new ItemStack(Blocks.BROWN_MUSHROOM, 1);
tileentitychest.setInventorySlotContents(18, itemstack7);
ItemStack itemstack8 = new ItemStack(Items.MELON, 1);
tileentitychest.setInventorySlotContents(19, itemstack8);
ItemStack itemstack9 = new ItemStack(Blocks.CACTUS, 1);
tileentitychest.setInventorySlotContents(20, itemstack9);
WarsMod.generateBlock(player.worldObj, i + 1, j + 1, k, Blocks.CHEST);
TileEntityChest chest3 = new TileEntityChest();
BlockPos chestPos2 = new BlockPos(i + 1, j + 1, k);
player.worldObj.setTileEntity(chestPos2, chest3);
TileEntityChest tileentitychest1 = (TileEntityChest)player.worldObj.getTileEntity(chestPos2);
if (tileentitychest1 != null && tileentitychest1.getSizeInventory() > 0) {
ItemStack itemstack15 = new ItemStack(Items.BOAT, 4);
tileentitychest1.setInventorySlotContents(0, itemstack15);
}
}
}
示例14: 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());
}
}
示例15: 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);
}