use of me.desht.pneumaticcraft.common.tileentity.TileEntityPressureTube in project pnc-repressurized by TeamPneumatic.
the class BlockPressureTube method rotateBlock.
@Override
public boolean rotateBlock(World world, EntityPlayer player, BlockPos pos, EnumFacing side) {
TileEntityPressureTube tube = ModInteractionUtils.getInstance().getTube(getTE(world, pos));
if (player.isSneaking()) {
TubeModule module = getLookedModule(world, pos, player);
if (module != null) {
// detach and drop the module as an item
if (!player.capabilities.isCreativeMode) {
List<ItemStack> drops = module.getDrops();
for (ItemStack drop : drops) {
EntityItem entity = new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
entity.setItem(drop);
world.spawnEntity(entity);
entity.onCollideWithPlayer(player);
}
}
tube.setModule(null, module.getDirection());
neighborChanged(world.getBlockState(pos), world, pos, this, pos.offset(side));
world.notifyNeighborsOfStateChange(pos, this, true);
} else {
// drop the pipe as an item
if (!player.capabilities.isCreativeMode)
dropBlockAsItem(world, pos, world.getBlockState(pos), 0);
world.setBlockToAir(pos);
}
} else {
// close (or reopen) this side of the pipe
Pair<Boolean, EnumFacing> lookData = getLookedTube(world, pos, player);
if (lookData != null) {
boolean isCore = lookData.getLeft();
EnumFacing sideHit = lookData.getRight();
tube.sidesClosed[sideHit.ordinal()] = !tube.sidesClosed[sideHit.ordinal()];
neighborChanged(world.getBlockState(pos), world, pos, this, pos.offset(side));
world.notifyNeighborsOfStateChange(pos, this, true);
}
}
return true;
}
use of me.desht.pneumaticcraft.common.tileentity.TileEntityPressureTube in project pnc-repressurized by TeamPneumatic.
the class BlockPressureTube method tryPlaceModule.
public boolean tryPlaceModule(EntityPlayer player, World world, BlockPos pos, EnumFacing side, boolean simulate) {
if (player.getHeldItemMainhand().getItem() instanceof ItemTubeModule) {
TileEntity te = getTE(world, pos);
TileEntityPressureTube pressureTube = ModInteractionUtils.getInstance().getTube(te);
if (pressureTube.modules[side.ordinal()] == null && !pressureTube.sidesClosed[side.ordinal()] && ModInteractionUtils.getInstance().occlusionTest(boundingBoxes[side.ordinal()], te)) {
TubeModule module = ModuleRegistrator.getModule(((ItemTubeModule) player.getHeldItemMainhand().getItem()).moduleName);
if (simulate)
module.markFake();
pressureTube.setModule(module, side);
if (!simulate) {
neighborChanged(world.getBlockState(pos), world, pos, this, pos.offset(side));
world.notifyNeighborsOfStateChange(pos, this, true);
if (!player.capabilities.isCreativeMode)
player.getHeldItemMainhand().shrink(1);
NetworkHandler.sendToAllAround(new PacketPlaySound(SoundType.GLASS.getStepSound(), SoundCategory.BLOCKS, pos.getX(), pos.getY(), pos.getZ(), SoundType.GLASS.getVolume() * 5.0f, SoundType.GLASS.getPitch() * 0.9f, false), world);
}
return true;
}
} else if (player.getHeldItemMainhand().getItem() == Itemss.ADVANCED_PCB && !simulate) {
TubeModule module = BlockPressureTube.getLookedModule(world, pos, player);
if (module != null && !module.isUpgraded() && module.canUpgrade()) {
if (!world.isRemote) {
module.upgrade();
if (!player.capabilities.isCreativeMode)
player.getHeldItemMainhand().shrink(1);
}
return true;
}
}
return false;
}
use of me.desht.pneumaticcraft.common.tileentity.TileEntityPressureTube in project pnc-repressurized by TeamPneumatic.
the class BlockPressureTube method getLookedModule.
public static TubeModule getLookedModule(World world, BlockPos pos, EntityPlayer player) {
Pair<Vec3d, Vec3d> vecs = PneumaticCraftUtils.getStartAndEndLookVec(player);
IBlockState state = world.getBlockState(pos);
RayTraceResult rayTraceResult = state.collisionRayTrace(world, pos, vecs.getLeft(), vecs.getRight());
TubeHitInfo tubeHitInfo = getHitInfo(rayTraceResult);
if (tubeHitInfo.type == TubeHitInfo.PartType.MODULE) {
TileEntityPressureTube tube = ModInteractionUtils.getInstance().getTube(getTE(world, pos));
return tube.modules[tubeHitInfo.dir.ordinal()];
}
return null;
}
use of me.desht.pneumaticcraft.common.tileentity.TileEntityPressureTube in project pnc-repressurized by TeamPneumatic.
the class BlockPressureTube method addCollisionBoxToList.
@Override
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean isActualState) {
if (getCamoState(worldIn, pos) != null) {
super.addCollisionBoxToList(state, worldIn, pos, entityBox, collidingBoxes, entityIn, isActualState);
return;
}
addCollisionBoxToList(pos, entityBox, collidingBoxes, BASE_BOUNDS);
TileEntity te = getTE(worldIn, pos);
if (te instanceof TileEntityPressureTube) {
TileEntityPressureTube tePt = (TileEntityPressureTube) te;
for (int i = 0; i < 6; i++) {
if (tePt.sidesConnected[i]) {
addCollisionBoxToList(pos, entityBox, collidingBoxes, boundingBoxes[i]);
}
if (tePt.modules[i] != null) {
addCollisionBoxToList(pos, entityBox, collidingBoxes, tePt.modules[i].boundingBoxes[i]);
}
}
}
}
use of me.desht.pneumaticcraft.common.tileentity.TileEntityPressureTube in project pnc-repressurized by TeamPneumatic.
the class BlockPressureTube method getActualState.
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
state = super.getActualState(state, worldIn, pos);
TileEntity te = getTE(worldIn, pos);
if (te instanceof TileEntityPressureTube) {
TileEntityPressureTube tube = (TileEntityPressureTube) te;
for (int i = 0; i < 6; i++) {
ConnectionType conn = tube.sidesClosed[i] ? ConnectionType.CLOSED : tube.sidesConnected[i] ? ConnectionType.CONNECTED : ConnectionType.OPEN;
state = state.withProperty(CONNECTION_PROPERTIES_3[i], conn);
}
// bit of a hack, but pressure tube should appear to connect to underside of gas lift
if (worldIn.getBlockState(pos.up()).getBlock() == Blockss.GAS_LIFT) {
state = state.withProperty(CONNECTION_PROPERTIES_3[EnumFacing.UP.getIndex()], ConnectionType.CONNECTED);
}
}
return state;
}
Aggregations