Search in sources :

Example 1 with TileEntityPressureTube

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;
}
Also used : TubeModule(me.desht.pneumaticcraft.common.block.tubes.TubeModule) ItemTubeModule(me.desht.pneumaticcraft.common.item.ItemTubeModule) TileEntityPressureTube(me.desht.pneumaticcraft.common.tileentity.TileEntityPressureTube) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 2 with TileEntityPressureTube

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) PacketPlaySound(me.desht.pneumaticcraft.common.network.PacketPlaySound) TubeModule(me.desht.pneumaticcraft.common.block.tubes.TubeModule) ItemTubeModule(me.desht.pneumaticcraft.common.item.ItemTubeModule) TileEntityPressureTube(me.desht.pneumaticcraft.common.tileentity.TileEntityPressureTube) ItemTubeModule(me.desht.pneumaticcraft.common.item.ItemTubeModule)

Example 3 with TileEntityPressureTube

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;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) RayTraceResult(net.minecraft.util.math.RayTraceResult) TileEntityPressureTube(me.desht.pneumaticcraft.common.tileentity.TileEntityPressureTube) Vec3d(net.minecraft.util.math.Vec3d)

Example 4 with TileEntityPressureTube

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]);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityPressureTube(me.desht.pneumaticcraft.common.tileentity.TileEntityPressureTube)

Example 5 with TileEntityPressureTube

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityPressureTube(me.desht.pneumaticcraft.common.tileentity.TileEntityPressureTube)

Aggregations

TileEntityPressureTube (me.desht.pneumaticcraft.common.tileentity.TileEntityPressureTube)9 TileEntity (net.minecraft.tileentity.TileEntity)5 TubeModule (me.desht.pneumaticcraft.common.block.tubes.TubeModule)4 ItemTubeModule (me.desht.pneumaticcraft.common.item.ItemTubeModule)4 RayTraceResult (net.minecraft.util.math.RayTraceResult)2 HashSet (java.util.HashSet)1 Stack (java.util.Stack)1 PacketPlaySound (me.desht.pneumaticcraft.common.network.PacketPlaySound)1 AirHandler (me.desht.pneumaticcraft.common.pressure.AirHandler)1 TileEntityCache (me.desht.pneumaticcraft.common.util.TileEntityCache)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityItem (net.minecraft.entity.item.EntityItem)1 ItemStack (net.minecraft.item.ItemStack)1 EnumFacing (net.minecraft.util.EnumFacing)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 Vec3d (net.minecraft.util.math.Vec3d)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1