diff options
Diffstat (limited to 'src/main/java/jp/plusplus/fbs/pottery/usable')
38 files changed, 1156 insertions, 0 deletions
diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryAppraisal.class b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryAppraisal.class Binary files differnew file mode 100644 index 0000000..da08fcd --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryAppraisal.class diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryAppraisal.java b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryAppraisal.java new file mode 100644 index 0000000..62cc097 --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryAppraisal.java @@ -0,0 +1,40 @@ +package jp.plusplus.fbs.pottery.usable;
+
+import jp.plusplus.fbs.alchemy.AlchemyRegistry;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.ItemStack;
+import net.minecraft.item.crafting.FurnaceRecipes;
+
+import javax.annotation.Nullable;
+
+/**
+ * Created by plusplus_F on 2016/04/02.
+ */
+public class PotteryAppraisal extends PotteryKeep {
+ @Override
+ public String getUnlocalizedName() {
+ return "pottery.fbs.pot.appraisal";
+ }
+
+ @Override
+ public float getPriceScale(ItemStack pottery){
+ return 1.5f;
+ }
+
+ @Override
+ public ItemStack onInventoryClosing(EntityPlayer player, ItemStack pottery, int index, @Nullable ItemStack itemStack){
+ if(itemStack!=null && !pottery.getTagCompound().getBoolean(CHANGED_INDEXES+index) && AlchemyRegistry.CanAppraisal(itemStack)){
+ ItemStack ret=AlchemyRegistry.GetRandomAppraisal(itemStack);
+ if(ret!=null){
+ ret.stackSize=Math.min(itemStack.stackSize, ret.getMaxStackSize());
+ return ret;
+ }
+ }
+ return itemStack;
+ }
+
+ @Override
+ public boolean canTakeStack(EntityPlayer player, ItemStack pottery, int index, ItemStack itemStack){
+ return !pottery.getTagCompound().getBoolean(CHANGED_INDEXES+index);
+ }
+}
diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryBase$1.class b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryBase$1.class Binary files differnew file mode 100644 index 0000000..90c8c4e --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryBase$1.class diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryBase.class b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryBase.class Binary files differnew file mode 100644 index 0000000..fbff80e --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryBase.class 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を返す<br>
+ * ここで返した文字列がそのままローカライズに使用される
+ * @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<list.tagCount();i++){
+ NBTTagCompound tag=list.getCompoundTagAt(i);
+ ItemStack itemStack=ItemStack.loadItemStackFromNBT(tag);
+ player.entityDropItem(itemStack, player.getEyeHeight());
+ }
+ }
+ }
+
+ /**
+ * 魔法の壺のインベントリが開く際に全てのスロットに対して行われる処理
+ * @param player 所有者
+ * @param pottery 壺のアイテムスタック
+ * @param index スロットインデックス
+ * @param itemStack 何か処理するアイテムスタック
+ * @return スロットに格納されるItemStack
+ */
+ public ItemStack onInventoryOpening(EntityPlayer player, ItemStack pottery, int index, @Nullable ItemStack itemStack){
+ return itemStack;
+ }
+
+ /**
+ * 魔法の壺のインベントリが閉じる際に全てのスロットに対して行われる処理
+ * @param player 所有者
+ * @param pottery 壺のアイテムスタック
+ * @param index スロットインデックス
+ * @param itemStack 何か処理するアイテムスタック
+ * @return NBTに書き込まれるItemStack
+ */
+ public ItemStack onInventoryClosing(EntityPlayer player, ItemStack pottery, int index, @Nullable ItemStack itemStack){
+ return itemStack;
+ }
+
+ /**
+ * 魔法の壺のインベントリがそのアイテムが適しているか
+ * @param player 所有者
+ * @param pottery 壺のアイテムスタック
+ * @param index スロットインデックス
+ * @param itemStack 判定アイテムスタック
+ * @return スロットに入るかどうか
+ */
+ public boolean isItemValid(EntityPlayer player, ItemStack pottery, int index, ItemStack itemStack){
+ return true;
+ }
+
+ /**
+ * 魔法の壺のインベントリからそのアイテムを取り出せるか
+ * @param player 所有者
+ * @param pottery 壺のアイテムスタック
+ * @param index スロットインデックス
+ * @param itemStack 判定アイテムスタック
+ * @return 取り出せるかどうか
+ */
+ public boolean canTakeStack(EntityPlayer player, ItemStack pottery, int index, ItemStack itemStack){
+ return true;
+ }
+}
diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryChange.class b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryChange.class Binary files differnew file mode 100644 index 0000000..da74aa2 --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryChange.class diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryChange.java b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryChange.java new file mode 100644 index 0000000..3fe76f1 --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryChange.java @@ -0,0 +1,74 @@ +package jp.plusplus.fbs.pottery.usable;
+
+import com.google.common.collect.Maps;
+import cpw.mods.fml.common.registry.GameData;
+import net.minecraft.block.Block;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemBlock;
+import net.minecraft.item.ItemStack;
+
+import javax.annotation.Nullable;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.Random;
+
+/**
+ * Created by plusplus_F on 2016/03/30.
+ */
+public class PotteryChange extends PotteryKeep {
+
+ private static Integer[] itemIds;
+
+ private Random rand=new Random();
+
+ @Override
+ public String getUnlocalizedName() {
+ return "pottery.fbs.pot.change";
+ }
+
+ @Override
+ public float getPriceScale(ItemStack pottery){
+ return 5.0f;
+ }
+
+ @Override
+ public ItemStack onInventoryClosing(EntityPlayer player, ItemStack pottery, int index, @Nullable ItemStack itemStack){
+ if(itemStack!=null && !pottery.getTagCompound().getBoolean(CHANGED_INDEXES+index)){
+ if(itemIds==null){
+ Map<String,Integer> idMapping = Maps.newHashMap();
+ GameData.itemRegistry.serializeInto(idMapping);
+ itemIds=new Integer[idMapping.size()];
+ idMapping.values().toArray(itemIds);
+ }
+
+ for(int i=0;i<10;i++){
+ Item item=Item.getItemById(rand.nextInt(itemIds.length));
+ if(item==null) continue;
+
+ if(item instanceof ItemBlock){
+ Block b=((ItemBlock) item).field_150939_a;
+ Item d=b.getItemDropped(0, rand, 0);
+ if(d==null || d==Item.getItemById(0) || b.quantityDropped(0, 0, rand)==0){
+ continue;
+ }
+ }
+
+ ArrayList<ItemStack> list=new ArrayList<ItemStack>();
+ item.getSubItems(item, item.getCreativeTab(), list);
+
+ if(!list.isEmpty()){
+ ItemStack ret=list.get(rand.nextInt(list.size()));
+ ret.stackSize=Math.min(ret.getMaxStackSize(), itemStack.stackSize);
+ return ret;
+ }
+ }
+ }
+ return itemStack;
+ }
+
+ @Override
+ public boolean canTakeStack(EntityPlayer player, ItemStack pottery, int index, ItemStack itemStack){
+ return !pottery.getTagCompound().getBoolean(CHANGED_INDEXES+index);
+ }
+}
diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryCrucible.class b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryCrucible.class Binary files differnew file mode 100644 index 0000000..efc7d21 --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryCrucible.class diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryCrucible.java b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryCrucible.java new file mode 100644 index 0000000..ef37d9d --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryCrucible.java @@ -0,0 +1,107 @@ +package jp.plusplus.fbs.pottery.usable;
+
+import net.minecraft.entity.EntityList;
+import net.minecraft.entity.EntityLiving;
+import net.minecraft.entity.monster.EntityCreeper;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.nbt.NBTTagList;
+import net.minecraft.world.World;
+
+import javax.annotation.Nullable;
+import java.util.ArrayList;
+
+/**
+ * Created by plusplus_F on 2016/04/02.
+ */
+public class PotteryCrucible extends PotteryUsableLimitted {
+ public static ArrayList<String> mobNames=new ArrayList<String>();
+
+ public PotteryCrucible(){
+ if(mobNames.isEmpty()){
+ mobNames.add("Zombie");
+ mobNames.add("Skeleton");
+ mobNames.add("Spider");
+ mobNames.add("Creeper");
+ mobNames.add("Enderman");
+ mobNames.add("Blaze");
+ mobNames.add("PigZombie");
+ mobNames.add("Slime");
+ mobNames.add("Ghast");
+ mobNames.add("CaveSpider");
+ mobNames.add("Silverfish");
+ mobNames.add("LavaSlime");
+ mobNames.add("Bat");
+ mobNames.add("Witch");
+ }
+ }
+
+ @Override
+ public String getUnlocalizedName() {
+ return "pottery.fbs.pot.monster";
+ }
+
+ @Override
+ public void effect(EntityPlayer player, ItemStack pottery) {
+ World w=player.worldObj;
+
+ if(!w.isRemote){
+ int mobC = 1;
+ int count = 0;
+ int max = mobNames.size();
+ for (int i = 0; i < 100 && count < mobC; i++) {
+ int n = rand.nextInt(max);
+ if (spawnEntityLiving(mobNames.get(n), w, player.posX, player.posY, player.posZ)) {
+ count++;
+ }
+ }
+ }
+ }
+
+ @Override
+ public void onCrash(EntityPlayer player, ItemStack pottery){
+ NBTTagCompound nbt=getPotteryNBT(pottery);
+ if(!player.worldObj.isRemote){
+ int mobC = nbt.getInteger(USE_COUNT);
+ int count = 0;
+ int max = mobNames.size();
+ for (int i = 0; i < 100 && count < mobC; i++) {
+ int n = rand.nextInt(max);
+ if (spawnEntityLiving(mobNames.get(n), player.worldObj, player.posX, player.posY, player.posZ)) {
+ count++;
+ }
+ }
+ }
+ }
+
+ private boolean spawnEntityLiving(String name, World world, double x, double y, double z){
+ EntityLiving entity = (EntityLiving) EntityList.createEntityByName(name, world);
+ if (entity == null) return false;
+ entity.onSpawnWithEgg(null);
+
+
+ boolean flag=false;
+ for(int i=0;i<30;i++) {
+ double x1 = x + 0.5 + (rand.nextDouble() - rand.nextDouble()) * 3;
+ double y1 = y+rand.nextInt(3);
+ double z1 = z + 0.5 + (rand.nextDouble() - rand.nextDouble()) * 3;
+ float a = rand.nextFloat() * 360.0F;
+ entity.setLocationAndAngles(x1, y1, z1, a, 0);
+
+ world.spawnEntityInWorld(entity);
+ entity.spawnExplosionParticle();
+ entity.playLivingSound();
+ flag=true;
+ break;
+ }
+
+ if(flag){
+ if(entity instanceof EntityCreeper && rand.nextFloat()<0.25f) {
+ entity.getDataWatcher().updateObject(17, new Byte((byte)1));
+ }
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryEnchantment$1.class b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryEnchantment$1.class Binary files differnew file mode 100644 index 0000000..0e6df6e --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryEnchantment$1.class diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryEnchantment.class b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryEnchantment.class Binary files differnew file mode 100644 index 0000000..c7a020f --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryEnchantment.class diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryEnchantment.java b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryEnchantment.java new file mode 100644 index 0000000..451e0ff --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryEnchantment.java @@ -0,0 +1,61 @@ +package jp.plusplus.fbs.pottery.usable;
+
+import com.google.common.collect.Maps;
+import cpw.mods.fml.common.registry.GameData;
+import jp.plusplus.fbs.api.IPottery;
+import net.minecraft.block.Block;
+import net.minecraft.enchantment.EnchantmentHelper;
+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 javax.annotation.Nullable;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.Random;
+
+/**
+ * Created by plusplus_F on 2016/03/30.
+ */
+public class PotteryEnchantment extends PotteryKeep {
+ private Random rand=new Random();
+
+ @Override
+ public String getUnlocalizedName() {
+ return "pottery.fbs.pot.enchant";
+ }
+
+ @Override
+ public float getPriceScale(ItemStack pottery){
+ return 3.5f;
+ }
+
+ @Override
+ public ItemStack onInventoryClosing(EntityPlayer player, ItemStack pottery, int index, @Nullable ItemStack itemStack){
+ NBTTagCompound nbt=pottery.getTagCompound();
+
+ if(itemStack!=null && !nbt.getBoolean(CHANGED_INDEXES + index)){
+ if(!itemStack.isItemEnchanted() && itemStack.isItemEnchantable()){
+ IPottery ip=(IPottery)((ItemBlock)pottery.getItem()).field_150939_a;
+
+ int lv;
+ switch (ip.getGrade(nbt)){
+ case BAD: lv=5; break;
+ case GOOD: lv=20; break;
+ case GREAT: lv=30; break;
+ case SOULFUL: lv=40; break;
+ default: lv=10; break;
+ }
+ return EnchantmentHelper.addRandomEnchantment(rand, itemStack, lv);
+ }
+ }
+ return itemStack;
+ }
+
+ @Override
+ public boolean canTakeStack(EntityPlayer player, ItemStack pottery, int index, ItemStack itemStack){
+ return !pottery.getTagCompound().getBoolean(CHANGED_INDEXES+index);
+ }
+}
diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryFurnace.class b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryFurnace.class Binary files differnew file mode 100644 index 0000000..7086075 --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryFurnace.class diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryFurnace.java b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryFurnace.java new file mode 100644 index 0000000..8f979bf --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryFurnace.java @@ -0,0 +1,48 @@ +package jp.plusplus.fbs.pottery.usable;
+
+import com.google.common.collect.Maps;
+import cpw.mods.fml.common.registry.GameData;
+import net.minecraft.block.Block;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemBlock;
+import net.minecraft.item.ItemStack;
+import net.minecraft.item.crafting.FurnaceRecipes;
+
+import javax.annotation.Nullable;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.Random;
+
+/**
+ * Created by plusplus_F on 2016/04/02.
+ */
+public class PotteryFurnace extends PotteryKeep {
+ @Override
+ public String getUnlocalizedName() {
+ return "pottery.fbs.pot.furnace";
+ }
+
+ @Override
+ public float getPriceScale(ItemStack pottery){
+ return 1.5f;
+ }
+
+ @Override
+ public ItemStack onInventoryClosing(EntityPlayer player, ItemStack pottery, int index, @Nullable ItemStack itemStack){
+ if(itemStack!=null && !pottery.getTagCompound().getBoolean(CHANGED_INDEXES+index)){
+ ItemStack ret=FurnaceRecipes.smelting().getSmeltingResult(itemStack);
+ if(ret!=null){
+ ItemStack t=ret.copy();
+ t.stackSize=Math.min(itemStack.stackSize, t.getMaxStackSize());
+ return t;
+ }
+ }
+ return itemStack;
+ }
+
+ @Override
+ public boolean canTakeStack(EntityPlayer player, ItemStack pottery, int index, ItemStack itemStack){
+ return !pottery.getTagCompound().getBoolean(CHANGED_INDEXES+index);
+ }
+}
diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryKeep.class b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryKeep.class Binary files differnew file mode 100644 index 0000000..9675d30 --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryKeep.class diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryKeep.java b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryKeep.java new file mode 100644 index 0000000..fe318cf --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryKeep.java @@ -0,0 +1,39 @@ +package jp.plusplus.fbs.pottery.usable;
+
+import com.google.common.collect.Maps;
+import cpw.mods.fml.common.registry.GameData;
+import jp.plusplus.fbs.FBS;
+import net.minecraft.block.Block;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemBlock;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.MathHelper;
+
+import javax.annotation.Nullable;
+import java.util.ArrayList;
+import java.util.Map;
+
+/**
+ * Created by plusplus_F on 2016/03/30.
+ */
+public class PotteryKeep extends PotteryBase {
+ public static final String CHANGED_INDEXES="ChangedIndex";
+
+ @Override
+ public String getUnlocalizedName() {
+ return "pottery.fbs.pot.keep";
+ }
+
+ @Override
+ public ItemStack onInventoryOpening(EntityPlayer player, ItemStack pottery, int index, @Nullable ItemStack itemStack){
+ pottery.getTagCompound().setBoolean(CHANGED_INDEXES+index, itemStack!=null);
+ return itemStack;
+ }
+
+ @Override
+ public ItemStack onUse(EntityPlayer player, ItemStack pottery) {
+ player.openGui(FBS.instance, FBS.GUI_MAGIC_POT_ID, player.worldObj, MathHelper.floor_double(player.posX), MathHelper.floor_double(player.posY), MathHelper.floor_double(player.posZ));
+ return pottery;
+ }
+}
diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryLottery.class b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryLottery.class Binary files differnew file mode 100644 index 0000000..beb0309 --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryLottery.class diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryLottery.java b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryLottery.java new file mode 100644 index 0000000..33b2fd1 --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryLottery.java @@ -0,0 +1,44 @@ +package jp.plusplus.fbs.pottery.usable;
+
+import jp.plusplus.fbs.FBS;
+import jp.plusplus.fbs.Registry;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.ChatComponentText;
+import net.minecraft.util.MathHelper;
+import net.minecraft.util.StatCollector;
+import net.minecraft.world.World;
+
+/**
+ * Created by plusplus_F on 2016/04/02.
+ */
+public class PotteryLottery extends PotteryUsableLimitted {
+ @Override
+ public String getUnlocalizedName() {
+ return "pottery.fbs.pot.lottery";
+ }
+
+ @Override
+ public float getPriceScale(ItemStack pottery){
+ return 0.8f*super.getPriceScale(pottery);
+ }
+
+ @Override
+ public void effect(EntityPlayer player, ItemStack pottery) {
+ World world=player.worldObj;
+
+ if(!world.isRemote){
+ if(world.rand.nextInt(256)==1){
+ //願い判定
+ player.openGui(FBS.instance, FBS.GUI_WISH_ID, world, MathHelper.floor_double(player.posX), MathHelper.floor_double(player.posY), MathHelper.floor_double(player.posZ));
+ }
+ else{
+ //ランダムにメッセージ
+ String m= Registry.GetRandomMessage();
+ int v=Registry.GetRandomMessageVariant(m);
+ player.addChatComponentMessage(new ChatComponentText("<"+ StatCollector.translateToLocal(getUnlocalizedName())+">"+Registry.GetLocalizedFortuneCookieMessage(m, v)));
+ }
+ }
+ }
+
+}
diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotterySenaka.class b/src/main/java/jp/plusplus/fbs/pottery/usable/PotterySenaka.class Binary files differnew file mode 100644 index 0000000..e75b8db --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotterySenaka.class diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotterySenaka.java b/src/main/java/jp/plusplus/fbs/pottery/usable/PotterySenaka.java new file mode 100644 index 0000000..7839376 --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotterySenaka.java @@ -0,0 +1,41 @@ +package jp.plusplus.fbs.pottery.usable;
+
+import jp.plusplus.fbs.FBS;
+import jp.plusplus.fbs.api.IPottery;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.ItemBlock;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.MathHelper;
+import net.minecraft.world.World;
+import shift.sextiarysector.api.SextiarySectorAPI;
+
+import javax.annotation.Nullable;
+
+/**
+ * Created by plusplus_F on 2016/03/30.
+ */
+public class PotterySenaka extends PotteryUsableLimitted {
+ public static final String USE_COUNT="UseCount";
+
+ @Override
+ public String getUnlocalizedName() {
+ return "pottery.fbs.pot.senaka";
+ }
+
+ @Override
+ public float getPriceScale(ItemStack pottery){
+ return 2.f*super.getPriceScale(pottery);
+ }
+
+ @Override
+ public void effect(EntityPlayer player, ItemStack pottery) {
+ player.heal(player.getMaxHealth());
+ player.getFoodStats().addStats(20, 1);
+ if(FBS.cooperatesSS2) forSS2(player);
+ }
+
+ protected void forSS2(EntityPlayer player){
+ SextiarySectorAPI.addMoistureStats(player, 20, 1);
+ SextiarySectorAPI.addStaminaStats(player, 100, 1);
+ }
+}
diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryTaboo.class b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryTaboo.class Binary files differnew file mode 100644 index 0000000..1b250ca --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryTaboo.class diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryTaboo.java b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryTaboo.java new file mode 100644 index 0000000..df1f298 --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryTaboo.java @@ -0,0 +1,72 @@ +package jp.plusplus.fbs.pottery.usable;
+
+import jp.plusplus.fbs.AchievementRegistry;
+import jp.plusplus.fbs.api.FBSEntityPropertiesAPI;
+import jp.plusplus.fbs.api.IPottery;
+import jp.plusplus.fbs.exprop.FBSEntityProperties;
+import jp.plusplus.fbs.exprop.SanityManager;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.ItemBlock;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.nbt.NBTTagList;
+import net.minecraft.potion.Potion;
+import net.minecraft.potion.PotionEffect;
+import net.minecraft.util.ChatComponentText;
+import net.minecraft.util.DamageSource;
+import net.minecraft.util.StatCollector;
+
+/**
+ * Created by plusplus_F on 2016/04/02.
+ */
+public class PotteryTaboo extends PotteryUsableLimitted {
+
+ @Override
+ public float getPriceScale(ItemStack pottery){
+ return 3.5f*super.getPriceScale(pottery);
+ }
+
+ @Override
+ public void effect(EntityPlayer player, ItemStack pottery) {
+ if(player.worldObj.isRemote) return;
+
+ FBSEntityProperties properties=FBSEntityProperties.get(player);
+
+ int now=properties.getSanity();
+ properties.setSanity(now/2+1);
+ int san=now-properties.getSanity();
+ if(san>0){
+ player.addChatComponentMessage(new ChatComponentText(String.format(StatCollector.translateToLocal("info.fbs.san.1"), san)));
+ player.triggerAchievement(AchievementRegistry.insanity);
+
+ if(san>=2 && 100*san/now>=20){
+ //発狂判定
+ player.addChatComponentMessage(new ChatComponentText(StatCollector.translateToLocal("info.fbs.san.2")));
+ player.addPotionEffect(new PotionEffect(Potion.confusion.getId(), 20 * 15, 2));
+ player.addPotionEffect(new PotionEffect(Potion.hunger.getId(), 20*15, 1));
+ player.triggerAchievement(AchievementRegistry.madness);
+ }
+ }
+ SanityManager.sendPacket(player);
+
+ if(!player.isDead){
+ IPottery ip=(IPottery)((ItemBlock)pottery.getItem()).field_150939_a;
+
+ int dur=20*30*(ip.getGrade(pottery.getTagCompound()).getValue()+1);
+
+ player.addPotionEffect(new PotionEffect(Potion.damageBoost.getId(), dur, 2));
+ player.addPotionEffect(new PotionEffect(Potion.resistance.getId(), dur, 2));
+ player.addPotionEffect(new PotionEffect(Potion.moveSpeed.getId(), dur, 2));
+ }
+ }
+
+ @Override
+ public String getUnlocalizedName() {
+ return "pottery.fbs.pot.taboo";
+ }
+
+ public void onCrash(EntityPlayer player, ItemStack pottery){
+ if(player.worldObj.isRemote) return;
+ SanityManager.loseSanity(player, 10, 100, true);
+ }
+}
diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryUnbreakable.class b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryUnbreakable.class Binary files differnew file mode 100644 index 0000000..3843db3 --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryUnbreakable.class diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryUnbreakable.java b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryUnbreakable.java new file mode 100644 index 0000000..a4b2ddd --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryUnbreakable.java @@ -0,0 +1,39 @@ +package jp.plusplus.fbs.pottery.usable;
+
+import com.google.common.collect.Maps;
+import cpw.mods.fml.common.registry.GameData;
+import net.minecraft.block.Block;
+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 javax.annotation.Nullable;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.Random;
+
+/**
+ * Created by plusplus_F on 2016/03/30.
+ */
+public class PotteryUnbreakable extends PotteryKeep {
+ @Override
+ public String getUnlocalizedName() {
+ return "pottery.fbs.pot.unbreakable";
+ }
+
+ @Override
+ public float getPriceScale(ItemStack pottery){
+ return 5.0f;
+ }
+
+ @Override
+ public boolean canTakeStack(EntityPlayer player, ItemStack pottery, int index, ItemStack itemStack){
+ return !pottery.getTagCompound().getBoolean(CHANGED_INDEXES+index);
+ }
+
+ @Override
+ public void onCrash(EntityPlayer player, ItemStack pottery){}
+}
diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryUsableLimitted$1.class b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryUsableLimitted$1.class Binary files differnew file mode 100644 index 0000000..85bb083 --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryUsableLimitted$1.class diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryUsableLimitted.class b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryUsableLimitted.class Binary files differnew file mode 100644 index 0000000..d63d7ce --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryUsableLimitted.class diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryUsableLimitted.java b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryUsableLimitted.java new file mode 100644 index 0000000..1dbcb69 --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryUsableLimitted.java @@ -0,0 +1,71 @@ +package jp.plusplus.fbs.pottery.usable;
+
+import jp.plusplus.fbs.FBS;
+import jp.plusplus.fbs.api.IPottery;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.ItemBlock;
+import net.minecraft.item.ItemStack;
+import net.minecraft.world.World;
+import shift.sextiarysector.api.SextiarySectorAPI;
+
+import javax.annotation.Nullable;
+import java.util.Random;
+
+/**
+ * Created by plusplus_F on 2016/04/02.
+ */
+public abstract class PotteryUsableLimitted extends PotteryBase {
+ public static final String USE_COUNT="UseCount";
+ public Random rand=new Random();
+
+ /**
+ * 壺そのものの効果
+ * @param player 所有者
+ * @param pottery 壺のアイテムスタック
+ */
+ public abstract void effect(EntityPlayer player, ItemStack pottery);
+
+ @Override
+ public String getNameModifier(ItemStack pottery){
+ return "["+pottery.getTagCompound().getInteger(USE_COUNT)+"]";
+ }
+
+ @Override
+ public float getPriceScale(ItemStack pottery){
+ return 0.8f+0.1f*pottery.getTagCompound().getInteger(USE_COUNT);
+ }
+
+ @Override
+ public void onBaked(ItemStack pottery){
+ IPottery ip=(IPottery)((ItemBlock) pottery.getItem()).field_150939_a;
+
+ int c;
+ switch (ip.getSize(pottery.getTagCompound())){
+ case SMALL: c=2; break;
+ case LARGE: c=8; break;
+ default: c=5; break;
+ }
+ c+=rand.nextInt(c/2);
+
+ switch (ip.getGrade(pottery.getTagCompound())){
+ case BAD: c=(int)(c*0.8); break;
+ case GOOD: c=(int)(c*1.5); break;
+ case GREAT: c=(int)(c*2); break;
+ case SOULFUL: c=(int)(c*3); break;
+ default: break;
+ }
+
+ pottery.getTagCompound().setInteger(USE_COUNT, c);
+ }
+
+ @Override
+ public ItemStack onUse(EntityPlayer player, ItemStack pottery) {
+ int c=pottery.getTagCompound().getInteger(USE_COUNT);
+ if(c>0){
+ effect(player, pottery);
+ if(!player.capabilities.isCreativeMode) pottery.getTagCompound().setInteger(USE_COUNT, c-1);
+ player.swingItem();
+ }
+ return pottery;
+ }
+}
diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryVoid.class b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryVoid.class Binary files differnew file mode 100644 index 0000000..bc28a2a --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryVoid.class diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryVoid.java b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryVoid.java new file mode 100644 index 0000000..62fbf3d --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/PotteryVoid.java @@ -0,0 +1,26 @@ +package jp.plusplus.fbs.pottery.usable;
+
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.ItemStack;
+
+import javax.annotation.Nullable;
+
+/**
+ * Created by plusplus_F on 2016/03/30.
+ */
+public class PotteryVoid extends PotteryKeep {
+ @Override
+ public String getUnlocalizedName() {
+ return "pottery.fbs.pot.void";
+ }
+
+ @Override
+ public float getPriceScale(ItemStack pottery){
+ return 0.5f;
+ }
+
+ public ItemStack onInventoryClosing(EntityPlayer player, ItemStack pottery, int index, @Nullable ItemStack itemStack){
+ return null;
+ }
+
+}
diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/container/ContainerPotteryUsableBase.class b/src/main/java/jp/plusplus/fbs/pottery/usable/container/ContainerPotteryUsableBase.class Binary files differnew file mode 100644 index 0000000..425e8ea --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/container/ContainerPotteryUsableBase.class diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/container/ContainerPotteryUsableBase.java b/src/main/java/jp/plusplus/fbs/pottery/usable/container/ContainerPotteryUsableBase.java new file mode 100644 index 0000000..0c679c5 --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/container/ContainerPotteryUsableBase.java @@ -0,0 +1,95 @@ +package jp.plusplus.fbs.pottery.usable.container;
+
+import jp.plusplus.fbs.container.slot.SlotShowOnly;
+import jp.plusplus.fbs.item.ItemCore;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.InventoryPlayer;
+import net.minecraft.inventory.Container;
+import net.minecraft.inventory.ContainerChest;
+import net.minecraft.inventory.Slot;
+import net.minecraft.item.ItemStack;
+
+/**
+ * Created by plusplus_F on 2016/03/30.
+ */
+public class ContainerPotteryUsableBase extends Container {
+ public ItemStack currentItem;
+ public EntityPlayer player;
+ public InventoryPotteryUsable inventory;
+ public int inventoryRows;
+
+ public ContainerPotteryUsableBase(EntityPlayer player) {
+ this.player = player;
+ currentItem = player.getCurrentEquippedItem();
+ inventory = new InventoryPotteryUsable(player);
+
+ //壺のスロット
+ inventoryRows = (inventory.getSizeInventory() + 8) / 9;
+ for (int i = 0; i < inventory.getSizeInventory(); i++) {
+ addSlotToContainer(new SlotPotteryUsable(inventory, i, 8 + (i % 9) * 18, 18 + (i / 9) * 18));
+ }
+
+ //player slots
+ int y = (inventoryRows - 4) * 18;
+ for (int j = 0; j < 3; ++j) {
+ for (int k = 0; k < 9; ++k) {
+ this.addSlotToContainer(new Slot(player.inventory, k + j * 9 + 9, 8 + k * 18, 103 + j * 18 + y));
+ }
+ }
+ for (int j = 0; j < 9; ++j) {
+ if (j == inventory.potteryStackIndex) this.addSlotToContainer(new SlotShowOnly(player.inventory, j, 8 + j * 18, 161 + y));
+ else this.addSlotToContainer(new Slot(player.inventory, j, 8 + j * 18, 161 + y));
+ }
+
+ inventory.openInventory();
+ }
+
+ public void onContainerClosed(EntityPlayer p_75134_1_) {
+ super.onContainerClosed(p_75134_1_);
+ inventory.closeInventory();
+ }
+
+ @Override
+ public boolean canInteractWith(EntityPlayer p_75145_1_) {
+ return true;
+ }
+
+ @Override
+ public ItemStack transferStackInSlot(EntityPlayer player1, int slotIndex) {
+ ItemStack itemstack = null;
+ Slot slot = (Slot) this.inventorySlots.get(slotIndex);
+
+ if (slot != null && slot.getHasStack()) {
+ ItemStack itemstack1 = slot.getStack();
+ itemstack = itemstack1.copy();
+
+ if(slot.getStack()==null || slotIndex==inventory.potteryStackIndex){
+ //スロットがNULLだったり開いてる壺なら何もしない
+ return null;
+ }
+ else if (slotIndex < this.inventory.getSizeInventory()) {
+ //壺のインベントリ内であれば他所に移す
+ if (!this.mergeItemStack(itemstack1, this.inventory.getSizeInventory(), this.inventorySlots.size(), true)) {
+ return null;
+ }
+ }
+ else if(!inventory.isItemValidForSlot(slotIndex, itemstack)){
+ //プレイヤーのインベントリにあり、それが壺のインベントリに適さない場合何もしない
+ return null;
+ }
+ else if (!this.mergeItemStack(itemstack1, 0, this.inventory.getSizeInventory(), false)) {
+ //壺のインベントリに移せるか試してる
+ return null;
+ }
+
+ //アイテムの消去と更新処理
+ if (itemstack1.stackSize == 0) {
+ slot.putStack((ItemStack) null);
+ } else {
+ slot.onSlotChanged();
+ }
+ }
+
+ return itemstack;
+ }
+}
diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/container/GuiPotteryUsableBase.class b/src/main/java/jp/plusplus/fbs/pottery/usable/container/GuiPotteryUsableBase.class Binary files differnew file mode 100644 index 0000000..23856fb --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/container/GuiPotteryUsableBase.class diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/container/GuiPotteryUsableBase.java b/src/main/java/jp/plusplus/fbs/pottery/usable/container/GuiPotteryUsableBase.java new file mode 100644 index 0000000..b3c9967 --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/container/GuiPotteryUsableBase.java @@ -0,0 +1,40 @@ +package jp.plusplus.fbs.pottery.usable.container;
+
+import net.minecraft.client.gui.inventory.GuiChest;
+import net.minecraft.client.gui.inventory.GuiContainer;
+import net.minecraft.client.resources.I18n;
+import net.minecraft.inventory.Container;
+import net.minecraft.util.ResourceLocation;
+import org.lwjgl.opengl.GL11;
+
+/**
+ * Created by plusplus_F on 2016/03/30.
+ */
+public class GuiPotteryUsableBase extends GuiContainer {
+ private static final ResourceLocation field_147017_u = new ResourceLocation("textures/gui/container/generic_54.png");
+ private ContainerPotteryUsableBase container;
+
+ public GuiPotteryUsableBase(ContainerPotteryUsableBase p_i1072_1_) {
+ super(p_i1072_1_);
+ this.container=p_i1072_1_;
+ this.allowUserInput = false;
+ short short1 = 222;
+ int i = short1 - 108;
+ this.ySize = i + container.inventoryRows * 18;
+ }
+
+ @Override
+ protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
+ this.fontRendererObj.drawString(container.inventory.getInventoryName(), 8, 6, 4210752);
+ }
+
+ @Override
+ protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) {
+ GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
+ this.mc.getTextureManager().bindTexture(field_147017_u);
+ int k = (this.width - this.xSize) / 2;
+ int l = (this.height - this.ySize) / 2;
+ this.drawTexturedModalRect(k, l, 0, 0, this.xSize, container.inventoryRows * 18 + 17);
+ this.drawTexturedModalRect(k, l + container.inventoryRows * 18 + 17, 0, 126, this.xSize, 96);
+ }
+}
diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable$1.class b/src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable$1.class Binary files differnew file mode 100644 index 0000000..18ad90d --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable$1.class diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable.class b/src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable.class Binary files differnew file mode 100644 index 0000000..7f289ed --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable.class diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable.java b/src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable.java new file mode 100644 index 0000000..ec5ef32 --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable.java @@ -0,0 +1,175 @@ +package jp.plusplus.fbs.pottery.usable.container;
+
+import jp.plusplus.fbs.api.IPottery;
+import jp.plusplus.fbs.pottery.ItemBlockPottery;
+import jp.plusplus.fbs.pottery.PotteryRegistry;
+import jp.plusplus.fbs.pottery.usable.PotteryBase;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.item.ItemBlock;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.nbt.NBTTagList;
+
+/**
+ * Created by plusplus_F on 2016/03/30.
+ * インベントリ持ち魔法の壺のインベントリ
+ */
+public class InventoryPotteryUsable implements IInventory{
+ public EntityPlayer player;
+ public ItemStack potteryStack;
+ public int potteryStackIndex;
+ public PotteryBase potteryEffect;
+ public IPottery pottery;
+
+ protected ItemStack[] itemStacks;
+ protected int inventorySize;
+
+ public InventoryPotteryUsable(EntityPlayer player){
+ this.player=player;
+ this.potteryStack=player.getCurrentEquippedItem();
+ this.potteryStackIndex=player.inventory.currentItem;
+ this.potteryEffect= PotteryRegistry.getPotteryEffect(ItemBlockPottery.getId(potteryStack));
+ this.pottery=(IPottery)((ItemBlock)potteryStack.getItem()).field_150939_a;
+
+ switch (pottery.getSize(potteryStack.getTagCompound())){
+ case MEDIUM: inventorySize=9*2; break;
+ case LARGE: inventorySize=9*3; break;
+ default: inventorySize=9*1; break;
+ }
+ itemStacks=new ItemStack[inventorySize];
+ }
+
+ @Override
+ public int getSizeInventory() {
+ return inventorySize;
+ }
+
+ @Override
+ public ItemStack getStackInSlot(int p_70301_1_) {
+ return itemStacks[p_70301_1_];
+ }
+
+ @Override
+ public ItemStack decrStackSize(int i, int size) {
+ if (this.itemStacks[i] != null) {
+ ItemStack itemstack;
+
+ if (this.itemStacks[i].stackSize <= size) {
+ itemstack = this.itemStacks[i];
+ this.itemStacks[i] = null;
+ this.markDirty();
+ return itemstack;
+ } else {
+ itemstack = this.itemStacks[i].splitStack(size);
+
+ if (this.itemStacks[i].stackSize == 0) {
+ this.itemStacks[i] = null;
+ }
+
+ this.markDirty();
+ return itemstack;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public ItemStack getStackInSlotOnClosing(int i) {
+ if (this.itemStacks[i] != null) {
+ ItemStack itemstack = this.itemStacks[i];
+ this.itemStacks[i] = null;
+ return itemstack;
+ }
+ return null;
+ }
+
+ @Override
+ public void setInventorySlotContents(int i, ItemStack item) {
+ this.itemStacks[i] = item;
+
+ if (item != null && item.stackSize > this.getInventoryStackLimit()) {
+ item.stackSize = this.getInventoryStackLimit();
+ }
+
+ this.markDirty();
+ }
+
+ @Override
+ public String getInventoryName() {
+ return potteryStack.getDisplayName();
+ }
+
+ @Override
+ public boolean hasCustomInventoryName() {
+ return false;
+ }
+
+ @Override
+ public int getInventoryStackLimit() {
+ return 64;
+ }
+
+ @Override
+ public void markDirty() {
+
+ }
+
+ @Override
+ public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {
+ return true;
+ }
+
+ @Override
+ public void openInventory() {
+ if (!potteryStack.hasTagCompound()) {
+ potteryStack.setTagCompound(new NBTTagCompound());
+ potteryStack.getTagCompound().setTag(PotteryBase.ITEM_STACKS, new NBTTagList());
+ }
+ else if(!potteryStack.getTagCompound().hasKey(PotteryBase.ITEM_STACKS)){
+ potteryStack.getTagCompound().setTag(PotteryBase.ITEM_STACKS, new NBTTagList());
+ }
+
+ NBTTagList tags = (NBTTagList) potteryStack.getTagCompound().getTag(PotteryBase.ITEM_STACKS);
+ for (int i = 0; i < tags.tagCount(); i++) {
+ NBTTagCompound tagCompound = tags.getCompoundTagAt(i);
+ int slot = tagCompound.getByte("Slot");
+ if (slot >= 0 && slot < itemStacks.length) {
+ itemStacks[slot] = ItemStack.loadItemStackFromNBT(tagCompound);
+ }
+ }
+
+ //インベントリが開くときの処理
+ for(int i=0;i<inventorySize;i++){
+ itemStacks[i]=potteryEffect.onInventoryOpening(player, potteryStack, i, itemStacks[i]);
+ }
+ }
+
+ @Override
+ public void closeInventory() {
+ //インベントリが閉じるときのの処理
+ for(int i=0;i<inventorySize;i++){
+ itemStacks[i]=potteryEffect.onInventoryClosing(player, potteryStack, i, itemStacks[i]);
+ }
+
+ NBTTagList tagList = new NBTTagList();
+ for (int i = 0; i < itemStacks.length; i++) {
+ if (itemStacks[i] != null) {
+ NBTTagCompound compound = new NBTTagCompound();
+ compound.setByte("Slot", (byte) i);
+ itemStacks[i].writeToNBT(compound);
+ tagList.appendTag(compound);
+ }
+ }
+ ItemStack result = new ItemStack(potteryStack.getItem(), 1, potteryStack.getItemDamage());
+ result.setTagCompound((NBTTagCompound)potteryStack.getTagCompound().copy());
+ result.getTagCompound().setTag(PotteryBase.ITEM_STACKS, tagList);
+
+ player.inventory.mainInventory[potteryStackIndex] = result;
+ }
+
+ @Override
+ public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {
+ return potteryEffect.isItemValid(player, potteryStack, p_94041_1_, p_94041_2_);
+ }
+}
diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/container/SlotPotteryUsable.class b/src/main/java/jp/plusplus/fbs/pottery/usable/container/SlotPotteryUsable.class Binary files differnew file mode 100644 index 0000000..afebc3b --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/container/SlotPotteryUsable.class diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/container/SlotPotteryUsable.java b/src/main/java/jp/plusplus/fbs/pottery/usable/container/SlotPotteryUsable.java new file mode 100644 index 0000000..099e65b --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/container/SlotPotteryUsable.java @@ -0,0 +1,27 @@ +package jp.plusplus.fbs.pottery.usable.container;
+
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.inventory.Slot;
+import net.minecraft.item.ItemStack;
+
+/**
+ * Created by plusplus_F on 2016/03/30.
+ */
+public class SlotPotteryUsable extends Slot {
+ protected InventoryPotteryUsable inventoryPottery;
+ public SlotPotteryUsable(InventoryPotteryUsable iInventory, int index, int x, int y) {
+ super(iInventory, index, x, y);
+ inventoryPottery=iInventory;
+ }
+
+ @Override
+ public boolean isItemValid(ItemStack itemStack) {
+ return inventoryPottery.potteryEffect.isItemValid(inventoryPottery.player, inventoryPottery.potteryStack, getSlotIndex(), itemStack);
+ }
+
+ @Override
+ public boolean canTakeStack(EntityPlayer player) {
+ return inventoryPottery.potteryEffect.canTakeStack(player, inventoryPottery.potteryStack, getSlotIndex(), getStack());
+ }
+}
|
