本文整理汇总了Java中net.minecraft.item.ItemStack.shrink方法的典型用法代码示例。如果您正苦于以下问题:Java ItemStack.shrink方法的具体用法?Java ItemStack.shrink怎么用?Java ItemStack.shrink使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.item.ItemStack
的用法示例。
在下文中一共展示了ItemStack.shrink方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: consumeAmmo
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public void consumeAmmo(EntityLivingBase living, ItemStack stack, int amount) {
if (stack == STACK_FILL)
return;
// if(EntityDispenser.isNearDispenser(living.world, living)) return;
if (amount > 0) {
stack.shrink(amount);
/*if (stack.isEmpty() && living instanceof EntityPlayer) {
if (living.getCapability(TF2weapons.INVENTORY_CAP, null).getStackInSlot(3) != null){
IItemHandlerModifiable invAmmo = (IItemHandlerModifiable) living.getCapability(TF2weapons.INVENTORY_CAP, null).getStackInSlot(3)
.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
for (int i = 0; i < invAmmo.getSlots(); i++) {
ItemStack stackInv = invAmmo.getStackInSlot(i);
if (stack == stackInv) {
invAmmo.setStackInSlot(i, null);
return;
}
}
}
((EntityPlayer) living).inventory.deleteStack(stack);
}*/
}
}
示例2: onItemUse
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public EnumActionResult onItemUse (EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack stack = player.getHeldItem(hand);
IBlockState state = worldIn.getBlockState(pos);
if (facing != EnumFacing.UP)
return EnumActionResult.FAIL;
if (!player.canPlayerEdit(pos.offset(facing), facing, stack))
return EnumActionResult.FAIL;
if (!state.getBlock().canSustainPlant(state, worldIn, pos, EnumFacing.UP, this))
return EnumActionResult.FAIL;
if (!worldIn.isAirBlock(pos.up()))
return EnumActionResult.FAIL;
worldIn.setBlockState(pos.up(), ModBlocks.candelilla.getDefaultState());
if (player instanceof EntityPlayerMP)
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)player, pos.up(), stack);
stack.shrink(1);
return EnumActionResult.SUCCESS;
}
示例3: plantAll
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private void plantAll(List<EntityItem> items, World world, BlockPos pos, int amplifier) {
int box = 1 + (int) ((float) amplifier / 2F);
BlockPos posI = pos.add(box, 1, box);
BlockPos posF = pos.add(-box, -1, -box);
Iterable<BlockPos> spots = BlockPos.getAllInBox(posI, posF);
for (EntityItem item : items) {
ItemStack stack = item.getItem();
for (BlockPos spot : spots) {
if (stack.isEmpty()) {
item.setDead();
break;
}
IBlockState state = world.getBlockState(spot);
IPlantable seed = (IPlantable) stack.getItem();
if (world.isAirBlock(spot.up()) && state.getBlock().canSustainPlant(state, world, spot, EnumFacing.UP, seed)) {
world.setBlockState(spot.up(), seed.getPlant(world, spot.up()));
stack.shrink(1);
}
}
}
}
示例4: adjustPhantomSlot
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private void adjustPhantomSlot(Slot slot, ClickType clickType, int dragType) {
if (!((IPhantomSlot) slot).canAdjust()) {
return;
}
ItemStack stackSlot = slot.getStack().copy();
if (dragType == 1) {
if (clickType == ClickType.QUICK_MOVE) {
stackSlot.setCount(Math.min(stackSlot.getCount() * 2, slot.getSlotStackLimit())); // shift-r-click: double stack size
} else {
stackSlot.setCount(Math.min(stackSlot.getCount() + 1, slot.getSlotStackLimit())); // r-click: increase stack size
}
} else if (dragType == 0) {
if (clickType == ClickType.QUICK_MOVE) {
stackSlot.setCount(stackSlot.getCount() / 2); // shift-l-click: half stack size
} else {
stackSlot.shrink(1); // l-click: decrease stack size
}
}
slot.putStack(stackSlot);
}
示例5: onBlockActivated
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override //&& state.getValue(GENERATED)==1
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack heldItem = playerIn.getHeldItem(hand);
if (heldItem.isEmpty()) {
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
if (!worldIn.isRemote && heldItem.getItem() == Items.BOWL && facing != EnumFacing.UP && facing != EnumFacing.DOWN) {
ItemStack itemstack1 = new ItemStack(ItemRegistry.rubber_sap);
heldItem.shrink(1);
if (heldItem.isEmpty()) {
playerIn.setHeldItem(hand, itemstack1);
} else if (!playerIn.inventory.addItemStackToInventory(itemstack1)) {
playerIn.dropItem(itemstack1, false);
}
}
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
示例6: useOnVanillaFurnace
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private boolean useOnVanillaFurnace(EntityPlayer playerIn, World world, BlockPos pos, ItemStack stack, Upgrades upgrade)
{
TileEntity te = world.getTileEntity(pos);
if (te != null && te instanceof TileEntityFurnace)
{
TileEntityFurnace furnace = (TileEntityFurnace) te;
boolean upgraded = upgradeVanillaFurnace(world, pos, furnace, upgrade.getUpgradedType());
if (upgraded && !playerIn.capabilities.isCreativeMode)
{
stack.shrink(1);
}
return true;
}
return false;
}
示例7: onItemRightClick
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand)
{
ItemStack itemStackIn=playerIn.getHeldItem(hand);
if(!worldIn.isRemote){
for(ItemStack stack:playerIn.inventory.mainInventory){
if(!stack.isEmpty() && stack.getItem() instanceof ItemFromData&& ItemFromData.getData(stack).getInt(PropertyType.AMMO_TYPE)!=0){
itemStackIn.setItemDamage(ItemFromData.getData(stack).getInt(PropertyType.AMMO_TYPE));
break;
}
}
ItemStack out=convertPackage(itemStackIn,playerIn);
if(playerIn.inventory.addItemStackToInventory(out))
itemStackIn.shrink(1);
}
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemStackIn);
}
示例8: updateMachineTier
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public void updateMachineTier(World world, EntityPlayer player, EnumHand hand, BlockPos pos, ItemStack stack) {
if (stack.getItem() == ModItems.itemChip) {
ChipTypes newType = ChipTypes.values()[stack.getItemDamage() % ChipTypes.values().length];
ChipTypes currentType = (ChipTypes) world.getBlockState(pos).getValue(TYPE);
IBlockState newState = world.getBlockState(pos).withProperty(TYPE, newType);
if (newType.getID() > currentType.getID()) {
world.setBlockState(pos, newState, 2);
}
ItemStack newStack = stack.copy();
newStack.shrink(1);
player.setHeldItem(hand, newStack);
if (player.getHeldItem(hand).getCount() <= 0)
player.setHeldItem(hand, ItemStack.EMPTY);
}
}
示例9: doBlockInteraction
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
protected boolean doBlockInteraction(BlockPos pos, double distToBlock) {
if (drone.getPathNavigator().hasNoPath()) {
EnumFacing side = ProgWidgetPlace.getDirForSides(((ISidedWidget) widget).getSides());
for (int i = 0; i < drone.getInv().getSlots(); i++) {
ItemStack droneStack = drone.getInv().getStackInSlot(i);
if (droneStack.getItem() instanceof ItemBlock && ((ItemBlock) droneStack.getItem()).getBlock().canPlaceBlockOnSide(drone.world(), pos, ProgWidgetPlace.getDirForSides(((ISidedWidget) widget).getSides()))) {
if (widget.isItemValidForFilters(droneStack)) {
ItemBlock itemBlock = (ItemBlock) droneStack.getItem();
Block block = itemBlock.getBlock();
if (drone.world().mayPlace(block, pos, false, side, drone instanceof EntityDrone ? (EntityDrone) drone : null)) {
int newMeta = itemBlock.getMetadata(droneStack.getMetadata());
setFakePlayerAccordingToDir();
IBlockState iblockstate1 = block.getStateForPlacement(drone.world(), pos, side, side.getFrontOffsetX(), side.getFrontOffsetY(), side.getFrontOffsetZ(), newMeta, drone.getFakePlayer(), EnumHand.MAIN_HAND);
if (itemBlock.placeBlockAt(droneStack, drone.getFakePlayer(), drone.world(), pos, side, side.getFrontOffsetX(), side.getFrontOffsetY(), side.getFrontOffsetZ(), iblockstate1)) {
drone.addAir(null, -PneumaticValues.DRONE_USAGE_PLACE);
SoundType soundType = block.getSoundType(iblockstate1, drone.world(), pos, drone.getFakePlayer());
drone.world().playSound(pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F, false);
droneStack.shrink(1);
if (droneStack.getCount() <= 0) {
drone.getInv().setStackInSlot(i, ItemStack.EMPTY);
}
}
return false;
}
}
}
}
return false;
} else {
return true;
}
}
示例10: tryFluidExtraction
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
* Attempt to extract fluid from the given fluid handler into the given fluid-containing item.
*
* @param srcHandler fluid handler into which to place the fluid
* @param destStack the fluid container item to extract from
* @param returnedItems the modified fluid container after extraction
* @return true if any fluid was moved, false otherwise
*/
public static boolean tryFluidExtraction(IFluidHandler srcHandler, ItemStack destStack, NonNullList<ItemStack> returnedItems) {
FluidActionResult result = FluidUtil.tryFillContainer(destStack, srcHandler, 1000, null, true);
if (result.isSuccess()) {
returnedItems.add(result.getResult());
destStack.shrink(1);
return true;
} else {
return false;
}
}
示例11: onItemUse
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Nonnull
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
IBlockState iblockstate = worldIn.getBlockState(pos);
Block block = iblockstate.getBlock();
Block cake = Block.REGISTRY.getObject(new ResourceLocation(FoodCraftReloaded.MODID, NameBuilder.buildRegistryName(fruitType.toString(), "cake")));
if (block == Blocks.SNOW_LAYER && iblockstate.getValue(BlockSnow.LAYERS) < 1)
facing = EnumFacing.UP;
else if (!block.isReplaceable(worldIn, pos))
pos = pos.offset(facing);
ItemStack itemstack = player.getHeldItem(hand);
if (!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(cake, pos, false, facing, null)) {
IBlockState blockState = cake.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, 0, player, hand);
if (!worldIn.setBlockState(pos, blockState, 11))
return EnumActionResult.FAIL;
else {
blockState = worldIn.getBlockState(pos);
if (blockState.getBlock() == cake) {
ItemBlock.setTileEntityNBT(worldIn, player, pos, itemstack);
blockState.getBlock().onBlockPlacedBy(worldIn, pos, blockState, player, itemstack);
}
SoundType soundtype = blockState.getBlock().getSoundType(blockState, worldIn, pos, player);
worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
itemstack.shrink(1);
return EnumActionResult.SUCCESS;
}
}
else
return EnumActionResult.FAIL;
}
示例12: onItemRightClick
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
ItemStack itemStackIn = playerIn.getHeldItem(hand);
ItemStack itemstack1 = new ItemStack(ModItems.itemWirelessMap, 1, worldIn.getUniqueDataId("map"));
String s = "map_" + itemstack1.getItemDamage();
MapData mapdata = new MapData(s);
worldIn.setData(s, mapdata);
mapdata.scale = 0;
int i = 128 * (1 << mapdata.scale);
mapdata.xCenter = (int)(Math.round(playerIn.posX / (double)i) * (long)i);
mapdata.zCenter = (int)(Math.round(playerIn.posZ / (double)i) * (long)i);
mapdata.dimension = worldIn.provider.getDimension();
mapdata.markDirty();
itemStackIn.shrink(1);
if (itemStackIn.getCount() <= 0)
{
return new ActionResult<>(EnumActionResult.SUCCESS, itemstack1);
}
else
{
if (!playerIn.inventory.addItemStackToInventory(itemstack1.copy()))
{
playerIn.dropItem(itemstack1, false);
}
return new ActionResult<>(EnumActionResult.SUCCESS, itemStackIn);
}
}
示例13: shrink
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public void shrink(ItemStack stack){
for(OreDictStack oreDictStack : this.inputs){
if(oreDictStack.isSubstractable(stack)){
stack.shrink(oreDictStack.getStacksize());
return;
}
}
}
示例14: onItemRightClick
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
* Applies the data in the EntityTag tag of the given ItemStack to the given
* Entity.
*/
@Override
public ActionResult<ItemStack> onItemRightClick( World worldIn, EntityPlayer playerIn,
EnumHand hand) {
ItemStack itemStackIn=playerIn.getHeldItem(hand);
if (worldIn.isRemote)
return new ActionResult<ItemStack>(EnumActionResult.PASS, itemStackIn);
else {
RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, true);
if (raytraceresult != null && raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK) {
BlockPos blockpos = raytraceresult.getBlockPos();
if (!(worldIn.getBlockState(blockpos).getBlock() instanceof BlockLiquid))
return new ActionResult<ItemStack>(EnumActionResult.PASS, itemStackIn);
else if (worldIn.isBlockModifiable(playerIn, blockpos)
&& playerIn.canPlayerEdit(blockpos, raytraceresult.sideHit, itemStackIn)) {
boolean hastag = itemStackIn.getTagCompound() != null && itemStackIn.getTagCompound().hasKey("SavedEntity");
EntityLivingBase entity = spawnCreature(worldIn, itemStackIn.getItemDamage(),
blockpos.getX() + 0.5D, blockpos.getY() + 0.5D, blockpos.getZ() + 0.5D,
hastag
? itemStackIn.getTagCompound().getCompoundTag("SavedEntity") : null);
if (entity == null)
return new ActionResult(EnumActionResult.PASS, itemStackIn);
else {
if (entity instanceof EntityLivingBase && itemStackIn.hasDisplayName())
entity.setCustomNameTag(itemStackIn.getDisplayName());
if (!playerIn.capabilities.isCreativeMode)
itemStackIn.shrink(1);
if (entity instanceof EntityBuilding) {
((EntityBuilding) entity).setOwner(playerIn);
if(hastag) {
((EntityBuilding) entity).setConstructing(true);
((EntityBuilding) entity).redeploy = true;
}
entity.rotationYaw = playerIn.rotationYawHead;
entity.renderYawOffset = playerIn.rotationYawHead;
entity.rotationYawHead = playerIn.rotationYawHead;
/*
* if(entity instanceof EntityTeleporter){
* ((EntityTeleporter)
* entity).setExit(itemStackIn.getItemDamage()>23);
* }
*/
}
playerIn.addStat(StatList.getObjectUseStats(this));
return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
}
} else
return new ActionResult(EnumActionResult.FAIL, itemStackIn);
} else
return new ActionResult(EnumActionResult.PASS, itemStackIn);
}
}
示例15: onBlockActivated
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand,
EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (world.isRemote)
{
return true;
}
TileEntity teUnchecked = world.getTileEntity(pos);
if (!(teUnchecked instanceof TileEntityAnalyzer))
{
return false;
}
TileEntityAnalyzer te = (TileEntityAnalyzer) teUnchecked;
ItemStack stack = player.getHeldItem(hand);
if (!stack.isEmpty() && !player.isSneaking())
{
ItemStack insertStack = stack.copy();
if (stack.getItem().equals(ModRegistry.BLANK_PARCHMENT))
{
List<NotebookCategory> unlockable = ArcaneMagicAPI.getAnalyzer()
.getAnalysisResults(te.getStack(0).copy());
if (!te.getStack(0).isEmpty() && unlockable.size() > 0 && te.getStack(1).isEmpty())
{
stack.shrink(1);
te.setStack(1, new ItemStack(ModRegistry.BLANK_PARCHMENT));
}
} else if (te.getStack(0).isEmpty())
{
stack.shrink(1);
insertStack.setCount(1);
player.setHeldItem(hand, stack);
te.setPlayer(player);
te.setStack(0, insertStack);
te.markDirty();
world.playSound(player, pos, SoundEvents.ENTITY_ITEMFRAME_ADD_ITEM, SoundCategory.BLOCKS, 1, 1);
}
} else if (player.isSneaking())
{
ItemStack toExtract = te.getStack(0).copy();
if (!toExtract.isEmpty())
{
if (!world.isRemote)
{
if (player.addItemStackToInventory(toExtract.copy()))
{
te.setStack(0, ItemStack.EMPTY);
te.markDirty();
}
} else
{
world.playSound(player, pos, SoundEvents.ENTITY_ITEMFRAME_REMOVE_ITEM, SoundCategory.BLOCKS, 1, 1);
}
}
}
return true;
}