本文整理汇总了Java中net.minecraft.item.ItemStack.setItemDamage方法的典型用法代码示例。如果您正苦于以下问题:Java ItemStack.setItemDamage方法的具体用法?Java ItemStack.setItemDamage怎么用?Java ItemStack.setItemDamage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.item.ItemStack
的用法示例。
在下文中一共展示了ItemStack.setItemDamage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fillEight
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private void fillEight(ItemStack stack, World world, EntityPlayer player)
{
boolean doSFX = false;
int counter = 0;
while (counter < 8)
{
if (player.inventory.hasItem(Items.redstone))
{
int dmg = stack.getItemDamage() - 1;
stack.setItemDamage(dmg);
player.inventory.consumeInventoryItem(Items.redstone); // We're just grabbing what we need from the inventory
doSFX = true;
}
// else, doesn't have what it takes
counter += 1;
}
if (doSFX) { world.playSoundAtEntity(player, "random.wood_click", 1.0F, 0.2F); }
}
示例2: call
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public void call(String[] args) throws CmdException
{
if(args.length > 0)
throw new CmdSyntaxError();
// check for creative mode
EntityPlayerSP player = WMinecraft.getPlayer();
if(!player.capabilities.isCreativeMode)
throw new CmdError("Creative mode only.");
// validate item
ItemStack item = player.inventory.getCurrentItem();
if(item == null)
throw new CmdError("You need an item in your hand.");
if(!item.isItemStackDamageable())
throw new CmdError("This item can't take damage.");
if(!item.isItemDamaged())
throw new CmdError("This item is not damaged.");
// repair item
item.setItemDamage(0);
WConnection.sendPacket(new CPacketCreativeInventoryAction(
36 + player.inventory.currentItem, item));
}
示例3: dropMagazine
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private void dropMagazine(World world, ItemStack stack, Entity entity)
{
if (!(entity instanceof EntityPlayer)) // For QuiverMobs/Arms Assistants
{
this.setCooldown(stack, 60);
return;
}
ItemStack clipStack = Helper.getAmmoStack(ObsidianMagazine.class, stack.getItemDamage()); // Unloading all ammo into that clip
stack.setItemDamage(this.getMaxDamage()); // Emptying out
// Creating the clip
EntityItem entityitem = new EntityItem(world, entity.posX, entity.posY + 1.0d, entity.posZ, clipStack);
entityitem.delayBeforeCanPickup = 10;
// And dropping it
if (entity.captureDrops) { entity.capturedDrops.add(entityitem); }
else { world.spawnEntityInWorld(entityitem); }
// SFX
world.playSoundAtEntity(entity, "random.click", 1.7F, 0.3F);
}
示例4: dropMagazine
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private void dropMagazine(World world, ItemStack stack, Entity entity)
{
if (!(entity instanceof EntityPlayer)) // For QuiverMobs/Arms Assistants
{
this.setCooldown(stack, 60);
return;
}
ItemStack clipStack = Helper.getAmmoStack(ObsidianMagazine.class, MathHelper.floor_double(stack.getItemDamage() / 2) + 1); // Unloading all ammo into that clip, with some loss
stack.setItemDamage(this.getMaxDamage()); // Emptying out
// Creating the clip
EntityItem entityitem = new EntityItem(world, entity.posX, entity.posY + 1.0d, entity.posZ, clipStack);
entityitem.delayBeforeCanPickup = 10;
// And dropping it
if (entity.captureDrops) { entity.capturedDrops.add(entityitem); }
else { world.spawnEntityInWorld(entityitem); }
// SFX
world.playSoundAtEntity(entity, "random.click", 1.7F, 0.3F);
}
示例5: fill
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public boolean fill(EntityPlayer player, EnumHand hand, int amount)
{
boolean flag = false;
ItemStack stack = player.getHeldItem(hand);
NBTTagCompound nbt = getNBT(stack);
if(nbt.getInteger("Blood") + amount <= 50)
{
nbt.setInteger("Blood", nbt.getInteger("Blood") + amount);
flag = true;
}
stack.setItemDamage(metaChange(nbt));
stack.setTagCompound(nbt);
player.setHeldItem(hand, stack);
return flag;
}
示例6: getReplacement
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public static ItemStack getReplacement(EntityPlayer player, ItemStack stack) {
if (!stack.isEmpty() && stack.getItem() instanceof ItemBuildingBox
&& player.getTeam() == player.world.getScoreboard().getTeam("BLU"))
stack.setItemDamage(stack.getItemDamage() + 1);
if (!stack.isEmpty() && stack.getItem() instanceof ItemBanner){
NBTTagCompound pattern=new NBTTagCompound();
if(player.getTeam() == player.world.getScoreboard().getTeam("BLU")){
stack.setItemDamage(EnumDyeColor.BLUE.getDyeDamage());
pattern.setString("Pattern", "bb");
pattern.setInteger("Color", 15);
}
else{
pattern.setString("Pattern", "rb");
pattern.setInteger("Color", 15);
}
stack.getSubCompound("BlockEntityTag").getTagList("Patterns", 10).appendTag(pattern);
}
if (!stack.isEmpty() && stack.getItem() instanceof ItemBuildingBox && stack.getItemDamage()/2 == 11) {
ItemStack wrench=TF2Util.getFirstItem(player.inventory, stackL ->{
return TF2Attribute.getModifier("Teleporter Cost", stackL, 1, player) != 1;
});
if(!wrench.isEmpty()) {
stack.setCount((int) TF2Attribute.getModifier("Teleporter Cost", wrench, 1, player));
}
}
return stack;
}
示例7: getCraftingResult
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public ItemStack getCraftingResult(InventoryCrafting inventory) {
ItemStack output = getRecipeOutput();
output.setItemDamage(getCanister(inventory).getItemDamage());
//System.out.println("output damage: " + output.getItemDamage());
return output;
}
示例8: getCraftingResult
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public ItemStack getCraftingResult(InventoryCrafting inventory) {
if (!matches(inventory, null)) return null;
ItemStack output = getRecipeOutput();
for (int i = 0; i < inventory.getSizeInventory(); i++) {
if (inventory.getStackInSlot(i).getItem() == Itemss.AIR_CANISTER) {
output.setItemDamage(inventory.getStackInSlot(i).getItemDamage());
}
}
return output;
}
示例9: onItemRightClick
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand)
{
if (this.isMapReady(stack))
{
// Is already a map, so nothing to be done here
}
else
{
// Initiating it now
stack.setTagCompound(new NBTTagCompound());
stack.getTagCompound().setBoolean("initiated", true);
stack.setItemDamage(world.getUniqueDataId("map"));
String uniqueName = "map_" + stack.getItemDamage();
MapData mapdata = new MapData(uniqueName);
world.setItemData(uniqueName, mapdata);
mapdata.scale = 2; // Default scale
int i = 128 * (1 << mapdata.scale);
mapdata.xCenter = (int)(Math.round(player.posX / i) * i);
mapdata.zCenter = (int)(Math.round(player.posZ / i) * i);
mapdata.dimension = world.provider.getDimension();
mapdata.markDirty();
}
return new ActionResult(EnumActionResult.PASS, stack);
}
示例10: checkHarvestedCrops
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@SubscribeEvent
public void checkHarvestedCrops(BlockEvent.HarvestDropsEvent event) {
Block crop = event.getState().getBlock();
if (event.getHarvester() != null && event.getHarvester().capabilities.isCreativeMode)
return;
if (crop == UCBlocks.cropInvisibilia) {
if (event.getHarvester() == null)
{
event.getDrops().clear();
event.setResult(Result.DEFAULT);
}
}
if (crop == UCBlocks.cropFeroxia && ((Feroxia)crop).isFullyGrown(event.getWorld(), event.getPos(), event.getState())) {
if (event.getHarvester() != null && !(event.getHarvester() instanceof FakePlayer))
GrowthSteps.generateSteps(event.getHarvester());
else
event.getDrops().clear();
event.setResult(Result.DEFAULT);
}
if (crop == UCBlocks.cropDyeius && !event.getDrops().isEmpty()) {
for (ItemStack stack : event.getDrops()) {
if (stack.getItem() == Items.DYE)
{
long time = event.getWorld().getWorldTime() % 24000L;
int meta = (int)(time / 1500);
LocalDateTime current = LocalDateTime.now();
if (current.getDayOfWeek() == DayOfWeek.FRIDAY)
stack.setItemDamage(EnumDyeColor.byMetadata(meta).getMetadata());
else
stack.setItemDamage(EnumDyeColor.byMetadata(meta).getDyeDamage());
}
}
}
}
示例11: getContainerItem
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public ItemStack getContainerItem(ItemStack itemStack) {
ItemStack stack = itemStack.copy();
stack.setItemDamage(stack.getItemDamage() + 1);
stack.setCount(1);
return stack;
}
示例12: dropEquipment
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
* Drop the equipment for this entity.
*/
protected void dropEquipment(boolean p_82160_1_, int p_82160_2_)
{
for (int i = 0; i < this.getInventory().length; ++i)
{
ItemStack itemstack = this.getEquipmentInSlot(i);
boolean flag = this.equipmentDropChances[i] > 1.0F;
if (itemstack != null && (p_82160_1_ || flag) && this.rand.nextFloat() - (float)p_82160_2_ * 0.01F < this.equipmentDropChances[i])
{
if (!flag && itemstack.isItemStackDamageable())
{
int j = Math.max(itemstack.getMaxDamage() - 25, 1);
int k = itemstack.getMaxDamage() - this.rand.nextInt(this.rand.nextInt(j) + 1);
if (k > j)
{
k = j;
}
if (k < 1)
{
k = 1;
}
itemstack.setItemDamage(k);
}
this.entityDropItem(itemstack, 0.0F);
}
}
}
示例13: remove
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public boolean remove(EntityPlayer player, EnumHand hand, int amount)
{
if(player.capabilities.isCreativeMode)
return true;
ItemStack stack = player.getHeldItem(hand);
NBTTagCompound nbt = getNBT(stack);
if(nbt.getInteger("Blood") - amount < 0)
return false;
nbt.setInteger("Blood", nbt.getInteger("Blood") - amount);
stack.setItemDamage(metaChange(nbt));
return true;
}
示例14: onLivingUpdate
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
* Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
* use this to react to sunlight and start to burn.
*/
public void onLivingUpdate()
{
if (this.world.isDaytime() && !this.world.isRemote)
{
float f = this.getBrightness(1.0F);
BlockPos blockpos = this.getRidingEntity() instanceof EntityBoat ? (new BlockPos(this.posX, (double)Math.round(this.posY), this.posZ)).up() : new BlockPos(this.posX, (double)Math.round(this.posY), this.posZ);
if (f > 0.5F && this.rand.nextFloat() * 30.0F < (f - 0.4F) * 2.0F && this.world.canSeeSky(blockpos))
{
boolean flag = true;
ItemStack itemstack = this.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
if (!itemstack.func_190926_b())
{
if (itemstack.isItemStackDamageable())
{
itemstack.setItemDamage(itemstack.getItemDamage() + this.rand.nextInt(2));
if (itemstack.getItemDamage() >= itemstack.getMaxDamage())
{
this.renderBrokenItemStack(itemstack);
this.setItemStackToSlot(EntityEquipmentSlot.HEAD, ItemStack.field_190927_a);
}
}
flag = false;
}
if (flag)
{
this.setFire(8);
}
}
}
super.onLivingUpdate();
}
示例15: setMeta
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public static void setMeta(ItemStack stack, int meta) {
stack.setItemDamage(meta);
}