Search in sources :

Example 1 with ItemTubeModule

use of me.desht.pneumaticcraft.common.item.ItemTubeModule 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 2 with ItemTubeModule

use of me.desht.pneumaticcraft.common.item.ItemTubeModule 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)2 ItemTubeModule (me.desht.pneumaticcraft.common.item.ItemTubeModule)2 PacketPlaySound (me.desht.pneumaticcraft.common.network.PacketPlaySound)1 TileEntityPressureTube (me.desht.pneumaticcraft.common.tileentity.TileEntityPressureTube)1 TileEntity (net.minecraft.tileentity.TileEntity)1