-
Notifications
You must be signed in to change notification settings - Fork 497
/
BlockLaser.java
138 lines (120 loc) · 4.5 KB
/
BlockLaser.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
/** 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.silicon;
import java.util.EnumMap;
import java.util.List;
import com.google.common.collect.Maps;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import buildcraft.core.BCCreativeTab;
import buildcraft.core.lib.block.BlockBuildCraft;
import buildcraft.core.lib.client.render.ICustomHighlight;
import buildcraft.core.lib.utils.MatrixUtils;
public class BlockLaser extends BlockBuildCraft implements ICustomHighlight {
private static final EnumMap<EnumFacing, AxisAlignedBB[]> boxesMap = Maps.newEnumMap(EnumFacing.class);
static {
for (EnumFacing face : EnumFacing.values()) {
AxisAlignedBB[] array = new AxisAlignedBB[2];
array[0] = new AxisAlignedBB(0, 0, 0, 1, 0.25, 1);
array[1] = new AxisAlignedBB(5 / 16.0, 4 / 16.0, 5 / 16.0, 11 / 16.0, 13 / 16.0, 11 / 16.0);
array = MatrixUtils.multiplyAll(array, MatrixUtils.rotateTowardsFace(EnumFacing.UP, face));
boxesMap.put(face, array);
}
}
public BlockLaser() {
super(Material.iron, FACING_6_PROP);
setHardness(10F);
setCreativeTab(BCCreativeTab.get("main"));
setDefaultState(getDefaultState().withProperty(FACING_6_PROP, EnumFacing.UP));
}
@Override
public AxisAlignedBB[] getBoxes(IBlockAccess access, BlockPos pos, IBlockState state) {
return boxesMap.get(state.getValue(FACING_6_PROP));
}
@Override
public double getExpansion() {
return 0.0075;
}
@Override
public double getBreathingCoefficent() {
return 0.725;
}
// @Override
// public MovingObjectPosition collisionRayTrace(World wrd, BlockPos pos, Vec3 origin, Vec3 direction) {
// AxisAlignedBB[] aabbs = getBoxes(wrd, pos, wrd.getBlockState(pos));
// MovingObjectPosition closest = null;
// for (AxisAlignedBB aabb : aabbs) {
// MovingObjectPosition mop = aabb.offset(pos.getX(), pos.getY(), pos.getZ()).calculateIntercept(origin, direction);
// if (mop != null) {
// if (closest != null && mop.hitVec.distanceTo(origin) < closest.hitVec.distanceTo(origin)) {
// closest = mop;
// } else {
// closest = mop;
// }
// }
// }
// if (closest != null) {
// closest.hitVec = Utils.convertMiddle(pos);
//
// // closest.blockX = x;
// // closest.blockY = y;
// // closest.blockZ = z;
// }
// return closest;
// }
@Override
@SuppressWarnings("unchecked")
public void addCollisionBoxesToList(World wrd, BlockPos pos, IBlockState state, AxisAlignedBB mask, List list, Entity ent) {
AxisAlignedBB[] aabbs = getBoxes(wrd, pos, state);
for (AxisAlignedBB aabb : aabbs) {
AxisAlignedBB aabbTmp = aabb.offset(pos.getX(), pos.getY(), pos.getZ());
if (mask.intersectsWith(aabbTmp)) {
list.add(aabbTmp);
}
}
}
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public boolean isFullCube() {
return false;
}
@Override
public TileEntity createNewTileEntity(World world, int metadata) {
return new TileLaser();
}
@Override
public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta,
EntityLivingBase placer) {
return super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer);
}
// @Override
// public int onBlockPlaced(World world, BlockPos pos, EnumFacing face, float par6, float par7, float par8, int
// meta) {
// super.onBlockPlaced(world, pos, side, par6, par7, par8, meta);
//
// int retMeta = meta;
//
// if (side <= 6) {
// retMeta = side;
// }
//
// return retMeta;
// }
@Override
public boolean isSideSolid(IBlockAccess world, BlockPos pos, EnumFacing side) {
return false;
}
}