-
Notifications
You must be signed in to change notification settings - Fork 497
/
BlockFrame.java
214 lines (169 loc) · 7.39 KB
/
BlockFrame.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
/**
* Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
* <p/>
* 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 java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
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.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftCore;
import buildcraft.core.CoreConstants;
import buildcraft.core.internal.IFramePipeConnection;
import buildcraft.core.lib.utils.Utils;
public class BlockFrame extends Block implements IFramePipeConnection {
public BlockFrame() {
super(Material.glass);
setHardness(0.5F);
}
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
if (world.isRemote) {
return;
}
removeNeighboringFrames(world, x, y, z);
}
public void removeNeighboringFrames(World world, int x, int y, int z) {
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
Block nBlock = world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ);
if (nBlock == this) {
world.setBlockToAir(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ);
}
}
}
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public boolean renderAsNormalBlock() {
return false;
}
@Override
public Item getItemDropped(int i, Random random, int j) {
return null;
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
return new ArrayList<ItemStack>();
}
@Override
public int getRenderType() {
return BuilderProxy.frameRenderId;
}
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int i, int j, int k) {
float xMin = CoreConstants.PIPE_MIN_POS, xMax = CoreConstants.PIPE_MAX_POS, yMin = CoreConstants.PIPE_MIN_POS, yMax = CoreConstants.PIPE_MAX_POS, zMin = CoreConstants.PIPE_MIN_POS, zMax = CoreConstants.PIPE_MAX_POS;
if (Utils.checkLegacyPipesConnections(world, i, j, k, i - 1, j, k)) {
xMin = 0.0F;
}
if (Utils.checkLegacyPipesConnections(world, i, j, k, i + 1, j, k)) {
xMax = 1.0F;
}
if (Utils.checkLegacyPipesConnections(world, i, j, k, i, j - 1, k)) {
yMin = 0.0F;
}
if (Utils.checkLegacyPipesConnections(world, i, j, k, i, j + 1, k)) {
yMax = 1.0F;
}
if (Utils.checkLegacyPipesConnections(world, i, j, k, i, j, k - 1)) {
zMin = 0.0F;
}
if (Utils.checkLegacyPipesConnections(world, i, j, k, i, j, k + 1)) {
zMax = 1.0F;
}
return AxisAlignedBB.getBoundingBox((double) i + xMin, (double) j + yMin, (double) k + zMin, (double) i + xMax, (double) j + yMax, (double) k + zMax);
}
@Override
@SuppressWarnings({"all"})
// @Override (client only)
public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int i, int j, int k) {
return getCollisionBoundingBoxFromPool(world, i, j, k);
}
@SuppressWarnings("rawtypes")
@Override
public void addCollisionBoxesToList(World world, int i, int j, int k, AxisAlignedBB axisalignedbb, List arraylist, Entity par7Entity) {
setBlockBounds(CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
if (Utils.checkLegacyPipesConnections(world, i, j, k, i - 1, j, k)) {
setBlockBounds(0.0F, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (Utils.checkLegacyPipesConnections(world, i, j, k, i + 1, j, k)) {
setBlockBounds(CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, 1.0F, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (Utils.checkLegacyPipesConnections(world, i, j, k, i, j - 1, k)) {
setBlockBounds(CoreConstants.PIPE_MIN_POS, 0.0F, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (Utils.checkLegacyPipesConnections(world, i, j, k, i, j + 1, k)) {
setBlockBounds(CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, 1.0F, CoreConstants.PIPE_MAX_POS);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (Utils.checkLegacyPipesConnections(world, i, j, k, i, j, k - 1)) {
setBlockBounds(CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, 0.0F, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (Utils.checkLegacyPipesConnections(world, i, j, k, i, j, k + 1)) {
setBlockBounds(CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS, 1.0F);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
@Override
public MovingObjectPosition collisionRayTrace(World world, int i, int j, int k, Vec3 vec3d, Vec3 vec3d1) {
float xMin = CoreConstants.PIPE_MIN_POS, xMax = CoreConstants.PIPE_MAX_POS, yMin = CoreConstants.PIPE_MIN_POS, yMax = CoreConstants.PIPE_MAX_POS, zMin = CoreConstants.PIPE_MIN_POS, zMax = CoreConstants.PIPE_MAX_POS;
if (Utils.checkLegacyPipesConnections(world, i, j, k, i - 1, j, k)) {
xMin = 0.0F;
}
if (Utils.checkLegacyPipesConnections(world, i, j, k, i + 1, j, k)) {
xMax = 1.0F;
}
if (Utils.checkLegacyPipesConnections(world, i, j, k, i, j - 1, k)) {
yMin = 0.0F;
}
if (Utils.checkLegacyPipesConnections(world, i, j, k, i, j + 1, k)) {
yMax = 1.0F;
}
if (Utils.checkLegacyPipesConnections(world, i, j, k, i, j, k - 1)) {
zMin = 0.0F;
}
if (Utils.checkLegacyPipesConnections(world, i, j, k, i, j, k + 1)) {
zMax = 1.0F;
}
setBlockBounds(xMin, yMin, zMin, xMax, yMax, zMax);
MovingObjectPosition r = super.collisionRayTrace(world, i, j, k, vec3d, vec3d1);
setBlockBounds(0, 0, 0, 1, 1, 1);
return r;
}
@Override
public boolean isPipeConnected(IBlockAccess blockAccess, int x1, int y1, int z1, int x2, int y2, int z2) {
return blockAccess.getBlock(x2, y2, z2) == this;
}
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public void getSubBlocks(Item item, CreativeTabs tab, List list) {
list.add(new ItemStack(this));
}
@Override
public void registerBlockIcons(IIconRegister register) {
blockIcon = register.registerIcon("buildcraftbuilders:frameBlock/default");
}
}