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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
package goodgenerator.blocks.regularBlock;
import goodgenerator.blocks.tileEntity.EssentiaHatch;
import goodgenerator.main.GoodGenerator;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gregtech.api.GregTech_API;
import gregtech.api.util.GT_Utility;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.StatCollector;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.IEssentiaContainerItem;
import java.util.List;
public class TEBlock extends BlockContainer {
@SideOnly(Side.CLIENT)
protected IIcon[] texture;
String[] textureNames;
protected String name;
protected int index;
public TEBlock(String name, String[] texture, CreativeTabs Tab){
super(Material.iron);
this.setHardness(9.0F);
this.setResistance(5.0F);
this.name = name;
this.textureNames = texture;
this.setHarvestLevel("wrench",2);
this.setCreativeTab(GoodGenerator.GG);
GregTech_API.registerMachineBlock(this, -1);
}
public TEBlock(String name, String[] texture, int index){
super(Material.iron);
this.setHardness(9.0F);
this.setResistance(5.0F);
this.name = name;
this.textureNames = texture;
this.setHarvestLevel("wrench",2);
this.index = index;
this.setCreativeTab(GoodGenerator.GG);
GregTech_API.registerMachineBlock(this, -1);
}
public TEBlock(String name, String[] texture, Material material){
super(material);
this.setHardness(9.0F);
this.setResistance(5.0F);
this.name = name;
this.textureNames = texture;
this.setHarvestLevel("wrench",2);
this.setCreativeTab(GoodGenerator.GG);
GregTech_API.registerMachineBlock(this, -1);
}
public int getIndex() {
return this.index;
}
@Override
public int damageDropped(int meta) {
return meta;
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int meta) {
return meta < this.texture.length ? this.texture[meta] : this.texture[0];
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister par1IconRegister) {
this.texture = new IIcon[this.textureNames.length];
for (int i = 0; i < this.textureNames.length; i++) {
this.texture[i] = par1IconRegister.registerIcon(this.textureNames[i]);
}
}
@Override
@SideOnly(Side.CLIENT)
@SuppressWarnings("unchecked")
public void getSubBlocks(Item item, CreativeTabs tab, List list) {
for (int i = 0; i < this.textureNames.length; i++) {
list.add(new ItemStack(item, 1, i));
}
}
@Override
public void onBlockAdded(World aWorld, int aX, int aY, int aZ) {
if (GregTech_API.isMachineBlock(this, aWorld.getBlockMetadata(aX, aY, aZ))) {
GregTech_API.causeMachineUpdate(aWorld, aX, aY, aZ);
}
}
@Override
public void breakBlock(World aWorld, int aX, int aY, int aZ, Block aBlock, int aMetaData) {
if (GregTech_API.isMachineBlock(this, aWorld.getBlockMetadata(aX, aY, aZ))) {
GregTech_API.causeMachineUpdate(aWorld, aX, aY, aZ);
}
aWorld.removeTileEntity(aX, aY, aZ);
}
@Override
public String getUnlocalizedName() {
return this.name;
}
@Override
public boolean canBeReplacedByLeaves(IBlockAccess world, int x, int y, int z) {
return false;
}
@Override
public boolean canEntityDestroy(IBlockAccess world, int x, int y, int z, Entity entity) {
return false;
}
@Override
public boolean canCreatureSpawn(EnumCreatureType type, IBlockAccess world, int x, int y, int z) {
return false;
}
@Override
public TileEntity createTileEntity(World world, int meta) {
if (index == 1)
return new EssentiaHatch();
return null;
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) {
if (world.isRemote) {
return false;
} else {
TileEntity tile = world.getTileEntity(x, y, z);
if (index == 1) {
if (tile instanceof EssentiaHatch) {
ItemStack tItemStack = player.getHeldItem();
if (tItemStack != null) {
Item tItem = tItemStack.getItem();
if (tItem instanceof IEssentiaContainerItem && ((IEssentiaContainerItem) tItem).getAspects(player.getHeldItem()) != null && ((IEssentiaContainerItem) tItem).getAspects(player.getHeldItem()).size() > 0) {
Aspect tLocked = ((IEssentiaContainerItem) tItem).getAspects(player.getHeldItem()).getAspects()[0];
((EssentiaHatch) tile).setLockedAspect(tLocked);
GT_Utility.sendChatToPlayer(player, String.format(StatCollector.translateToLocal("essentiahatch.chat.0"), tLocked.getLocalizedDescription()));
}
}
else {
((EssentiaHatch) tile).setLockedAspect(null);
GT_Utility.sendChatToPlayer(player, StatCollector.translateToLocal("essentiahatch.chat.1"));
}
world.markBlockForUpdate(x, y, z);
return true;
}
else return false;
}
else return false;
}
}
@Override
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
return null;
}
}
|