-
Notifications
You must be signed in to change notification settings - Fork 497
/
BlockMarker.java
237 lines (204 loc) · 7.07 KB
/
BlockMarker.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/**
* 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.builders;
import java.util.ArrayList;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Icon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import buildcraft.BuildCraftBuilders;
import buildcraft.BuildCraftCore;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.DefaultProps;
import buildcraft.core.utils.Utils;
public class BlockMarker extends BlockContainer {
public BlockMarker(int i) {
super(i, Material.circuits);
setLightValue(0.5F);
setCreativeTab(CreativeTabBuildCraft.tabBuildCraft);
}
@SuppressWarnings({ "all" })
// @Override (client only)
public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int i, int j, int k) {
int meta = world.getBlockMetadata(i, j, k);
double w = 0.15;
double h = 0.65;
switch (meta) {
case 0:
return AxisAlignedBB.getBoundingBox(i + 0.5 - w, j + 1 - h, k + 0.5 - w, i + 0.5 + w, j + 1, k + 0.5 + w);
case 5:
return AxisAlignedBB.getBoundingBox(i + 0.5 - w, j, k + 0.5 - w, i + 0.5 + w, j + h, k + 0.5 + w);
case 3:
return AxisAlignedBB.getBoundingBox(i + 0.5 - w, j + 0.5 - w, k, i + 0.5 + w, j + 0.5 + w, k + h);
case 4:
return AxisAlignedBB.getBoundingBox(i + 0.5 - w, j + 0.5 - w, k + 1 - h, i + 0.5 + w, j + 0.5 + w, k + 1);
case 1:
return AxisAlignedBB.getBoundingBox(i, j + 0.5 - w, k + 0.5 - w, i + h, j + 0.5 + w, k + 0.5 + w);
default:
return AxisAlignedBB.getBoundingBox(i + 1 - h, j + 0.5 - w, k + 0.5 - w, i + 1, j + 0.5 + w, k + 0.5 + w);
}
}
@Override
public int getRenderType() {
return BuildCraftCore.markerModel;
}
public boolean isACube() {
return false;
}
@Override
public TileEntity createNewTileEntity(World var1) {
return new TileMarker();
}
@Override
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7, float par8, float par9) {
((TileMarker) world.getBlockTileEntity(i, j, k)).tryConnection();
return true;
}
@Override
public void breakBlock(World world, int x, int y, int z, int par5, int par6) {
Utils.preDestroyBlock(world, x, y, z);
super.breakBlock(world, x, y, z, par5, par6);
}
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int i, int j, int k) {
return null;
}
@Override
public boolean isOpaqueCube() {
return Block.torchWood.isOpaqueCube();
}
@Override
public boolean renderAsNormalBlock() {
return false;
}
@Override
public void onNeighborBlockChange(World world, int i, int j, int k, int l) {
((TileMarker) world.getBlockTileEntity(i, j, k)).updateSignals();
if (dropTorchIfCantStay(world, i, j, k)) {
int i1 = world.getBlockMetadata(i, j, k);
boolean flag = false;
if (!BuildersProxy.canPlaceTorch(world, i - 1, j, k) && i1 == 1) {
flag = true;
}
if (!BuildersProxy.canPlaceTorch(world, i + 1, j, k) && i1 == 2) {
flag = true;
}
if (!BuildersProxy.canPlaceTorch(world, i, j, k - 1) && i1 == 3) {
flag = true;
}
if (!BuildersProxy.canPlaceTorch(world, i, j, k + 1) && i1 == 4) {
flag = true;
}
if (!BuildersProxy.canPlaceTorch(world, i, j - 1, k) && i1 == 5) {
flag = true;
}
if (!BuildersProxy.canPlaceTorch(world, i, j + 1, k) && i1 == 0) {
flag = true;
}
if (flag) {
dropBlockAsItem(world, i, j, k, BuildCraftBuilders.markerBlock.blockID, 0);
world.setBlock(i, j, k, 0);
}
}
}
@Override
public MovingObjectPosition collisionRayTrace(World world, int i, int j, int k, Vec3 vec3d, Vec3 vec3d1) {
return Block.torchWood.collisionRayTrace(world, i, j, k, vec3d, vec3d1);
}
@Override
public boolean canPlaceBlockAt(World world, int i, int j, int k) {
if (BuildersProxy.canPlaceTorch(world, i - 1, j, k))
return true;
if (BuildersProxy.canPlaceTorch(world, i + 1, j, k))
return true;
if (BuildersProxy.canPlaceTorch(world, i, j, k - 1))
return true;
if (BuildersProxy.canPlaceTorch(world, i, j, k + 1))
return true;
if (BuildersProxy.canPlaceTorch(world, i, j - 1, k))
return true;
return BuildersProxy.canPlaceTorch(world, i, j + 1, k);
}
@Override
public int onBlockPlaced(World world, int x, int y, int z, int side, float par6, float par7, float par8, int meta) {
super.onBlockPlaced(world, x, y, z, side, par6, par7, par8, meta);
if (side == 1 && BuildersProxy.canPlaceTorch(world, x, y - 1, z)) {
meta = 5;
}
if (side == 2 && BuildersProxy.canPlaceTorch(world, x, y, z + 1)) {
meta = 4;
}
if (side == 3 && BuildersProxy.canPlaceTorch(world, x, y, z - 1)) {
meta = 3;
}
if (side == 4 && BuildersProxy.canPlaceTorch(world, x + 1, y, z)) {
meta = 2;
}
if (side == 5 && BuildersProxy.canPlaceTorch(world, x - 1, y, z)) {
meta = 1;
}
if (side == 0 && BuildersProxy.canPlaceTorch(world, x, y + 1, z)) {
meta = 0;
}
return meta;
}
@Override
public void onBlockAdded(World world, int i, int j, int k) {
super.onBlockAdded(world, i, j, k);
if (BuildersProxy.canPlaceTorch(world, i - 1, j, k)) {
world.setBlockMetadataWithNotify(i, j, k, 1,1);
} else if (BuildersProxy.canPlaceTorch(world, i + 1, j, k)) {
world.setBlockMetadataWithNotify(i, j, k, 2,1);
} else if (BuildersProxy.canPlaceTorch(world, i, j, k - 1)) {
world.setBlockMetadataWithNotify(i, j, k, 3,1);
} else if (BuildersProxy.canPlaceTorch(world, i, j, k + 1)) {
world.setBlockMetadataWithNotify(i, j, k, 4,1);
} else if (BuildersProxy.canPlaceTorch(world, i, j - 1, k)) {
world.setBlockMetadataWithNotify(i, j, k, 5,1);
} else if (BuildersProxy.canPlaceTorch(world, i, j + 1, k)) {
world.setBlockMetadataWithNotify(i, j, k, 0,1);
}
dropTorchIfCantStay(world, i, j, k);
}
private boolean dropTorchIfCantStay(World world, int i, int j, int k) {
if (!canPlaceBlockAt(world, i, j, k)) {
dropBlockAsItem(world, i, j, k, BuildCraftBuilders.markerBlock.blockID, 0);
world.setBlock(i, j, k, 0);
return false;
} else
return true;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void addCreativeItems(ArrayList itemList) {
itemList.add(new ItemStack(this));
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister)
{
this.blockIcon = par1IconRegister.registerIcon("buildcraft:blockMarker");
}
@Override
@SideOnly(Side.CLIENT)
public Icon getBlockTexture(IBlockAccess par1iBlockAccess, int par2, int par3, int par4, int par5) {
return this.blockIcon;
}
}