forked from xjboss/KCauldronX
模块化方块捕获还原动作
This commit is contained in:
38
src/main/java/cc/capture/ItemSnapshot.java
Normal file
38
src/main/java/cc/capture/ItemSnapshot.java
Normal file
@ -0,0 +1,38 @@
|
||||
package cc.capture;
|
||||
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ItemSnapshot{
|
||||
|
||||
public final EntityPlayer mPlayer;
|
||||
public final ItemStack mItem;
|
||||
|
||||
private boolean mApply=false;
|
||||
|
||||
public ItemSnapshot(EntityPlayer pPlayer,ItemStack pItem){
|
||||
this.mPlayer=pPlayer;
|
||||
this.mItem=pItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将物品放到玩家身上
|
||||
*
|
||||
* @return 如果背包满,将生成物品在地上并返回false
|
||||
*/
|
||||
public boolean apply(){
|
||||
if(!this.mApply){
|
||||
this.mApply=true;
|
||||
this.mPlayer.inventory.addItemStackToInventory(this.mItem);
|
||||
|
||||
if(!this.mPlayer.inventory.addItemStackToInventory(this.mItem)){
|
||||
this.mPlayer.worldObj.spawnEntityInWorld(
|
||||
new EntityItem(this.mPlayer.worldObj,this.mPlayer.posX,this.mPlayer.posY,this.mPlayer.posZ,this.mItem));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user