-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDecoBlockCrate.java
158 lines (131 loc) · 4.47 KB
/
DecoBlockCrate.java
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package net.minecraft.src;
import java.util.List;
public class DecoBlockCrate extends BlockContainer
{
private Icon[] m_IconByMetadataArray;
protected DecoBlockCrate(int id)
{
super(id, Material.wood);
this.setUnlocalizedName("decoBlockCrate");
this.setHardness(1.0F);
this.setStepSound(soundWoodFootstep);
this.setCreativeTab(CreativeTabs.tabDecorations);
DecoAddonManager.register(this, DecoUtilsStrings.WOOD_TAGS, DecoUtilsStrings.WOOD_NAMES, " Crate");
}
public TileEntity createNewTileEntity(World world)
{
return new DecoTileEntityCrate();
}
public int idPicked(World world, int x, int y, int z)
{
return world.getBlockId(x, y, z);
}
/**
* Get the block's damage value (for use with pick block).
*/
public int getDamageValue(World world, int x, int y, int z)
{
return world.getBlockMetadata(x, y, z);
}
/**
* Determines the damage on the item the block drops. Used in cloth and wood.
*/
public int damageDropped(int metadata)
{
return metadata;
}
/**
* Called when the block is placed in the world.
*/
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving entity, ItemStack itemStack)
{
if (!world.isRemote)
{
DecoTileEntityCrate crate = (DecoTileEntityCrate)world.getBlockTileEntity(x, y, z);
if (itemStack.hasTagCompound()) crate.readInventoryFromNBT(itemStack.getTagCompound());
}
}
/**
* Called upon block activation (right click on the block.)
*/
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{
if (!world.isRemote)
{
DecoTileEntityCrate entity = (DecoTileEntityCrate)world.getBlockTileEntity(x, y, z);
if (player instanceof EntityPlayerMP)
{
DecoContainerCrate container = new DecoContainerCrate(player.inventory, entity);
DecoUtilsPacketHandler.ServerOpenCustomInterface((EntityPlayerMP)player, container, DecoModuleDecoration.decoSubModuleCrates.decoContainerCrateID);
}
}
return true;
}
/**
* Called when the player destroys a block with an item that can harvest it. (i, j, k) are the coordinates of the
* block and l is the block's subtype/damage.
*/
public void harvestBlock(World world, EntityPlayer player, int x, int y, int z, int metadata) { }
/**
* Called when the block is attempted to be harvested
*/
public void onBlockHarvested(World world, int x, int y, int z, int metadata, EntityPlayer player)
{
if (!world.isRemote)
{
DecoTileEntityCrate entity = (DecoTileEntityCrate)world.getBlockTileEntity(x, y, z);
if (player instanceof EntityPlayerMP)
{
ItemStack itemStack = new ItemStack(this, 1, metadata);
NBTTagCompound tagCompound = new NBTTagCompound();
entity.writeInventoryToNBT(tagCompound);
itemStack.setTagCompound(tagCompound);
world.spawnEntityInWorld(new EntityItem(world, x, y, z, itemStack));
}
}
}
/**
* Called upon the block being destroyed by an explosion
*/
public void onBlockDestroyedByExplosion(World world, int x, int y, int z, Explosion explosion)
{
if (!world.isRemote)
{
DecoTileEntityCrate entity = (DecoTileEntityCrate)world.getBlockTileEntity(x, y, z);
ItemStack itemStack = new ItemStack(this, 1, world.getBlockMetadata(x, y, z));
NBTTagCompound tagCompound = new NBTTagCompound();
entity.writeToNBT(tagCompound);
if (!tagCompound.hasNoTags()) itemStack.setTagCompound(tagCompound);
world.spawnEntityInWorld(new EntityItem(world, x, y, z, itemStack));
}
}
/**
* When this method is called, your block should register all the icons it needs with the given IconRegister. This
* is the only chance you get to register icons.
*/
public void registerIcons(IconRegister register)
{
this.m_IconByMetadataArray = new Icon[DecoUtilsStrings.WOOD_TAGS.length];
for (int index = 0; index < DecoUtilsStrings.WOOD_TAGS.length; index++)
{
this.m_IconByMetadataArray[index] = register.registerIcon("decoBlockCrate_" + DecoUtilsStrings.WOOD_TAGS[index]);
}
}
/**
* From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
*/
public Icon getIcon(int side, int metadata)
{
return this.m_IconByMetadataArray[metadata];
}
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (int index = 0; index < DecoUtilsStrings.WOOD_TAGS.length; index++)
{
par3List.add(new ItemStack(par1, 1, index));
}
}
}