本文整理匯總了Java中net.minecraftforge.event.ForgeEventFactory.onItemUseFinish方法的典型用法代碼示例。如果您正苦於以下問題:Java ForgeEventFactory.onItemUseFinish方法的具體用法?Java ForgeEventFactory.onItemUseFinish怎麽用?Java ForgeEventFactory.onItemUseFinish使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.minecraftforge.event.ForgeEventFactory
的用法示例。
在下文中一共展示了ForgeEventFactory.onItemUseFinish方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: insertItem
import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
@Nonnull
@Override
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
EntityPlayer player = getPlayer();
if (player == null || getFoodValue(stack) <= 0) return stack;
if (!okToFeed(stack, player)) return stack;
if (simulate) return ItemStack.EMPTY;
int startValue = stack.getCount();
ItemStack remainingItem = stack;
while (stack.getCount() > 0) {
remainingItem = stack.onItemUseFinish(player.world, player);
remainingItem = ForgeEventFactory.onItemUseFinish(player, stack, 0, remainingItem);
if (remainingItem.getCount() > 0 && (remainingItem != stack || remainingItem.getCount() != startValue)) {
if (!player.inventory.addItemStackToInventory(remainingItem) && remainingItem.getCount() > 0) {
player.dropItem(remainingItem, false);
}
}
if (stack.getCount() == startValue) break;
}
return remainingItem.getCount() > 0 ? remainingItem : ItemStack.EMPTY;
}
示例2: onItemUseFinish
import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
protected void onItemUseFinish()
{
if (this.itemInUse != null)
{
updateItemUse(this.itemInUse, 16);
int i = this.itemInUse.stackSize;
ItemStack itemstack = this.itemInUse.onFoodEaten(this.worldObj, this);
itemstack = ForgeEventFactory.onItemUseFinish(this, this.itemInUse, this.itemInUseCount, itemstack);
if ((itemstack != this.itemInUse) || ((itemstack != null) && (itemstack.stackSize != i)))
{
this.inventory.mainInventory[this.inventory.currentItem] = itemstack;
if ((itemstack != null) && (itemstack.stackSize == 0)) {
this.inventory.mainInventory[this.inventory.currentItem] = null;
}
}
clearItemInUse();
}
}
示例3: onItemUseFinish
import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
protected void onItemUseFinish()
{
if (this.itemInUse != null)
{
this.updateItemUse(this.itemInUse, 16);
int i = this.itemInUse.stackSize;
ItemStack itemstack = this.itemInUse.onFoodEaten(this.worldObj, this);
itemstack = ForgeEventFactory.onItemUseFinish(this, itemInUse, itemInUseCount, itemstack);
if (itemstack != this.itemInUse || itemstack != null && itemstack.stackSize != i)
{
this.inventory.mainInventory[this.inventory.currentItem] = itemstack;
if (itemstack != null && itemstack.stackSize == 0)
{
this.inventory.mainInventory[this.inventory.currentItem] = null;
}
}
this.clearItemInUse();
}
}
示例4: setInventorySlotContents
import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
@Override
public void setInventorySlotContents(int slot, ItemStack itemStack){
if(slot < 4) {
inventory[slot] = itemStack;
if(itemStack != null && itemStack.stackSize > getInventoryStackLimit()) {
itemStack.stackSize = getInventoryStackLimit();
}
} else {
EntityPlayer player = getPlayer();
if(dispenserUpgradeInserted) {
if(itemStack != null) {
int startValue = itemStack.stackSize;
while(itemStack.stackSize > 0) {
ItemStack remainingItem = itemStack.onFoodEaten(player.worldObj, player);
remainingItem = ForgeEventFactory.onItemUseFinish(player, itemStack, 0, remainingItem);
if(remainingItem != null && remainingItem.stackSize > 0 && (remainingItem != itemStack || remainingItem.stackSize != startValue)) {
if(!player.inventory.addItemStackToInventory(remainingItem) && remainingItem.stackSize > 0) {
player.dropPlayerItemWithRandomChoice(remainingItem, false);
}
}
if(itemStack.stackSize == startValue) break;
}
}
} else {
InventoryPlayer inventoryPlayer = player != null ? player.inventory : null;
if(inventoryPlayer != null) {
inventoryPlayer.setInventorySlotContents(slot - 4, itemStack);
} else if(worldObj != null && !worldObj.isRemote) {
EntityItem item = new EntityItem(worldObj, xCoord, yCoord, zCoord, itemStack);
worldObj.spawnEntityInWorld(item);
}
}
}
}
示例5: onItemUseFinish
import net.minecraftforge.event.ForgeEventFactory; //導入方法依賴的package包/類
protected void onItemUseFinish()
{
if (this.itemInUse != null)
{
this.updateItemUse(this.itemInUse, 16);
int i = this.itemInUse.stackSize;
// CraftBukkit start
org.bukkit.inventory.ItemStack craftItem = CraftItemStack.asBukkitCopy(this.itemInUse);
PlayerItemConsumeEvent event = new PlayerItemConsumeEvent((Player) this.getBukkitEntity(), craftItem);
worldObj.getServer().getPluginManager().callEvent(event);
if (event.isCancelled())
{
// Update client
if (this instanceof EntityPlayerMP)
{
((EntityPlayerMP) this).playerNetServerHandler.sendPacket(new S2FPacketSetSlot((byte) 0, openContainer.getSlotFromInventory((IInventory) this.inventory, this.inventory.currentItem).slotIndex, this.itemInUse));
// Spigot Start
((EntityPlayerMP) this).getBukkitEntity().updateInventory();
((EntityPlayerMP) this).getBukkitEntity().updateScaledHealth();
// Spigot End
}
return;
}
// Plugin modified the item, process it but don't remove it
if (!craftItem.equals(event.getItem()))
{
CraftItemStack.asNMSCopy(event.getItem()).onFoodEaten(this.worldObj, this);
// Update client
if (this instanceof EntityPlayerMP)
{
((EntityPlayerMP) this).playerNetServerHandler.sendPacket(new S2FPacketSetSlot((byte) 0, openContainer.getSlotFromInventory((IInventory) this.inventory, this.inventory.currentItem).slotIndex, this.itemInUse));
}
return;
}
// CraftBukkit end
ItemStack itemstack = this.itemInUse.onFoodEaten(this.worldObj, this);
itemstack = ForgeEventFactory.onItemUseFinish(this, itemInUse, itemInUseCount, itemstack);
if (itemstack != this.itemInUse || itemstack != null && itemstack.stackSize != i)
{
this.inventory.mainInventory[this.inventory.currentItem] = itemstack;
if (itemstack != null && itemstack.stackSize == 0)
{
this.inventory.mainInventory[this.inventory.currentItem] = null;
}
}
this.clearItemInUse();
}
}