本文整理汇总了Java中net.minecraft.item.ItemStack.copy方法的典型用法代码示例。如果您正苦于以下问题:Java ItemStack.copy方法的具体用法?Java ItemStack.copy怎么用?Java ItemStack.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.item.ItemStack
的用法示例。
在下文中一共展示了ItemStack.copy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dropItemsFromInventory
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public static void dropItemsFromInventory(World world, BlockPos pos, CompatItemHandler inventoryItemHandler){
for (int i = 0; i < inventoryItemHandler.getSlots(); i++) {
ItemStack stack = inventoryItemHandler.getStackInSlot(i);
if(!ItemStackTools.isEmpty(stack) && ItemStackTools.getStackSize(stack) != 0){
float dX = world.rand.nextFloat()*0.8F+0.1F;
float dY = world.rand.nextFloat()*0.8F+0.1F;
float dZ = world.rand.nextFloat()*0.8F+0.1F;
EntityItem entityItem = new EntityItem(world, pos.getX()+dX, pos.getY()+dY, pos.getZ()+dZ, stack.copy());
float factor = 0.05F;
entityItem.motionX = world.rand.nextGaussian()*factor;
entityItem.motionY = world.rand.nextGaussian()*factor+0.2F;
entityItem.motionZ = world.rand.nextGaussian()*factor;
WorldTools.spawnEntity(world, entityItem);
}
}
}
示例2: setDisplayedItemWithUpdate
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private void setDisplayedItemWithUpdate(ItemStack stack, boolean p_174864_2_)
{
if (!stack.func_190926_b())
{
stack = stack.copy();
stack.func_190920_e(1);
stack.setItemFrame(this);
}
this.getDataManager().set(ITEM, stack);
this.getDataManager().setDirty(ITEM);
if (!stack.func_190926_b())
{
this.playSound(SoundEvents.ENTITY_ITEMFRAME_ADD_ITEM, 1.0F, 1.0F);
}
if (p_174864_2_ && this.hangingPosition != null)
{
this.world.updateComparatorOutputLevel(this.hangingPosition, Blocks.AIR);
}
}
示例3: attemptSmelting
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/** Attempt to smelt the given item.<br>
* This returns instantly, callously disregarding such frivolous niceties as cooking times or the presence of a furnace.<br>
* It will, however, consume fuel from the player's inventory.
* @param player
* @param input the raw ingredients we want to cook.
* @return true if cooking was successful.
*/
public static boolean attemptSmelting(EntityPlayerMP player, ItemStack input)
{
if (player == null || input == null)
return false;
List<ItemStack> ingredients = new ArrayList<ItemStack>();
ingredients.add(input);
ItemStack isOutput = (ItemStack)FurnaceRecipes.instance().getSmeltingList().get(input);
if (isOutput == null)
return false;
int cookingTime = 200; // Seems to be hard-coded in TileEntityFurnace.
if (playerHasIngredients(player, ingredients) && totalBurnTimeInInventory(player) >= cookingTime)
{
removeIngredientsFromPlayer(player, ingredients);
burnInventory(player, cookingTime, input);
ItemStack resultForInventory = isOutput.copy();
ItemStack resultForReward = isOutput.copy();
player.inventory.addItemStackToInventory(resultForInventory);
RewardForCollectingItemImplementation.GainItemEvent event = new RewardForCollectingItemImplementation.GainItemEvent(resultForReward);
MinecraftForge.EVENT_BUS.post(event);
return true;
}
return false;
}
示例4: dropItemOrSelf
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public void dropItemOrSelf(@Nullable Entity entityIn, boolean p_146065_2_)
{
if (this.world.getGameRules().getBoolean("doEntityDrops"))
{
ItemStack itemstack = this.getDisplayedItem();
if (entityIn instanceof EntityPlayer)
{
EntityPlayer entityplayer = (EntityPlayer)entityIn;
if (entityplayer.capabilities.isCreativeMode)
{
this.removeFrameFromMap(itemstack);
return;
}
}
if (p_146065_2_)
{
this.entityDropItem(new ItemStack(Items.ITEM_FRAME), 0.0F);
}
if (!itemstack.func_190926_b() && this.rand.nextFloat() < this.itemDropChance)
{
itemstack = itemstack.copy();
this.removeFrameFromMap(itemstack);
this.entityDropItem(itemstack, 0.0F);
}
}
}
示例5: C0EPacketClickWindow
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public C0EPacketClickWindow(int windowId, int slotId, int usedButton, int mode, ItemStack clickedItem, short actionNumber)
{
this.windowId = windowId;
this.slotId = slotId;
this.usedButton = usedButton;
this.clickedItem = clickedItem != null ? clickedItem.copy() : null;
this.actionNumber = actionNumber;
this.mode = mode;
}
示例6: setSearchStack
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public void setSearchStack(@Nonnull ItemStack stack) {
if (!stack.isEmpty() && stackPredicate.test(stack)) {
stack = stack.copy();
stack.setCount(1);
inventory.setStackInSlot(0, stack);
}
}
示例7: dropRecord
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private void dropRecord(World worldIn, BlockPos pos, IBlockState state)
{
if (!worldIn.isRemote)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof BlockJukebox.TileEntityJukebox)
{
BlockJukebox.TileEntityJukebox blockjukebox$tileentityjukebox = (BlockJukebox.TileEntityJukebox)tileentity;
ItemStack itemstack = blockjukebox$tileentityjukebox.getRecord();
if (itemstack != null)
{
worldIn.playEvent(1010, pos, 0);
worldIn.playRecord(pos, (SoundEvent)null);
blockjukebox$tileentityjukebox.setRecord((ItemStack)null);
float f = 0.7F;
double d0 = (double)(worldIn.rand.nextFloat() * 0.7F) + 0.15000000596046448D;
double d1 = (double)(worldIn.rand.nextFloat() * 0.7F) + 0.06000000238418579D + 0.6D;
double d2 = (double)(worldIn.rand.nextFloat() * 0.7F) + 0.15000000596046448D;
ItemStack itemstack1 = itemstack.copy();
EntityItem entityitem = new EntityItem(worldIn, (double)pos.getX() + d0, (double)pos.getY() + d1, (double)pos.getZ() + d2, itemstack1);
entityitem.setDefaultPickupDelay();
worldIn.spawnEntityInWorld(entityitem);
}
}
}
}
示例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: C08PacketPlayerBlockPlacement
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public C08PacketPlayerBlockPlacement(BlockPos positionIn, int placedBlockDirectionIn, ItemStack stackIn, float facingXIn, float facingYIn, float facingZIn)
{
this.position = positionIn;
this.placedBlockDirection = placedBlockDirectionIn;
this.stack = stackIn != null ? stackIn.copy() : null;
this.facingX = facingXIn;
this.facingY = facingYIn;
this.facingZ = facingZIn;
}
示例10: dispense
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
protected void dispense(World worldIn, BlockPos pos)
{
BlockSourceImpl blocksourceimpl = new BlockSourceImpl(worldIn, pos);
TileEntityDispenser tileentitydispenser = (TileEntityDispenser)blocksourceimpl.getBlockTileEntity();
if (tileentitydispenser != null)
{
int i = tileentitydispenser.getDispenseSlot();
if (i < 0)
{
worldIn.playAuxSFX(1001, pos, 0);
}
else
{
ItemStack itemstack = tileentitydispenser.getStackInSlot(i);
if (itemstack != null)
{
EnumFacing enumfacing = (EnumFacing)worldIn.getBlockState(pos).getValue(FACING);
BlockPos blockpos = pos.offset(enumfacing);
IInventory iinventory = TileEntityHopper.getInventoryAtPosition(worldIn, (double)blockpos.getX(), (double)blockpos.getY(), (double)blockpos.getZ());
ItemStack itemstack1;
if (iinventory == null)
{
itemstack1 = this.dropBehavior.dispense(blocksourceimpl, itemstack);
if (itemstack1 != null && itemstack1.stackSize <= 0)
{
itemstack1 = null;
}
}
else
{
itemstack1 = TileEntityHopper.putStackInInventoryAllSlots(iinventory, itemstack.copy().splitStack(1), enumfacing.getOpposite());
if (itemstack1 == null)
{
itemstack1 = itemstack.copy();
if (--itemstack1.stackSize <= 0)
{
itemstack1 = null;
}
}
else
{
itemstack1 = itemstack.copy();
}
}
tileentitydispenser.setInventorySlotContents(i, itemstack1);
}
}
}
}
示例11: addItem
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public static void addItem(EntityPlayer player, Entity_AA turret, ItemStack playerStack)
{
int slot = 0;
while (slot < turret.storage.length)
{
if (turret.storage[slot] == null) // That spot is free
{
turret.storage[slot] = playerStack.copy(); // Stored
if (!player.capabilities.isCreativeMode) { player.setCurrentItemOrArmor(0, null); } // Empty
if (playerStack.getItem() == Items.writable_book && AI_Targeting.isNameOnWhitelist(turret, Commands.cmdStayStationary))
{
//System.out.println("[ARMS ASSISTANT] Received a book with STAY command. Setting target position");
turret.stationaryX = turret.posX;
turret.stationaryY = turret.posY;
turret.stationaryZ = turret.posZ;
}
// Informing the client about this change
NetHelper.sendTurretInventoryMessageToPlayersInRange(turret.worldObj, turret,
Item.getIdFromItem(turret.storage[slot].getItem()), slot, turret.storage[slot].getItemDamage());
return; // We're done here
}
// else, there's something in there
slot += 1;
}
// No free spot found. What about existing ones?
slot = 0;
while (slot < turret.storage.length)
{
if (turret.storage[slot] != null)
{
boolean skip = false;
if (!(turret.storage[slot].getItem() instanceof _AmmoBase)) { skip = true; } // Not ammunition, hm?
if (turret.storage[slot].getItemDamage() < turret.storage[slot].getMaxDamage()) { skip = true; } // Not empty
if (!skip)
{
// Has an empty magazine in there, so replacing that now
dropSingleItem(turret, turret.storage[slot].copy());
turret.storage[slot] = playerStack.copy(); // Stored
if (!player.capabilities.isCreativeMode) { player.setCurrentItemOrArmor(0, null); } // Empty
// Informing the client about this change
NetHelper.sendTurretInventoryMessageToPlayersInRange(turret.worldObj, turret,
Item.getIdFromItem(turret.storage[slot].getItem()), slot, turret.storage[slot].getItemDamage());
return;
}
// else, not a magazine
}
// else, no free spot found but this is null? Da fuq?
slot += 1;
}
}
示例12: transferStackInSlot
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public ItemStack transferStackInSlot(EntityPlayer player, int slotNumber) {
ItemStack itemstack = null;
Slot slot = (Slot) this.inventorySlots.get(slotNumber);
if(slot != null && slot.getHasStack()) {
ItemStack slotStack = slot.getStack();
itemstack = slotStack.copy();
if(slotNumber == 5 || slotNumber == 6 || slotNumber == 7 || slotNumber == 8 || slotNumber == 9 || slotNumber == 10) {
if(!this.mergeItemStack(slotStack, 11, 47, true)) {
return null;
}
slot.onSlotChange(slotStack, itemstack);
} else if(slotNumber != 0 && slotNumber != 1 && slotNumber != 2 && slotNumber != 3 && slotNumber != 4) {
if(this.tileEntity.isItemUsedInRecipe(slotStack)) {
if(!this.mergeItemStack(slotStack, 0, 3, false)) {
return null;
}
} else if(TileEntityMachineRepairingForge.isItemFuelBurning(slotStack)) {
if(!this.mergeItemStack(slotStack, 4, 5, false)) {
return null;
}
} else if(TileEntityMachineRepairingForge.isItemFuelElectrical(slotStack)) {
if(!this.mergeItemStack(slotStack, 3, 4, false)) {
return null;
}
} else if(slotNumber >= 11 && slotNumber < 38) {
if(!this.mergeItemStack(slotStack, 0, 2, false)) {
return null;
}
} else if(slotNumber >= 38 && slotNumber < 47 && !this.mergeItemStack(slotStack, 0, 2, false)) {
return null;
}
} else if(!this.mergeItemStack(slotStack, 11, 47, false)) {
return null;
}
if(slotStack.stackSize == 0) {
slot.putStack((ItemStack) null);
} else {
slot.onSlotChanged();
}
if(slotStack.stackSize == itemstack.stackSize) {
return null;
}
slot.onPickupFromSlot(player, slotStack);
}
return itemstack;
}
示例13: C10PacketCreativeInventoryAction
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public C10PacketCreativeInventoryAction(int slotIdIn, ItemStack stackIn)
{
this.slotId = slotIdIn;
this.stack = stackIn != null ? stackIn.copy() : null;
}
示例14: transferStackInSlot
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
* Take a stack from the specified inventory slot.
*/
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
ItemStack itemstack = null;
Slot slot = (Slot)this.inventorySlots.get(index);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (index == 2)
{
if (!this.mergeItemStack(itemstack1, 3, 39, true))
{
return null;
}
slot.onSlotChange(itemstack1, itemstack);
}
else if (index != 0 && index != 1)
{
if (index >= 3 && index < 39 && !this.mergeItemStack(itemstack1, 0, 2, false))
{
return null;
}
}
else if (!this.mergeItemStack(itemstack1, 3, 39, false))
{
return null;
}
if (itemstack1.stackSize == 0)
{
slot.putStack((ItemStack)null);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.stackSize == itemstack.stackSize)
{
return null;
}
slot.onPickupFromSlot(playerIn, itemstack1);
}
return itemstack;
}
示例15: transferStackInSlot
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
* Take a stack from the specified inventory slot.
*/
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
ItemStack itemstack = null;
Slot slot = (Slot)this.inventorySlots.get(index);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if ((index < 0 || index > 2) && index != 3)
{
if (!this.theSlot.getHasStack() && this.theSlot.isItemValid(itemstack1))
{
if (!this.mergeItemStack(itemstack1, 3, 4, false))
{
return null;
}
}
else if (ContainerBrewingStand.Potion.canHoldPotion(itemstack))
{
if (!this.mergeItemStack(itemstack1, 0, 3, false))
{
return null;
}
}
else if (index >= 4 && index < 31)
{
if (!this.mergeItemStack(itemstack1, 31, 40, false))
{
return null;
}
}
else if (index >= 31 && index < 40)
{
if (!this.mergeItemStack(itemstack1, 4, 31, false))
{
return null;
}
}
else if (!this.mergeItemStack(itemstack1, 4, 40, false))
{
return null;
}
}
else
{
if (!this.mergeItemStack(itemstack1, 4, 40, true))
{
return null;
}
slot.onSlotChange(itemstack1, itemstack);
}
if (itemstack1.stackSize == 0)
{
slot.putStack((ItemStack)null);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.stackSize == itemstack.stackSize)
{
return null;
}
slot.onPickupFromSlot(playerIn, itemstack1);
}
return itemstack;
}