package jp.plusplus.fbs.pottery.usable;
import jp.plusplus.fbs.api.IPottery;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import javax.annotation.Nullable;
/**
* Created by plusplus_F on 2016/03/30.
* 魔法の壺の基底クラス
*/
public abstract class PotteryBase {
public static final String ITEM_STACKS="ItemStacks";
public NBTTagCompound getPotteryNBT(ItemStack pottery){
if(!pottery.hasTagCompound()){
pottery.setTagCompound(new NBTTagCompound());
}
return pottery.getTagCompound();
}
/**
* 壺のUnlocalizedNameを返す
* ここで返した文字列がそのままローカライズに使用される
* @return UnlocalizedName
*/
public abstract String getUnlocalizedName();
/**
* 名前の後ろにつく付加的な情報を返す
* @param pottery 壺のアイテムスタック
* @return
*/
public String getNameModifier(ItemStack pottery){
IPottery ip=(IPottery)((ItemBlock)pottery.getItem()).field_150939_a;
int slot;
switch (ip.getSize(pottery.getTagCompound())){
case SMALL: slot=9; break;
case LARGE: slot=27; break;
default: slot=18; break;
}
if(pottery.getTagCompound().hasKey(ITEM_STACKS)){
NBTTagList list=(NBTTagList)pottery.getTagCompound().getTag(ITEM_STACKS);
slot-=list.tagCount();
}
return "["+slot+"]";
}
/**
* 売却値にかかる補正を返す
* @param pottery 壺のアイテムスタック
* @return 売却値補正
*/
public float getPriceScale(ItemStack pottery){
return 1.f;
}
/**
* 壺が焼かれた時に呼び出される
* @param pottery 壺のアイテムスタック
*/
public void onBaked(ItemStack pottery){}
/**
* この壺が使用できるか判定する
* @param player 所有者
* @param pottery 壺のアイテムスタック
* @return
*/
public boolean canUse(EntityPlayer player, ItemStack pottery){
return true;
}
/**
* 壺を使用したときの処理
* @param player 所有者
* @param pottery 壺のアイテムスタック
* @return
*/
public abstract ItemStack onUse(EntityPlayer player, ItemStack pottery);
/**
* 壺が破壊されたときの処理
* @param player 所有者
* @param pottery 壺のアイテムスタック
*/
public void onCrash(EntityPlayer player, ItemStack pottery){
NBTTagCompound nbt=getPotteryNBT(pottery);
if(nbt.hasKey(ITEM_STACKS)){
NBTTagList list=(NBTTagList)nbt.getTag(ITEM_STACKS);
for(int i=0;i