Search in sources :

Example 1 with LaserColor

use of pl.asie.charset.api.laser.LaserColor in project Charset by CharsetMC.

the class ProxyClient method bakeModels.

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void bakeModels(ModelBakeEvent event) {
    if (prismModel != null) {
        for (Orientation o : Orientation.values()) {
            ModelResourceLocation location = new ModelResourceLocation("charset:laser_prism", "orientation=" + o.name().toLowerCase());
            IBakedModel model = prismModel.bake(o.toTransformation(), DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter());
            event.getModelRegistry().putObject(location, model);
        }
    }
    // Patch jars to glow
    for (EnumFacing facing : EnumFacing.VALUES) {
        for (LaserColor color : LaserColor.VALUES) {
            if (color == LaserColor.NONE)
                continue;
            IBlockState state = CharsetLaser.blockJar.getDefaultState().withProperty(CharsetLaser.LASER_COLOR, color).withProperty(Properties.FACING, facing);
            ModelResourceLocation location = new ModelResourceLocation("charset:light_jar", "color=" + color.getName() + ",facing=" + facing.getName());
            IBakedModel model = event.getModelRegistry().getObject(location);
            VertexFormat format = new VertexFormat(DefaultVertexFormats.ITEM);
            format.addElement(DefaultVertexFormats.TEX_2S);
            if (model != null) {
                SimpleMultiLayerBakedModel result = new SimpleMultiLayerBakedModel(model);
                BlockRenderLayer layerPre = MinecraftForgeClient.getRenderLayer();
                for (BlockRenderLayer layer : BlockRenderLayer.values()) {
                    if (CharsetLaser.blockJar.canRenderInLayer(CharsetLaser.blockJar.getDefaultState(), layer)) {
                        ForgeHooksClient.setRenderLayer(layer);
                        for (int i = 0; i <= 6; i++) {
                            EnumFacing facingIn = (i < 6) ? EnumFacing.getFront(i) : null;
                            for (BakedQuad quadIn : model.getQuads(state, facingIn, 0)) {
                                result.addQuad(layer, facingIn, ModelTransformer.transform(quadIn, (quad, element, data) -> {
                                    if (quad.getTintIndex() == 1 && element == DefaultVertexFormats.TEX_2S) {
                                        return new float[] { 15f * 0x20 / 0xFFFF, 0, 0, 0 };
                                    }
                                    return data;
                                }, (bakedQuad -> {
                                    if (bakedQuad.getTintIndex() == 1) {
                                        return format;
                                    } else {
                                        return bakedQuad.getFormat();
                                    }
                                })));
                            }
                        }
                    }
                }
                ForgeHooksClient.setRenderLayer(layerPre);
                event.getModelRegistry().putObject(location, result);
            }
        }
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) SimpleMultiLayerBakedModel(pl.asie.charset.lib.render.model.SimpleMultiLayerBakedModel) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ModelBakeEvent(net.minecraftforge.client.event.ModelBakeEvent) ModelRegistryEvent(net.minecraftforge.client.event.ModelRegistryEvent) Properties(pl.asie.charset.lib.Properties) LaserRenderer(pl.asie.charset.module.optics.laser.system.LaserRenderer) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) MinecraftForgeClient(net.minecraftforge.client.MinecraftForgeClient) LaserTintHandler(pl.asie.charset.module.optics.laser.blocks.LaserTintHandler) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) PixelOperationSprite(pl.asie.charset.lib.render.sprite.PixelOperationSprite) Side(net.minecraftforge.fml.relauncher.Side) CommandCharset(pl.asie.charset.lib.command.CommandCharset) RegistryUtils(pl.asie.charset.lib.utils.RegistryUtils) TextureStitchEvent(net.minecraftforge.client.event.TextureStitchEvent) ColorHandlerEvent(net.minecraftforge.client.event.ColorHandlerEvent) ModelLoader(net.minecraftforge.client.model.ModelLoader) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) ModelTransformer(pl.asie.charset.lib.render.model.ModelTransformer) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) LaserColor(pl.asie.charset.api.laser.LaserColor) EnumFacing(net.minecraft.util.EnumFacing) SubCommandDebugLasersClient(pl.asie.charset.module.optics.laser.system.SubCommandDebugLasersClient) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) IModel(net.minecraftforge.client.model.IModel) RenderUtils(pl.asie.charset.lib.utils.RenderUtils) IBlockState(net.minecraft.block.state.IBlockState) MinecraftForge(net.minecraftforge.common.MinecraftForge) Orientation(pl.asie.charset.lib.utils.Orientation) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) ForgeHooksClient(net.minecraftforge.client.ForgeHooksClient) SimpleMultiLayerBakedModel(pl.asie.charset.lib.render.model.SimpleMultiLayerBakedModel) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) Orientation(pl.asie.charset.lib.utils.Orientation) LaserColor(pl.asie.charset.api.laser.LaserColor) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with LaserColor

