use of pneumaticCraft.common.tileentity.TileEntityPressureTube in project PneumaticCraft by MineMaarten.
the class BlockPressureTube method tryPlaceModule.
public boolean tryPlaceModule(EntityPlayer player, World world, int x, int y, int z, int par6, boolean simulate) {
if (player.getCurrentEquippedItem() != null) {
if (player.getCurrentEquippedItem().getItem() instanceof ItemTubeModule) {
TileEntityPressureTube pressureTube = ModInteractionUtils.getInstance().getTube(world.getTileEntity(x, y, z));
if (pressureTube.modules[par6] == null && ModInteractionUtils.getInstance().occlusionTest(boundingBoxes[par6], world.getTileEntity(x, y, z))) {
TubeModule module = ModuleRegistrator.getModule(((ItemTubeModule) player.getCurrentEquippedItem().getItem()).moduleName);
if (simulate)
module.markFake();
pressureTube.setModule(module, ForgeDirection.getOrientation(par6));
if (!simulate) {
onNeighborBlockChange(world, x, y, z, this);
world.notifyBlocksOfNeighborChange(x, y, z, this, ForgeDirection.getOrientation(par6).getOpposite().ordinal());
if (!player.capabilities.isCreativeMode)
player.getCurrentEquippedItem().stackSize--;
world.playSoundEffect(x + 0.5, y + 0.5, z + 0.5, Block.soundTypeGlass.getStepResourcePath(), Block.soundTypeGlass.getVolume() * 5.0F, Block.soundTypeGlass.getPitch() * .9F);
}
return true;
}
} else if (player.getCurrentEquippedItem().getItem() == Itemss.advancedPCB && !simulate) {
TubeModule module = BlockPressureTube.getLookedModule(world, x, y, z, player);
if (module != null && !module.isUpgraded() && module.canUpgrade()) {
if (!world.isRemote) {
module.upgrade();
if (!player.capabilities.isCreativeMode)
player.getCurrentEquippedItem().stackSize--;
}
return true;
}
}
}
return false;
}
use of pneumaticCraft.common.tileentity.TileEntityPressureTube in project PneumaticCraft by MineMaarten.
the class BlockPressureTube method collisionRayTrace.
@Override
public MovingObjectPosition collisionRayTrace(World world, int x, int y, int z, Vec3 origin, Vec3 direction) {
MovingObjectPosition bestMOP = null;
AxisAlignedBB bestAABB = null;
setBlockBounds(BBConstants.PRESSURE_PIPE_MIN_POS, BBConstants.PRESSURE_PIPE_MIN_POS, BBConstants.PRESSURE_PIPE_MIN_POS, BBConstants.PRESSURE_PIPE_MAX_POS, BBConstants.PRESSURE_PIPE_MAX_POS, BBConstants.PRESSURE_PIPE_MAX_POS);
MovingObjectPosition mop = super.collisionRayTrace(world, x, y, z, origin, direction);
if (isCloserMOP(origin, bestMOP, mop)) {
bestMOP = mop;
bestAABB = AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
}
TileEntityPressureTube tube = ModInteractionUtils.getInstance().getTube(world.getTileEntity(x, y, z));
for (int i = 0; i < 6; i++) {
if (tube.sidesConnected[i]) {
setBlockBounds(boundingBoxes[i]);
mop = super.collisionRayTrace(world, x, y, z, origin, direction);
if (isCloserMOP(origin, bestMOP, mop)) {
bestMOP = mop;
bestAABB = AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
}
}
}
//unknown indicates we hit the tube.
if (bestMOP != null)
bestMOP.hitInfo = ForgeDirection.UNKNOWN;
TubeModule[] modules = tube.modules;
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if (modules[dir.ordinal()] != null) {
setBlockBounds(modules[dir.ordinal()].boundingBoxes[dir.ordinal()]);
mop = super.collisionRayTrace(world, x, y, z, origin, direction);
if (isCloserMOP(origin, bestMOP, mop)) {
mop.hitInfo = dir;
bestMOP = mop;
bestAABB = AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
}
}
}
if (bestAABB != null)
setBlockBounds(bestAABB);
return bestMOP;
}
use of pneumaticCraft.common.tileentity.TileEntityPressureTube in project PneumaticCraft by MineMaarten.
the class BlockPressureTube method addCollisionBoxesToList.
@Override
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB axisalignedbb, List arraylist, Entity par7Entity) {
setBlockBounds(BBConstants.PRESSURE_PIPE_MIN_POS, BBConstants.PRESSURE_PIPE_MIN_POS, BBConstants.PRESSURE_PIPE_MIN_POS, BBConstants.PRESSURE_PIPE_MAX_POS, BBConstants.PRESSURE_PIPE_MAX_POS, BBConstants.PRESSURE_PIPE_MAX_POS);
super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, arraylist, par7Entity);
TileEntity te = world.getTileEntity(x, y, z);
TileEntityPressureTube tePt = (TileEntityPressureTube) te;
for (int i = 0; i < 6; i++) {
if (tePt.sidesConnected[i]) {
setBlockBounds(boundingBoxes[i]);
super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, arraylist, par7Entity);
} else if (tePt.modules[i] != null) {
setBlockBounds(tePt.modules[i].boundingBoxes[i]);
super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, arraylist, par7Entity);
}
}
setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
use of pneumaticCraft.common.tileentity.TileEntityPressureTube in project PneumaticCraft by MineMaarten.
the class BlockPressureTube method getLookedModule.
public static TubeModule getLookedModule(World world, int x, int y, int z, EntityPlayer player) {
Pair<Vec3, Vec3> vecs = PneumaticCraftUtils.getStartAndEndLookVec(player);
MovingObjectPosition mop = Blockss.pressureTube.collisionRayTrace(world, x, y, z, vecs.getLeft(), vecs.getRight());
if (mop != null && mop.hitInfo instanceof ForgeDirection && (ForgeDirection) mop.hitInfo != ForgeDirection.UNKNOWN) {
TileEntityPressureTube tube = ModInteractionUtils.getInstance().getTube(world.getTileEntity(x, y, z));
return tube.modules[((ForgeDirection) mop.hitInfo).ordinal()];
}
return null;
}
use of pneumaticCraft.common.tileentity.TileEntityPressureTube in project PneumaticCraft by MineMaarten.
the class ModuleNetworkManager method getConnectedModules.
public Set<TubeModule> getConnectedModules(TubeModule module) {
Set<TubeModule> modules = new HashSet<TubeModule>();
Set<TileEntityPressureTube> traversedTubes = new HashSet<TileEntityPressureTube>();
Stack<TileEntityPressureTube> pendingTubes = new Stack<TileEntityPressureTube>();
pendingTubes.push((TileEntityPressureTube) module.getTube());
while (!pendingTubes.isEmpty()) {
TileEntityPressureTube tube = pendingTubes.pop();
for (TubeModule m : tube.modules) {
if (m != null)
modules.add(m);
}
TileEntityCache[] cache = ((TileEntityPneumaticBase) ((IPneumaticMachine) tube).getAirHandler()).getTileCache();
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
if (tube.sidesConnected[d.ordinal()]) {
TileEntityPressureTube newTube = ModInteractionUtils.getInstance().getTube(cache[d.ordinal()].getTileEntity());
if (newTube != null && !traversedTubes.contains(newTube)) {
pendingTubes.add(newTube);
traversedTubes.add(newTube);
}
}
}
}
return modules;
}
Aggregations