-
Notifications
You must be signed in to change notification settings - Fork 497
/
BlockEngine.java
170 lines (137 loc) · 4.84 KB
/
BlockEngine.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
159
160
161
162
163
164
165
166
167
168
169
170
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.energy;
import java.util.List;
import java.util.Random;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftEnergy;
import buildcraft.api.tools.IToolWrench;
import buildcraft.core.GuiIds;
import buildcraft.core.IItemPipe;
import buildcraft.core.proxy.CoreProxy;
public class BlockEngine extends BlockContainer {
public BlockEngine(int i) {
super(i, Material.iron);
setHardness(0.5F);
setCreativeTab(CreativeTabs.tabRedstone);
setBlockName("engineBlock");
}
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public boolean renderAsNormalBlock() {
return false;
}
@Override
public int getRenderType() {
return BuildCraftCore.blockByEntityModel;
}
@Override
public TileEntity createNewTileEntity(World var1) {
return new TileEngine();
}
@Override
public boolean isBlockSolidOnSide(World world, int x, int y, int z, ForgeDirection side) {
TileEntity tile = world.getBlockTileEntity(x, y, z);
if (tile instanceof TileEngine) {
return ForgeDirection.getOrientation(((TileEngine) tile).orientation).getOpposite() == side;
}
return false;
}
@Override
public void breakBlock(World world, int x, int y, int z, int par5, int par6) {
TileEngine engine = ((TileEngine) world.getBlockTileEntity(x, y, z));
if (engine != null) {
engine.delete();
}
super.breakBlock(world, x, y, z, par5, par6);
}
@Override
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7, float par8, float par9) {
TileEngine tile = (TileEngine) world.getBlockTileEntity(i, j, k);
// Drop through if the player is sneaking
if (entityplayer.isSneaking())
return false;
// Switch orientation if whacked with a wrench.
Item equipped = entityplayer.getCurrentEquippedItem() != null ? entityplayer.getCurrentEquippedItem().getItem() : null;
if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(entityplayer, i, j, k)) {
tile.switchOrientation();
((IToolWrench) equipped).wrenchUsed(entityplayer, i, j, k);
return true;
} else {
// Do not open guis when having a pipe in hand
if (entityplayer.getCurrentEquippedItem() != null)
if (entityplayer.getCurrentEquippedItem().getItem() instanceof IItemPipe)
return false;
if (tile.engine instanceof EngineStone) {
if (!CoreProxy.proxy.isRenderWorld(tile.worldObj)) {
entityplayer.openGui(BuildCraftEnergy.instance, GuiIds.ENGINE_STONE, world, i, j, k);
}
return true;
} else if (tile.engine instanceof EngineIron) {
if (!CoreProxy.proxy.isRenderWorld(tile.worldObj)) {
entityplayer.openGui(BuildCraftEnergy.instance, GuiIds.ENGINE_IRON, world, i, j, k);
}
return true;
}
}
return false;
}
@Override
public void onPostBlockPlaced(World world, int x, int y, int z, int par5) {
TileEngine tile = (TileEngine) world.getBlockTileEntity(x, y, z);
tile.orientation = ForgeDirection.UP.ordinal();
tile.switchOrientation();
}
@Override
public int damageDropped(int i) {
return i;
}
@SuppressWarnings({ "all" })
@Override
public void randomDisplayTick(World world, int i, int j, int k, Random random) {
TileEngine tile = (TileEngine) world.getBlockTileEntity(i, j, k);
if (!tile.isBurning())
return;
float f = (float) i + 0.5F;
float f1 = (float) j + 0.0F + (random.nextFloat() * 6F) / 16F;
float f2 = (float) k + 0.5F;
float f3 = 0.52F;
float f4 = random.nextFloat() * 0.6F - 0.3F;
world.spawnParticle("reddust", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
world.spawnParticle("reddust", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
world.spawnParticle("reddust", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D);
world.spawnParticle("reddust", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void getSubBlocks(int blockid, CreativeTabs par2CreativeTabs, List itemList) {
itemList.add(new ItemStack(this, 1, 0));
itemList.add(new ItemStack(this, 1, 1));
itemList.add(new ItemStack(this, 1, 2));
}
@Override
public void onNeighborBlockChange(World world, int i, int j, int k, int l) {
TileEngine tile = (TileEngine) world.getBlockTileEntity(i, j, k);
if (tile != null) {
tile.checkRedstonePower();
}
}
}