本文整理匯總了Java中net.minecraft.entity.item.EntityItem.setOwner方法的典型用法代碼示例。如果您正苦於以下問題:Java EntityItem.setOwner方法的具體用法?Java EntityItem.setOwner怎麽用?Java EntityItem.setOwner使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.minecraft.entity.item.EntityItem
的用法示例。
在下文中一共展示了EntityItem.setOwner方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: processCommand
import net.minecraft.entity.item.EntityItem; //導入方法依賴的package包/類
/**
* Callback when the command is invoked
*/
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
if (args.length < 2)
{
throw new WrongUsageException("commands.give.usage", new Object[0]);
}
else
{
EntityPlayer entityplayer = getPlayer(sender, args[0]);
Item item = getItemByText(sender, args[1]);
int i = args.length >= 3 ? parseInt(args[2], 1, 64) : 1;
int j = args.length >= 4 ? parseInt(args[3]) : 0;
ItemStack itemstack = new ItemStack(item, i, j);
if (args.length >= 5)
{
String s = getChatComponentFromNthArg(sender, args, 4).getUnformattedText();
try
{
itemstack.setTagCompound(JsonToNBT.getTagFromJson(s));
}
catch (NBTException nbtexception)
{
throw new CommandException("commands.give.tagError", new Object[] {nbtexception.getMessage()});
}
}
boolean flag = entityplayer.inventory.addItemStackToInventory(itemstack);
if (flag)
{
entityplayer.worldObj.playSoundAtEntity(entityplayer, "random.pop", 0.2F, ((entityplayer.getRNG().nextFloat() - entityplayer.getRNG().nextFloat()) * 0.7F + 1.0F) * 2.0F);
entityplayer.inventoryContainer.detectAndSendChanges();
}
if (flag && itemstack.stackSize <= 0)
{
itemstack.stackSize = 1;
sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, i);
EntityItem entityitem1 = entityplayer.dropPlayerItemWithRandomChoice(itemstack, false);
if (entityitem1 != null)
{
entityitem1.func_174870_v();
}
}
else
{
sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, i - itemstack.stackSize);
EntityItem entityitem = entityplayer.dropPlayerItemWithRandomChoice(itemstack, false);
if (entityitem != null)
{
entityitem.setNoPickupDelay();
entityitem.setOwner(entityplayer.getName());
}
}
notifyOperators(sender, this, "commands.give.success", new Object[] {itemstack.getChatComponent(), Integer.valueOf(i), entityplayer.getName()});
}
}
示例2: execute
import net.minecraft.entity.item.EntityItem; //導入方法依賴的package包/類
/**
* Callback for when the command is executed
*/
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
if (args.length < 2)
{
throw new WrongUsageException("commands.give.usage", new Object[0]);
}
else
{
EntityPlayer entityplayer = getPlayer(server, sender, args[0]);
Item item = getItemByText(sender, args[1]);
int i = args.length >= 3 ? parseInt(args[2], 1, 64) : 1;
int j = args.length >= 4 ? parseInt(args[3]) : 0;
ItemStack itemstack = new ItemStack(item, i, j);
if (args.length >= 5)
{
String s = getChatComponentFromNthArg(sender, args, 4).getUnformattedText();
try
{
itemstack.setTagCompound(JsonToNBT.getTagFromJson(s));
}
catch (NBTException nbtexception)
{
throw new CommandException("commands.give.tagError", new Object[] {nbtexception.getMessage()});
}
}
boolean flag = entityplayer.inventory.addItemStackToInventory(itemstack);
if (flag)
{
entityplayer.world.playSound((EntityPlayer)null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((entityplayer.getRNG().nextFloat() - entityplayer.getRNG().nextFloat()) * 0.7F + 1.0F) * 2.0F);
entityplayer.inventoryContainer.detectAndSendChanges();
}
if (flag && itemstack.func_190926_b())
{
itemstack.func_190920_e(1);
sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, i);
EntityItem entityitem1 = entityplayer.dropItem(itemstack, false);
if (entityitem1 != null)
{
entityitem1.makeFakeItem();
}
}
else
{
sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, i - itemstack.func_190916_E());
EntityItem entityitem = entityplayer.dropItem(itemstack, false);
if (entityitem != null)
{
entityitem.setNoPickupDelay();
entityitem.setOwner(entityplayer.getName());
}
}
notifyCommandListener(sender, this, "commands.give.success", new Object[] {itemstack.getTextComponent(), Integer.valueOf(i), entityplayer.getName()});
}
}
示例3: execute
import net.minecraft.entity.item.EntityItem; //導入方法依賴的package包/類
/**
* Callback for when the command is executed
*/
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
if (args.length < 2)
{
throw new WrongUsageException("commands.give.usage", new Object[0]);
}
else
{
EntityPlayer entityplayer = getPlayer(server, sender, args[0]);
Item item = getItemByText(sender, args[1]);
int i = args.length >= 3 ? parseInt(args[2], 1, 64) : 1;
int j = args.length >= 4 ? parseInt(args[3]) : 0;
ItemStack itemstack = new ItemStack(item, i, j);
if (args.length >= 5)
{
String s = getChatComponentFromNthArg(sender, args, 4).getUnformattedText();
try
{
itemstack.setTagCompound(JsonToNBT.getTagFromJson(s));
}
catch (NBTException nbtexception)
{
throw new CommandException("commands.give.tagError", new Object[] {nbtexception.getMessage()});
}
}
boolean flag = entityplayer.inventory.addItemStackToInventory(itemstack);
if (flag)
{
entityplayer.worldObj.playSound((EntityPlayer)null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((entityplayer.getRNG().nextFloat() - entityplayer.getRNG().nextFloat()) * 0.7F + 1.0F) * 2.0F);
entityplayer.inventoryContainer.detectAndSendChanges();
}
if (flag && itemstack.stackSize <= 0)
{
itemstack.stackSize = 1;
sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, i);
EntityItem entityitem1 = entityplayer.dropItem(itemstack, false);
if (entityitem1 != null)
{
entityitem1.makeFakeItem();
}
}
else
{
sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, i - itemstack.stackSize);
EntityItem entityitem = entityplayer.dropItem(itemstack, false);
if (entityitem != null)
{
entityitem.setNoPickupDelay();
entityitem.setOwner(entityplayer.getName());
}
}
notifyCommandListener(sender, this, "commands.give.success", new Object[] {itemstack.getTextComponent(), Integer.valueOf(i), entityplayer.getName()});
}
}