本文整理汇总了Java中net.minecraft.item.ItemStack.splitStack方法的典型用法代码示例。如果您正苦于以下问题:Java ItemStack.splitStack方法的具体用法?Java ItemStack.splitStack怎么用?Java ItemStack.splitStack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.item.ItemStack
的用法示例。
在下文中一共展示了ItemStack.splitStack方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: spawnItemStack
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public static void spawnItemStack(World worldIn, double x, double y, double z, ItemStack stack)
{
float f = RANDOM.nextFloat() * 0.8F + 0.1F;
float f1 = RANDOM.nextFloat() * 0.8F + 0.1F;
float f2 = RANDOM.nextFloat() * 0.8F + 0.1F;
while (stack.stackSize > 0)
{
int i = RANDOM.nextInt(21) + 10;
EntityItem entityitem = new EntityItem(worldIn, x + (double)f, y + (double)f1, z + (double)f2, stack.splitStack(i));
float f3 = 0.05F;
entityitem.motionX = RANDOM.nextGaussian() * 0.05000000074505806D;
entityitem.motionY = RANDOM.nextGaussian() * 0.05000000074505806D + 0.20000000298023224D;
entityitem.motionZ = RANDOM.nextGaussian() * 0.05000000074505806D;
worldIn.spawnEntityInWorld(entityitem);
}
}
示例2: buildSupport
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private void buildSupport(BlockPos pos, EntityItem entityItem) {
ItemStack blockStack = entityItem.getItem();
ItemStack actual = blockStack.splitStack(1);
if (blockStack.isEmpty()) {
entityItem.setDead();
}
if (actual.isEmpty()) {
return;
}
Item item = actual.getItem();
if (!(item instanceof ItemBlock)) {
// Safety
return;
}
IMeeCreep entity = helper.getMeeCreep();
World world = entity.getWorld();
Block block = ((ItemBlock) item).getBlock();
IBlockState stateForPlacement = block.getStateForPlacement(world, pos, EnumFacing.UP, 0, 0, 0, item.getMetadata(actual), GeneralTools.getHarvester(), EnumHand.MAIN_HAND);
world.setBlockState(pos, stateForPlacement, 3);
SoundTools.playSound(world, block.getSoundType().getPlaceSound(), pos.getX(), pos.getY(), pos.getZ(), 1.0f, 1.0f);
}
示例3: buildSupport
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private void buildSupport(BlockPos pos, EntityItem entityItem) {
IMeeCreep entity = helper.getMeeCreep();
ItemStack blockStack = entityItem.getItem();
ItemStack actual = blockStack.splitStack(1);
if (blockStack.isEmpty()) {
entityItem.setDead();
}
if (actual.isEmpty()) {
return;
}
Item item = actual.getItem();
if (!(item instanceof ItemBlock)) {
// Safety
return;
}
World world = entity.getWorld();
Block block = ((ItemBlock) item).getBlock();
IBlockState stateForPlacement = block.getStateForPlacement(world, pos, EnumFacing.UP, 0, 0, 0, item.getMetadata(actual), GeneralTools.getHarvester(), EnumHand.MAIN_HAND);
world.setBlockState(pos, stateForPlacement, 3);
SoundTools.playSound(world, block.getSoundType().getPlaceSound(), pos.getX(), pos.getY(), pos.getZ(), 1.0f, 1.0f);
}
示例4: collectCobble
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private void collectCobble(EntityItem entityItem) {
ItemStack blockStack = entityItem.getItem();
ItemStack actual = blockStack.splitStack(6);
if (blockStack.isEmpty()) {
entityItem.setDead();
}
if (actual.isEmpty()) {
return;
}
Item item = actual.getItem();
if (!(item instanceof ItemBlock)) {
// Safety
return;
}
numCobble += actual.getCount();
}
示例5: placeStair
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private void placeStair(EnumFacing facing, BlockPos pos, EntityItem entityItem) {
ItemStack blockStack = entityItem.getItem();
ItemStack actual = blockStack.splitStack(32);
numStairs += 32;
if (blockStack.isEmpty()) {
entityItem.setDead();
}
if (actual.isEmpty()) {
return;
}
Item item = actual.getItem();
if (!(item instanceof ItemBlock)) {
// Safety
return;
}
placeStair(facing, pos);
}
示例6: replant
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private void replant(BlockPos pos) {
IMeeCreep entity = helper.getMeeCreep();
World world = entity.getWorld();
Block block = needToReplant.get(pos);
needToReplant.remove(pos);
for (ItemStack stack : entity.getInventory()) {
if (stack.getItem() instanceof IPlantable) {
IBlockState plant = ((IPlantable) stack.getItem()).getPlant(world, pos);
if (plant.getBlock() == block) {
// This is a valid seed
stack.splitStack(1);
world.setBlockState(pos, plant);
break;
}
}
}
}
示例7: dispenseStack
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
* Dispense the specified stack, play the dispense sound and spawn particles.
*/
protected ItemStack dispenseStack(IBlockSource source, ItemStack stack)
{
EnumFacing enumfacing = BlockDispenser.getFacing(source.getBlockMetadata());
IPosition iposition = BlockDispenser.getDispensePosition(source);
ItemStack itemstack = stack.splitStack(1);
doDispense(source.getWorld(), itemstack, 6, enumfacing, iposition);
return stack;
}
示例8: insertItem
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
if (!this.allowedToPushTo(slot))
return stack;
if (!this.isItemValidForSlot(slot, stack))
return stack;
ItemStack existingStack = this.getStackInSlot(slot);
if (existingStack != null && !RezolveMod.areStacksSame(stack, existingStack)) {
return stack;
}
int itemsToKeep = stack.stackSize;
ItemStack returnStack = null;
ItemStack keepStack = stack.copy();
if (existingStack != null && existingStack.stackSize + stack.stackSize > this.getInventoryStackLimit()) {
itemsToKeep = this.getInventoryStackLimit() - existingStack.stackSize;
returnStack = keepStack.splitStack(stack.stackSize - itemsToKeep);
}
if (existingStack != null)
keepStack.stackSize += existingStack.stackSize;
if (!simulate) {
this.setInventorySlotContents(slot, keepStack);
}
return returnStack;
}
示例9: dispenseStack
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public ItemStack dispenseStack(IBlockSource block, ItemStack stack) {
EnumFacing enumfacing = BlockDispenser.func_149937_b(block.getBlockMetadata());
double d0 = block.getX() + enumfacing.getFrontOffsetX();
double d1 = block.getYInt() + 0.2F;
double d2 = block.getZ() + enumfacing.getFrontOffsetZ();
Entity entity = ItemEntityEgg.spawnEntity(block.getWorld(), stack.getItemDamage(), d0, d1, d2);
if (entity instanceof EntityLivingBase && stack.hasDisplayName())
((EntityLiving) entity).setCustomNameTag(stack.getDisplayName());
stack.splitStack(1);
return stack;
}
示例10: dispenseStack
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
* Dispense the specified stack, play the dispense sound and spawn particles.
*/
public ItemStack dispenseStack(IBlockSource source, ItemStack stack)
{
EnumFacing enumfacing = (EnumFacing)source.getBlockState().getValue(BlockDispenser.FACING);
World world = source.getWorld();
double d0 = source.getX() + (double)((float)enumfacing.getFrontOffsetX() * 1.125F);
double d1 = source.getY() + (double)((float)enumfacing.getFrontOffsetY() * 1.125F);
double d2 = source.getZ() + (double)((float)enumfacing.getFrontOffsetZ() * 1.125F);
BlockPos blockpos = source.getBlockPos().offset(enumfacing);
Material material = world.getBlockState(blockpos).getMaterial();
double d3;
if (Material.WATER.equals(material))
{
d3 = 1.0D;
}
else
{
if (!Material.AIR.equals(material) || !Material.WATER.equals(world.getBlockState(blockpos.down()).getMaterial()))
{
return this.dispenseBehavior.dispense(source, stack);
}
d3 = 0.0D;
}
EntityBoat entityboat = new EntityBoat(world, d0, d1 + d3, d2);
entityboat.setBoatType(this.boatType);
entityboat.rotationYaw = enumfacing.getOpposite().getHorizontalAngle();
world.spawnEntityInWorld(entityboat);
stack.splitStack(1);
return stack;
}
示例11: dispenseStack
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
* Dispense the specified stack, play the dispense sound and spawn particles.
*/
public ItemStack dispenseStack(IBlockSource source, ItemStack stack)
{
World world = source.getWorld();
IPosition iposition = BlockDispenser.getDispensePosition(source);
EnumFacing enumfacing = BlockDispenser.getFacing(source.getBlockMetadata());
IProjectile iprojectile = this.getProjectileEntity(world, iposition);
iprojectile.setThrowableHeading((double)enumfacing.getFrontOffsetX(), (double)((float)enumfacing.getFrontOffsetY() + 0.1F), (double)enumfacing.getFrontOffsetZ(), this.func_82500_b(), this.func_82498_a());
world.spawnEntityInWorld((Entity)iprojectile);
stack.splitStack(1);
return stack;
}
示例12: useItemSafely
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public static ItemStack useItemSafely(ItemStack stack) {
if (stack.stackSize == 1) {
if (stack.getItem().hasContainerItem(stack))
return stack.getItem().getContainerItem(stack);
else
return null;
}
else {
stack.splitStack(1);
return stack;
}
}
示例13: buildSupportBlock
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private void buildSupportBlock(EntityItem entityItem) {
ItemStack blockStack = entityItem.getItem();
ItemStack actual = blockStack.splitStack(1);
if (blockStack.isEmpty()) {
entityItem.setDead();
}
IMeeCreep entity = helper.getMeeCreep();
World world = entity.getWorld();
Block block = ((ItemBlock) actual.getItem()).getBlock();
IBlockState stateForPlacement = block.getStateForPlacement(world, supportPosTodo.south(), EnumFacing.DOWN, 0, 0, 0, actual.getItem().getMetadata(actual), GeneralTools.getHarvester(), EnumHand.MAIN_HAND);
world.setBlockState(supportPosTodo.south(), stateForPlacement, 3);
placeLadder(supportPosTodo);
supportPosTodo = null;
}
示例14: consumeItem
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public ItemStack consumeItem(Predicate<ItemStack> matcher, int amount) {
for (ItemStack stack : inventory) {
if (!stack.isEmpty() && matcher.test(stack)) {
return stack.splitStack(amount);
}
}
return ItemStack.EMPTY;
}
示例15: decrStackSize
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public ItemStack decrStackSize(int slot, int amt) {
ItemStack stack = getStackInSlot(slot);
if (stack != null) {
if (stack.stackSize <= amt) {
setInventorySlotContents(slot, null);
} else {
stack = stack.splitStack(amt);
if (stack.stackSize == 0) {
setInventorySlotContents(slot, null);
}
}
}
return stack;
}