use of pl.asie.charset.api.laser.LaserColor in project Charset by CharsetMC.

the class ProjectorRenderer method onRender.

@SubscribeEvent
public void onRender(RenderWorldLastEvent event) {
    Minecraft.getMinecraft().mcProfiler.startSection("projectors");
    GlStateManager.enableBlend();
    GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
    GlStateManager.glBlendEquation(GL14.GL_FUNC_ADD);
    GlStateManager.enableTexture2D();
    GlStateManager.enableAlpha();
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder worldrenderer = tessellator.getBuffer();
    worldrenderer.setTranslation(0, 0, 0);
    Entity cameraEntity = Minecraft.getMinecraft().getRenderViewEntity();
    Vec3d cameraPos = EntityUtils.interpolate(cameraEntity, event.getPartialTicks());
    ICamera camera = new Frustum();
    camera.setPosition(cameraPos.x, cameraPos.y, cameraPos.z);
    GlStateManager.pushMatrix();
    GlStateManager.translate(-cameraPos.x, -cameraPos.y, -cameraPos.z);
    for (TileEntity tileEntity : Minecraft.getMinecraft().world.loadedTileEntityList) {
        if (tileEntity instanceof TileProjector) {
            LaserColor color = LaserColor.NONE;
            Orientation orientation = ((TileProjector) tileEntity).getOrientation();
            if (CharsetProjector.useLasers) {
                for (int d = 0; d < 6; d++) {
                    LaserColor color2 = ((TileProjector) tileEntity).colors[d];
                    if (color2 != null && color2 != LaserColor.NONE) {
                        if (d == orientation.facing.getOpposite().ordinal()) {
                            // not rendering anything - laser in the way
                            color = LaserColor.NONE;
                            break;
                        } else {
                            color = color.union(color2);
                        }
                    }
                }
            } else {
                color = ((TileProjector) tileEntity).redstoneLevel > 0 ? LaserColor.WHITE : LaserColor.NONE;
            }
            if (color != LaserColor.NONE) {
                ItemStack stack = ((TileProjector) tileEntity).getStack();
                IProjectorHandler<ItemStack> handler = CharsetProjector.getHandler(stack);
                if (handler == null) {
                    continue;
                }
                Surface surface = getSurface(tileEntity.getWorld(), tileEntity.getPos(), orientation, 0.5f, handler.getAspectRatio(stack));
                if (surface == null) {
                    continue;
                }
                if (!camera.isBoundingBoxInFrustum(new AxisAlignedBB(surface.cornerStart, surface.cornerEnd))) {
                    continue;
                }
                surface.r = color.red ? 1.0f : 0.0f;
                surface.g = color.green ? 1.0f : 0.0f;
                surface.b = color.blue ? 1.0f : 0.0f;
                surface.a = 0.5f;
                if (!CharsetProjector.useLasers) {
                    surface.a *= ((TileProjector) tileEntity).redstoneLevel / 15.0f;
                }
                EnumDyeColor dyeColor = null;
                BlockPos inFrontPos = tileEntity.getPos().offset(((TileProjector) tileEntity).getOrientation().facing);
                IBlockState state = tileEntity.getWorld().getBlockState(inFrontPos);
                if (state.getBlock() instanceof BlockStainedGlass) {
                    dyeColor = state.getValue(BlockStainedGlass.COLOR);
                }
                if (dyeColor != null) {
                    float[] v = dyeColor.getColorComponentValues();
                    surface.r *= v[0];
                    surface.g *= v[1];
                    surface.b *= v[2];
                }
                surface.restoreGLColor();
                handler.render(stack, (IProjector) tileEntity, surface);
            }
        }
    }
    GlStateManager.popMatrix();
    GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GlStateManager.glBlendEquation(GL14.GL_FUNC_ADD);
    GlStateManager.disableBlend();
    Minecraft.getMinecraft().mcProfiler.endSection();
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) Frustum(net.minecraft.client.renderer.culling.Frustum) Tessellator(net.minecraft.client.renderer.Tessellator) IBlockState(net.minecraft.block.state.IBlockState) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) ICamera(net.minecraft.client.renderer.culling.ICamera) Orientation(pl.asie.charset.lib.utils.Orientation) EnumDyeColor(net.minecraft.item.EnumDyeColor) TileEntity(net.minecraft.tileentity.TileEntity) BlockStainedGlass(net.minecraft.block.BlockStainedGlass) LaserColor(pl.asie.charset.api.laser.LaserColor) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with LaserColor

use of pl.asie.charset.api.laser.LaserColor in project Charset by CharsetMC.

the class TileJar method recalculateOutputColor.

