summaryrefslogtreecommitdiff
path: root/src/main/java/jp/plusplus/fbs/block/BlockBookshelfDark.java
blob: 8a131b38af513f8570d1994e50ffcb7df21fe85b (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package jp.plusplus.fbs.block;

import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import jp.plusplus.fbs.FBS;
import jp.plusplus.fbs.Registry;
import jp.plusplus.fbs.exprop.FBSEntityProperties;
import jp.plusplus.fbs.item.ItemMonocle;
import jp.plusplus.fbs.particle.EntityGlowFX;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;

import java.util.Random;

/**
 * Createdby pluslus_Fon 2015/06/06.
 */
public class BlockBookshelfDark extends BlockBase {
    IIcon iconSide;

    public BlockBookshelfDark() {
        super(Material.wood);
        setBlockName("bookshelf");
        setBlockTextureName("bookshelf");
        setStepSound(Block.soundTypeWood);
        setCreativeTab(FBS.tabBook);
        setHardness(2.0F);
        setResistance(5.0F);
    }

    @Override
    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) {
        int meta = world.getBlockMetadata(x, y, z);
        if (meta == 0) return false;

        ItemStack monocle=ItemMonocle.findMonocle(player);
        if(monocle==null) return false;

        /*
        ItemStack helm = player.getCurrentArmor(3);
        if (helm == null || !(helm.getItem() instanceof ItemMonocle)) return false;
        */

        if (world.isRemote) return true;

        if(!player.capabilities.isCreativeMode){
            ItemMonocle.damageMonocle(player, monocle);
            /*
            helm.damageItem(1, player);
            if (helm.stackSize <= 0) {
                player.setCurrentItemOrArmor(4, null);
            }
            */
        }

        FBSEntityProperties prop = FBSEntityProperties.get(player);
        if (prop == null) return true;

        ItemStack get = Registry.GetRandomBook(prop.getMagicLevel());
        if (get != null) {
            player.entityDropItem(get, player.getEyeHeight());
            meta--;
            world.setBlockMetadataWithNotify(x, y, z, meta, 3);
            player.inventory.markDirty();
        }
        return true;
    }

    @Override
    public int onBlockPlaced(World world, int x, int y, int z, int side, float p_149660_6_, float p_149660_7_, float p_149660_8_, int meta) {
        //world.setBlockMetadataWithNotify(x, y, z, 3, 3);
        return 0;
    }

    @SideOnly(Side.CLIENT)
    public void registerBlockIcons(IIconRegister p_149651_1_) {
        blockIcon = p_149651_1_.registerIcon(FBS.MODID + ":bookshelfTop");
        iconSide = p_149651_1_.registerIcon(FBS.MODID + ":bookshelfSide");
    }

    @SideOnly(Side.CLIENT)
    public IIcon getIcon(int side, int meta) {
        return (side == 1 || side == 0) ? blockIcon : iconSide;
    }

    @SideOnly(Side.CLIENT)
    public void randomDisplayTick(World world, int x, int y, int z, Random rand) {
        if (world.getBlockMetadata(x, y, z) == 0) return;

        EntityPlayer ep = FBS.proxy.getEntityPlayerInstance();
        if (ep == null) return;

        if(ItemMonocle.findMonocle(ep)==null) return;

        /*
        ItemStack helm = ep.getCurrentArmor(3);
        if (helm == null || !(helm.getItem() instanceof ItemMonocle)) return;
        */

        float f = (float) x + 0.5F;
        float f1 = (float) y + 0.0F + rand.nextFloat() * 6.0F / 16.0F;
        float f2 = (float) z + 0.5F;
        float f3 = 0.6F;
        float f4 = rand.nextFloat() * 0.6F - 0.3F;
        float f5 =rand.nextFloat()*0.75f;
        //float f4=0.6f;

        spawnParticle(world, (double) (f - f3), (double) (f1+f5), (double) (f2 + f4));
        spawnParticle(world, (double) (f + f3), (double) (f1+f5), (double) (f2 + f4));
        spawnParticle(world, (double) (f + f4), (double) (f1+f5), (double) (f2 - f3));
        spawnParticle(world, (double) (f + f4), (double) (f1+f5), (double) (f2 + f3));
    }

    @Override
    public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_){
        return Items.book;
    }
    @Override
    public int quantityDropped(int meta, int fortune, Random random){
        return 3;
    }

    @SideOnly(Side.CLIENT)
    protected void spawnParticle(World world, double x, double y, double z){
        EntityGlowFX e=new EntityGlowFX(world, x,y,z);
        FMLClientHandler.instance().getClient().effectRenderer.addEffect(e);
    }
}