Search in sources :

Example 6 with TubeModule

use of me.desht.pneumaticcraft.common.block.tubes.TubeModule 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 7 with TubeModule

use of me.desht.pneumaticcraft.common.block.tubes.TubeModule in project pnc-repressurized by TeamPneumatic.

the class BlockPressureTube method collisionRayTrace.

@Override
public RayTraceResult collisionRayTrace(IBlockState state, World world, BlockPos pos, Vec3d origin, Vec3d direction) {
    RayTraceResult bestRTR = null;
    AxisAlignedBB bestAABB = null;
    setBlockBounds(BASE_BOUNDS);
    RayTraceResult rtr = super.collisionRayTrace(state, world, pos, origin, direction);
    if (rtr != null) {
        rtr.hitInfo = TubeHitInfo.CENTER;
        bestRTR = rtr;
        bestAABB = getBoundingBox(state, world, pos);
    }
    TileEntityPressureTube tube = ModInteractionUtils.getInstance().getTube(getTE(world, pos));
    for (int i = 0; i < 6; i++) {
        if (tube.sidesConnected[i] || tube.sidesClosed[i]) {
            setBlockBounds(tube.sidesClosed[i] ? closedBoundingBoxes[i] : boundingBoxes[i]);
            rtr = super.collisionRayTrace(state, world, pos, origin, direction);
            if (isCloserMOP(origin, bestRTR, rtr)) {
                // tube connection arm
                rtr.hitInfo = new TubeHitInfo(EnumFacing.getFront(i), TubeHitInfo.PartType.TUBE);
                bestRTR = rtr;
                bestAABB = getBoundingBox(state, world, pos);
            }
        }
    }
    TubeModule[] modules = tube.modules;
    for (EnumFacing dir : EnumFacing.VALUES) {
        if (modules[dir.ordinal()] != null) {
            setBlockBounds(modules[dir.ordinal()].boundingBoxes[dir.ordinal()]);
            rtr = super.collisionRayTrace(state, world, pos, origin, direction);
            if (isCloserMOP(origin, bestRTR, rtr)) {
                // tube module
                rtr.hitInfo = new TubeHitInfo(dir, TubeHitInfo.PartType.MODULE);
                bestRTR = rtr;
                bestAABB = getBoundingBox(state, world, pos);
            }
        }
    }
    if (bestAABB != null)
        setBlockBounds(bestAABB);
    return bestRTR;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) RayTraceResult(net.minecraft.util.math.RayTraceResult) TubeModule(me.desht.pneumaticcraft.common.block.tubes.TubeModule) ItemTubeModule(me.desht.pneumaticcraft.common.item.ItemTubeModule) TileEntityPressureTube(me.desht.pneumaticcraft.common.tileentity.TileEntityPressureTube)

Example 8 with TubeModule

use of me.desht.pneumaticcraft.common.block.tubes.TubeModule in project pnc-repressurized by TeamPneumatic.

the class ItemTubeModule method addInformation.

@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack par1ItemStack, World par2EntityPlayer, List<String> par3List, ITooltipFlag par4) {
    super.addInformation(par1ItemStack, par2EntityPlayer, par3List, par4);
    TubeModule module = ModuleRegistrator.getModule(moduleName);
    module.addItemDescription(par3List);
    par3List.add(TextFormatting.DARK_GRAY + "In line: " + (module.isInline() ? "Yes" : "No"));
}
Also used : TubeModule(me.desht.pneumaticcraft.common.block.tubes.TubeModule) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 9 with TubeModule

use of me.desht.pneumaticcraft.common.block.tubes.TubeModule in project pnc-repressurized by TeamPneumatic.

the class BlockPressureTube method randomDisplayTick.

