summaryrefslogtreecommitdiff
path: root/src/main/java/jp/plusplus/fbs/pottery/ItemBlockPottery.java
blob: d7ae5fd4b22b313f6537ec107fce45ec22f86377 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package jp.plusplus.fbs.pottery;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import jp.plusplus.fbs.api.IPottery;
import jp.plusplus.fbs.pottery.usable.PotteryBase;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;

/**
 * Created by plusplus_F on 2015/08/26.
 * 陶芸品用
 */
public class ItemBlockPottery extends ItemBlock {
    protected IPottery pottery;

    public ItemBlockPottery(Block p_i45328_1_) {
        super(p_i45328_1_);
        setMaxDamage(0);
        setHasSubtypes(true);
        setMaxStackSize(1);

        pottery=(IPottery)p_i45328_1_;
    }

    public static void setId(ItemStack itemStack, int id){
        if(!itemStack.hasTagCompound()) itemStack.setTagCompound(new NBTTagCompound());
        NBTTagCompound nbt=itemStack.getTagCompound();
        nbt.setInteger(BlockPotteryBase.EFFECT_ID, id);
    }

    public static int getId(ItemStack itemStack){
        if(!itemStack.hasTagCompound()) itemStack.setTagCompound(new NBTTagCompound());
        NBTTagCompound nbt=itemStack.getTagCompound();
        return nbt.getInteger(BlockPotteryBase.EFFECT_ID);
    }

    @Override
    @SideOnly(Side.CLIENT)
    public IIcon getIconFromDamage(int p_77617_1_)
    {
        return this.field_150939_a.getIcon(2, p_77617_1_);
    }

    @Override
    public int getMetadata(int p_77647_1_)
    {
        return p_77647_1_;
    }

    @Override
    public String getItemStackDisplayName(ItemStack itemStack) {
        BlockPotteryBase bpb=(BlockPotteryBase)field_150939_a;
        NBTTagCompound nbt=itemStack.getTagCompound();
        if(nbt==null) return bpb.getLocalizedName();

        if(pottery.hasEffect(nbt) && pottery.getState(nbt)==IPottery.PotteryState.BAKED){
            PotteryBase pb=PotteryRegistry.getPotteryEffect(getId(itemStack));
            return bpb.getLocalizedName(bpb.getNBT(itemStack))+StatCollector.translateToLocal(pb.getUnlocalizedName())+pb.getNameModifier(itemStack);
        }
        return bpb.getLocalizedName(bpb.getNBT(itemStack))+bpb.getLocalizedName();
    }

    @Override
    public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player) {
        NBTTagCompound nbt=item.getTagCompound();

        //魔法の壺の場合
        if(pottery.hasEffect(nbt) && pottery.getState(nbt)==IPottery.PotteryState.BAKED){
            PotteryBase pb=PotteryRegistry.getPotteryEffect(getId(item));
            if (pb.canUse(player, item)) {
                return pb.onUse(player, item);
            }
            return item;
        }

        return super.onItemRightClick(item, world, player);
    }

    @Override
    public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int p_77648_4_, int p_77648_5_, int p_77648_6_, int p_77648_7_, float p_77648_8_, float p_77648_9_, float p_77648_10_) {
        //魔法の壺は置けない
        NBTTagCompound nbt=itemStack.getTagCompound();
        if(pottery.hasEffect(nbt) && pottery.getState(nbt)==IPottery.PotteryState.BAKED){
            return false;
        }
        return super.onItemUse(itemStack, player, world, p_77648_4_, p_77648_5_, p_77648_6_, p_77648_7_, p_77648_8_, p_77648_9_, p_77648_10_);
    }

    @Override
    public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata) {
        //魔法の壺は置けない
        NBTTagCompound nbt=stack.getTagCompound();
        if(pottery.hasEffect(nbt) && pottery.getState(nbt)==IPottery.PotteryState.BAKED){
            return false;
        }
        else{
            boolean flag=super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata);
            if(flag){
                TileEntity entity=world.getTileEntity(x,y,z);
                if(entity instanceof TileEntityPottery){
                    TileEntityPottery te=(TileEntityPottery)entity;
                    te.setData(stack);
                    te.markDirty();
                    //((TileEntityPottery) te).potteryMetadata=metadata;
                }
            }
            return flag;
        }
    }
}