From 70c1354a4a96698758a88c032866288f79de6f5a Mon Sep 17 00:00:00 2001 From: Benjamin Culkin Date: Sat, 24 Aug 2024 08:16:37 -0400 Subject: Initial commit --- .../plusplus/fbs/pottery/usable/PotteryBase.java | 157 +++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 src/main/java/jp/plusplus/fbs/pottery/usable/PotteryBase.java (limited to 'src/main/java/jp/plusplus/fbs/pottery/usable/PotteryBase.java') diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryBase.java b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryBase.java new file mode 100644 index 0000000..ba0ed3f --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryBase.java @@ -0,0 +1,157 @@ +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