Search in sources :

Example 1 with Orientation

use of pl.asie.charset.lib.utils.Orientation 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 Orientation

use of pl.asie.charset.lib.utils.Orientation 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 Orientation

use of pl.asie.charset.lib.utils.Orientation in project Charset by CharsetMC.

the class TileProjectorRenderer method render.

@Override
public void render(TileProjector projector, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
    if (projector == null || projector.getStack().isEmpty()) {
        return;
    }
    ItemStack stack = projector.getStack();
    GlStateManager.pushMatrix();
    GlStateManager.translate(x, y, z);
    Orientation bo = projector.getOrientation();
    EnumFacing face = bo.top;
    if (SpaceUtils.sign(face) == 1) {
        GlStateManager.translate(face.getDirectionVec().getX(), face.getDirectionVec().getY(), face.getDirectionVec().getZ());
    }
    GlStateManager.translate(0.5 * (1 - Math.abs(face.getDirectionVec().getX())), 0.5 * (1 - Math.abs(face.getDirectionVec().getY())), 0.5 * (1 - Math.abs(face.getDirectionVec().getZ())));
    Quaternion quat = Quaternion.fromOrientation(bo);
    quat.glRotate();
    GlStateManager.rotate(90, 0, 1, 0);
    GlStateManager.translate(0.25, 0.25 - 1.0 / 16.0, 31.0 / 128.0);
    GlStateManager.enableAlpha();
    GlStateManager.enableLighting();
    GlStateManager.alphaFunc(GL11.GL_GREATER, 0.0F);
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    handleRenderItem(stack, projector);
    GlStateManager.popMatrix();
    GlStateManager.disableBlend();
}
Also used : Quaternion(pl.asie.charset.lib.utils.Quaternion) EnumFacing(net.minecraft.util.EnumFacing) ItemStack(net.minecraft.item.ItemStack) Orientation(pl.asie.charset.lib.utils.Orientation)

Example 4 with Orientation

use of pl.asie.charset.lib.utils.Orientation in project Charset by CharsetMC.

the class ProjectorHandlerBook method render.

@Override
@SideOnly(Side.CLIENT)
public void render(ItemStack stack, IProjector projector, IProjectorSurface surface) {
    // oh boy! text!
    if (stack.hasTagCompound()) {
        GlStateManager.pushMatrix();
        GlStateManager.translate(((surface.getCornerStart().x + surface.getCornerEnd().x) / 2) + surface.getScreenFacing().getFrontOffsetX() * 0.001f, ((surface.getCornerStart().y + surface.getCornerEnd().y) / 2) + surface.getScreenFacing().getFrontOffsetY() * 0.001f, ((surface.getCornerStart().z + surface.getCornerEnd().z) / 2) + surface.getScreenFacing().getFrontOffsetZ() * 0.001f);
        Orientation orientation = ProjectorHelper.INSTANCE.getOrientation(surface);
        Quaternion.fromOrientation(orientation).glRotate();
        GlStateManager.rotate(270.0f, 0, 0, 1);
        GlStateManager.rotate(270.0f, 0, 1, 0);
        GlStateManager.translate(0, 0, -ProjectorHelper.OFFSET);
        float scaleVal = 2f * surface.getWidth() / 146f;
        GlStateManager.scale(scaleVal, scaleVal, scaleVal);
        FontRenderer renderer = Minecraft.getMinecraft().fontRenderer;
        NBTTagList pages = stack.getTagCompound().getTagList("pages", Constants.NBT.TAG_STRING);
        if (pages.tagCount() > projector.getPage()) {
            String pageCount = I18n.format("book.pageIndicator", projector.getPage() + 1, pages.tagCount());
            renderer.drawString(pageCount, -73 + 129 - renderer.getStringWidth(pageCount), -90 + 15, 0xFF000000);
            String page = ((NBTTagString) pages.get(projector.getPage())).getString();
            ITextComponent fullComponent = ITextComponent.Serializer.jsonToComponent(page);
            if (fullComponent != null) {
                List<ITextComponent> components = GuiUtilRenderComponents.splitText(fullComponent, 116, renderer, true, true);
                for (int i = 0; i < components.size(); i++) {
                    renderer.drawString(components.get(i).getUnformattedText(), -73 + 16, -90 + 30 + i * renderer.FONT_HEIGHT, 0xFF000000);
                }
            }
        }
        GlStateManager.popMatrix();
        surface.restoreGLColor();
    }
    Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation("textures/gui/book.png"));
    ProjectorHelper.INSTANCE.renderTexture(surface, 20, 20 + 146, 1, 1 + 180);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ResourceLocation(net.minecraft.util.ResourceLocation) ITextComponent(net.minecraft.util.text.ITextComponent) NBTTagString(net.minecraft.nbt.NBTTagString) FontRenderer(net.minecraft.client.gui.FontRenderer) NBTTagString(net.minecraft.nbt.NBTTagString) Orientation(pl.asie.charset.lib.utils.Orientation) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 5 with Orientation

use of pl.asie.charset.lib.utils.Orientation in project Charset by CharsetMC.

the class TilePrism method rotateWrench.

@Override
public boolean rotateWrench(EnumFacing axis) {
    Orientation newOrientation;
    if (axis.getAxis() == orientation.facing.getAxis()) {
        newOrientation = Orientation.getOrientation(Orientation.fromDirection(axis).ordinal() & (~3) | (orientation.ordinal() & 3)).getNextRotationOnTop();
    } else if (axis.getAxis() == orientation.top.getAxis()) {
        newOrientation = Orientation.getOrientation(Orientation.fromDirection(axis).ordinal() & (~3) | (orientation.ordinal() & 3));
    } else {
        newOrientation = orientation.getPrevRotationOnFace().getNextRotationOnTop().getNextRotationOnFace();
    }
    changeOrientation(newOrientation, false);
    return true;
}
Also used : Orientation(pl.asie.charset.lib.utils.Orientation)

Aggregations

Orientation (pl.asie.charset.lib.utils.Orientation)11 EnumFacing (net.minecraft.util.EnumFacing)4 ItemStack (net.minecraft.item.ItemStack)3 IBlockState (net.minecraft.block.state.IBlockState)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 LaserColor (pl.asie.charset.api.laser.LaserColor)2 BlockStainedGlass (net.minecraft.block.BlockStainedGlass)1 FontRenderer (net.minecraft.client.gui.FontRenderer)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