@Override
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState state, World par1World, BlockPos pos, Random par5Random) {
    TileEntity te = getTE(par1World, pos);
    if (te instanceof TileEntityPressureTube) {
        TileEntityPressureTube tePt = (TileEntityPressureTube) te;
        int l = 0;
        for (TubeModule module : tePt.modules) {
            if (module != null)
                l = Math.max(l, module.getRedstoneLevel());
        }
        if (l > 0) {
            double d0 = pos.getX() + 0.5D + (par5Random.nextFloat() - 0.5D) * 0.5D;
            double d1 = pos.getY() + 0.5D + (par5Random.nextFloat() - 0.5D) * 0.5D;
            double d2 = pos.getZ() + 0.5D + (par5Random.nextFloat() - 0.5D) * 0.5D;
            float f = l / 15.0F;
            float f1 = f * 0.6F + 0.4F;
            float f2 = f * f * 0.7F - 0.5F;
            float f3 = f * f * 0.6F - 0.7F;
            if (f2 < 0.0F) {
                f2 = 0.0F;
            }
            if (f3 < 0.0F) {
                f3 = 0.0F;
            }
            par1World.spawnParticle(EnumParticleTypes.REDSTONE, d0, d1, d2, f1, f2, f3);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TubeModule(me.desht.pneumaticcraft.common.block.tubes.TubeModule) ItemTubeModule(me.desht.pneumaticcraft.common.item.ItemTubeModule) TileEntityPressureTube(me.desht.pneumaticcraft.common.tileentity.TileEntityPressureTube) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 10 with TubeModule

use of me.desht.pneumaticcraft.common.block.tubes.TubeModule in project pnc-repressurized by TeamPneumatic.

the class RenderPressureTubeModule method render.

@Override
public void render(TileEntityPressureTube tile, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
    if (tile.getCamouflage() != null) {
        return;
    }
    boolean holdingModule = Minecraft.getMinecraft().player.getHeldItemMainhand().getItem() instanceof ItemTubeModule;
    boolean render = false;
    for (int i = 0; i < tile.modules.length; i++) {
        if (tile.modules[i] != null)
            render = true;
    }
    if (!render && !holdingModule)
        return;
    GlStateManager.pushMatrix();
    FMLClientHandler.instance().getClient().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    GlStateManager.enableTexture2D();
    GlStateManager.disableAlpha();
    GlStateManager.color(1, 1, 1);
    GlStateManager.translate((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
    GlStateManager.scale(1.0F, -1F, -1F);
    // "fake" module is for showing a preview of where the module would be placed
    if (holdingModule)
        attachFakeModule(tile);
    for (int i = 0; i < tile.modules.length; i++) {
        TubeModule module = tile.modules[i];
        if (module != null) {
            if (module.isFake()) {
                GlStateManager.enableBlend();
                GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
                GlStateManager.color(1, 1, 1, 0.5f);
            } else if (module.isUpgraded()) {
                GlStateManager.color(0.95f, 1, 0.75f, 1);
            }
            module.getModel().renderModel(0.0625f, module.getDirection(), partialTicks);
            module.doExtraRendering();
            if (module.isFake()) {
                tile.modules[i] = null;
                GlStateManager.disableBlend();
                GL11.glDisable(GL11.GL_BLEND);
            }
            if (module.isFake() || module.isUpgraded()) {
                GlStateManager.color(1, 1, 1, 1);
            }
        }
    }
    GlStateManager.color(1, 1, 1, 1);
    GlStateManager.enableAlpha();
    GlStateManager.popMatrix();
}
Also used : TubeModule(me.desht.pneumaticcraft.common.block.tubes.TubeModule) ItemTubeModule(me.desht.pneumaticcraft.common.item.ItemTubeModule) ItemTubeModule(me.desht.pneumaticcraft.common.item.ItemTubeModule)

Aggregations

TubeModule (me.desht.pneumaticcraft.common.block.tubes.TubeModule)12 ItemTubeModule (me.desht.pneumaticcraft.common.item.ItemTubeModule)5 TileEntityPressureTube (me.desht.pneumaticcraft.common.tileentity.TileEntityPressureTube)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 TileEntity (net.minecraft.tileentity.TileEntity)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 ArrayList (java.util.ArrayList)1 LayoutStyle (mcjty.theoneprobe.apiimpl.styles.LayoutStyle)1 IAirHandler (me.desht.pneumaticcraft.api.tileentity.IAirHandler)1 PacketPlaySound (me.desht.pneumaticcraft.common.network.PacketPlaySound)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 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 Pair (org.apache.commons.lang3.tuple.Pair)1