private void recalculateOutputColor() {
    LaserColor newOutputColor = LaserColor.NONE;
    boolean set = false;
    EnumFacing jarFacing = getJarFacing();
    for (EnumFacing facing : EnumFacing.VALUES) {
        if (facing.getAxis() != jarFacing.getAxis()) {
            newOutputColor = newOutputColor.union(colors[facing.ordinal()]);
            if (colors[facing.ordinal()] != LaserColor.NONE) {
                set = true;
            }
        }
    }
    newOutputColor = newOutputColor.difference(colors[jarFacing.getOpposite().ordinal()]);
    if (colors[jarFacing.getOpposite().ordinal()] != LaserColor.NONE) {
        set = true;
    }
    if (set && outputColor != newOutputColor) {
        outputColor = newOutputColor;
        markBlockForUpdate();
        CharsetLaser.laserStorage.markLaserForUpdate(TileJar.this, getJarFacing());
    }
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) LaserColor(pl.asie.charset.api.laser.LaserColor)

Example 4 with LaserColor

use of pl.asie.charset.api.laser.LaserColor in project Charset by CharsetMC.

the class TilePrism method recalcColors.

private void recalcColors() {
    LaserColor[] oldColors = new LaserColor[6];
    for (int i = 0; i < 6; i++) {
        oldColors[i] = colors[i];
        colors[i] = LaserColor.NONE;
    }
    for (int i = 0; i < 6; i++) {
        LaserColor source = sourceColors[i];
        if (source != LaserColor.NONE) {
            EnumFacing face = EnumFacing.getFront(i);
            FaceBehaviour b = getFaceBehaviour(face);
            if (b == FaceBehaviour.PASS) {
                colors[i ^ 1] = colors[i ^ 1].union(source);
            } else {
                // TODO: Optimize
                boolean isRed = (source.ordinal() & 4) != 0;
                boolean isGreen = (source.ordinal() & 2) != 0;
                boolean isBlue = (source.ordinal() & 1) != 0;
                if (isGreen) {
                    colors[i ^ 1] = colors[i ^ 1].union(LaserColor.GREEN);
                }
                if (isRed || isBlue) {
                    for (EnumFacing target : EnumFacing.VALUES) {
                        FaceBehaviour targetB = getFaceBehaviour(target);
                        if (targetB != FaceBehaviour.PASS) {
                            if (isRed && targetB != b) {
                                colors[target.ordinal()] = colors[target.ordinal()].union(LaserColor.RED);
                            }
                            if (isBlue && targetB == b) {
                                colors[target.ordinal()] = colors[target.ordinal()].union(LaserColor.BLUE);
                            }
                        }
                    }
                }
            }
        }
    }
    for (int i = 0; i < 6; i++) {
        if (colors[i] != oldColors[i]) {
            CharsetLaser.laserStorage.markLaserForUpdate(this, EnumFacing.getFront(i));
        }
    }
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) LaserColor(pl.asie.charset.api.laser.LaserColor)

Example 5 with LaserColor

use of pl.asie.charset.api.laser.LaserColor in project Charset by CharsetMC.

the class TileReflector method updateSourceColor.

public void updateSourceColor(int i) {
    IBlockState state = world.getBlockState(pos);
    EnumFacing rotation = state.getValue(BlockReflector.ROTATION);
    if ((rotation.ordinal() & (~1)) != (i & (~1))) {
        boolean isSplitter = state.getValue(BlockReflector.SPLITTER);
        LaserColor colorFiltered = sourceColors[i].intersection(this.color);
        LaserColor colorRemaining = isSplitter ? sourceColors[i] : sourceColors[i].difference(this.color);
        int ri = BlockReflector.getTargetFacing(EnumFacing.getFront(i), rotation).ordinal();
        if (colorFiltered != bouncedColors[ri]) {
            bouncedColors[ri] = colorFiltered;
            updateColor(ri);
        }
        ri = i ^ 1;
        if (colorRemaining != passedColors[ri]) {
            passedColors[ri] = colorRemaining;
            updateColor(ri);
        }
    } else {
        bouncedColors[i ^ 1] = LaserColor.NONE;
        if (passedColors[i ^ 1] != sourceColors[i]) {
            passedColors[i ^ 1] = sourceColors[i];
            updateColor(i ^ 1);
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) LaserColor(pl.asie.charset.api.laser.LaserColor)

Aggregations

LaserColor (pl.asie.charset.api.laser.LaserColor)6 EnumFacing (net.minecraft.util.EnumFacing)4 IBlockState (net.minecraft.block.state.IBlockState)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 Orientation (pl.asie.charset.lib.utils.Orientation)2 BlockStainedGlass (net.minecraft.block.BlockStainedGlass)1 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)1 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)1 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)1 Frustum (net.minecraft.client.renderer.culling.Frustum)1 ICamera (net.minecraft.client.renderer.culling.ICamera)1 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)1 DefaultVertexFormats (net.minecraft.client.renderer.vertex.DefaultVertexFormats)1 VertexFormat (net.minecraft.client.renderer.vertex.VertexFormat)1 Entity (net.minecraft.entity.Entity)1 EnumDyeColor (net.minecraft.item.EnumDyeColor)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1