Search in sources :

Example 1 with ClientConfiguration

use of com.almuradev.almura.core.client.config.ClientConfiguration in project Almura by AlmuraDev.

the class CacheTileEntityRenderer method render.

void render(final SingleSlotTileEntity te, final double x, final double y, final double z, final IBlockState blockState) {
    final ClientConfiguration configuration = ClientStaticAccess.configAdapter.get();
    EntityLivingBase viewer = (EntityLivingBase) Minecraft.getMinecraft().getRenderViewEntity();
    if (viewer == null) {
        viewer = Minecraft.getMinecraft().player;
    }
    final ISingleSlotItemHandler itemHandler = (ISingleSlotItemHandler) te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
    if (itemHandler == null) {
        return;
    }
    final ItemStack cache = itemHandler.getStackInSlot(0);
    final BlockPos pos = te.getPos();
    if (!(blockState.getBlock() instanceof CacheBlock)) {
        return;
    }
    final CacheBlock block = (CacheBlock) blockState.getBlock();
    GlStateManager.pushMatrix();
    float angle = 0f;
    double translatedX = x;
    double translatedZ = z;
    final EnumFacing facing = blockState.getValue(BlockHorizontal.FACING);
    switch(facing) {
        case SOUTH:
            angle = 0f;
            translatedX += 0.5;
            translatedZ += 1.025;
            break;
        case WEST:
            angle = -90f;
            translatedX -= 0.025;
            translatedZ += 0.5;
            break;
        case NORTH:
            angle = 180f;
            translatedX += 0.5;
            translatedZ -= 0.025;
            break;
        case EAST:
            angle = 90f;
            translatedX += 1.025;
            translatedZ += 0.5;
            break;
    }
    final int brightness = te.hasWorld() ? blockState.getPackedLightmapCoords(te.getWorld(), pos.offset(facing)) : 15 << 20 | 15 << 4;
    // Move the matrix to the front face, in the center
    GlStateManager.translate(translatedX, y + 0.525f, translatedZ);
    GlStateManager.rotate(angle, 0f, 1f, 0f);
    // Set lightmap coordinates to the skylight value of the block in front of the cache item model
    int j = brightness % 65536;
    int k = brightness / 65536;
    OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, j / 1.0F, k / 1.0F);
    GlStateManager.color(1f, 1f, 1f, 1f);
    // Rotate cache item model to fit default Vanilla cache icon look. We do not support rotating the item model
    GlStateManager.rotate(180f, 0.0F, 1f, 0f);
    GlStateManager.scale(0.5F, 0.5F, 0.5F);
    // FIXED is meant for ItemFrame rendering which we are mimicing
    boolean renderItem = true;
    if (configuration.general.itemFrameRenderDistance > 0) {
        if (viewer == null || !te.hasWorld() || te.getDistanceSq(viewer.posX, viewer.posY, viewer.posZ) > (configuration.general.itemFrameRenderDistance * 16)) {
            renderItem = false;
        }
    }
    if (renderItem) {
        this.client.getRenderItem().renderItem(cache, ItemCameraTransforms.TransformType.FIXED);
    }
    // Revert lightmap texture coordinates to world values pre-render tick
    OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, OpenGlHelper.lastBrightnessX, OpenGlHelper.lastBrightnessY);
    GlStateManager.popMatrix();
    GlStateManager.pushMatrix();
    // Translate to face the cache item model is on but at the bottom edge
    GlStateManager.translate(translatedX, y, translatedZ);
    // Rotate on the y-axis by the angle
    GlStateManager.rotate(angle, 0f, 1f, 0f);
    // Scale the matrix by a scale factor (to make writing legible but not too big on block)
    final float scaleFactor = 0.6666667F * 0.016666668F;
    GlStateManager.scale(scaleFactor, -scaleFactor, scaleFactor);
    final FontRenderer fontRenderer = this.client.fontRenderer;
    String displayName;
    String cacheQuantity = ZERO_QUANTITY;
    boolean renderText = true;
    if (configuration.general.signTextRenderDistance > 0) {
        if (viewer == null || !te.hasWorld() || te.getDistanceSq(viewer.posX, viewer.posY, viewer.posZ) > (configuration.general.signTextRenderDistance * 16)) {
            renderText = false;
        }
    }
    if (renderText) {
        boolean empty = cache.isEmpty();
        if (empty) {
            displayName = block.getLocalizedName();
        } else {
            cacheQuantity = CacheFeature.format.format(cache.getCount());
            displayName = cache.getDisplayName();
        }
        final String cacheMaxQuantity = CacheFeature.format.format(itemHandler.getSlotLimit(0));
        // Check if we can fit the displayname on the first line, if not then split it to two lines at most
        if (fontRenderer.getStringWidth(displayName) > MAX_LINE_WIDTH) {
            int firstLineLength = displayName.length();
            while (fontRenderer.getStringWidth(displayName.substring(0, firstLineLength)) > MAX_LINE_WIDTH) {
                firstLineLength--;
            }
            final String firstLine = displayName.substring(0, firstLineLength);
            final String secondLine = displayName.substring(firstLineLength);
            fontRenderer.drawString(firstLine, -fontRenderer.getStringWidth(firstLine) / 2, (int) y - 80, 0);
            fontRenderer.drawString(secondLine, -fontRenderer.getStringWidth(secondLine) / 2, (int) y - 70, 0);
        } else {
            fontRenderer.drawString(displayName, -fontRenderer.getStringWidth(displayName) / 2, (int) y - 80, 0);
        }
        final int lineWidth = fontRenderer.getStringWidth(cacheMaxQuantity) / 2;
        fontRenderer.drawString(cacheQuantity, -fontRenderer.getStringWidth(cacheQuantity) / 2, (int) y - 24, 0);
        Gui.drawRect(-lineWidth, (int) y - 16, lineWidth, (int) y - 15, 0xFF000000);
        fontRenderer.drawString(cacheMaxQuantity, -fontRenderer.getStringWidth(cacheMaxQuantity) / 2, (int) y - 14, 0);
    }
    GlStateManager.popMatrix();
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) ISingleSlotItemHandler(com.almuradev.almura.shared.capability.ISingleSlotItemHandler) EntityLivingBase(net.minecraft.entity.EntityLivingBase) BlockPos(net.minecraft.util.math.BlockPos) CacheBlock(com.almuradev.almura.feature.cache.block.CacheBlock) FontRenderer(net.minecraft.client.gui.FontRenderer) ItemStack(net.minecraft.item.ItemStack) ClientConfiguration(com.almuradev.almura.core.client.config.ClientConfiguration)

Example 2 with ClientConfiguration

use of com.almuradev.almura.core.client.config.ClientConfiguration in project Almura by AlmuraDev.

the class AlmuraSettings method applyPack.

protected static void applyPack(String pack) {
    final GameSettings settings = Minecraft.getMinecraft().gameSettings;
    final ClientConfiguration configuration = configAdapter.get();
    if (!settings.resourcePacks.contains(pack)) {
        settings.resourcePacks.add(pack);
    }
    settings.saveOptions();
    final ResourcePackRepository resourcepackrepository = Minecraft.getMinecraft().getResourcePackRepository();
    final Iterator<String> iterator = settings.resourcePacks.iterator();
    while (iterator.hasNext()) {
        String name = iterator.next();
        for (ResourcePackRepository.Entry resourcepackrepository$entry : ((ResourcePackRepositoryAccessor) resourcepackrepository).accessor$getRepositoryEntriesAll()) {
            if (resourcepackrepository$entry.getResourcePackName().equals(name)) {
                if (resourcepackrepository$entry.getPackFormat() == 3 || settings.incompatibleResourcePacks.contains(resourcepackrepository$entry.getResourcePackName())) {
                    if (!((ResourcePackRepositoryAccessor) resourcepackrepository).accessor$getRepositoryEntries().contains(resourcepackrepository$entry)) {
                        ((ResourcePackRepositoryAccessor) resourcepackrepository).accessor$getRepositoryEntries().add(resourcepackrepository$entry);
                    }
                    break;
                }
                iterator.remove();
            }
        }
    }
}
Also used : ResourcePackRepository(net.minecraft.client.resources.ResourcePackRepository) ResourcePackRepositoryAccessor(com.almuradev.almura.asm.mixin.accessors.client.resources.ResourcePackRepositoryAccessor) GameSettings(net.minecraft.client.settings.GameSettings) ClientConfiguration(com.almuradev.almura.core.client.config.ClientConfiguration)

Example 3 with ClientConfiguration

use of com.almuradev.almura.core.client.config.ClientConfiguration in project Almura by AlmuraDev.

the class AlmuraSettings method optimizeGame.

public static void optimizeGame() {
    final GameSettings settings = Minecraft.getMinecraft().gameSettings;
    final ClientConfiguration configuration = configAdapter.get();
    settings.autoJump = false;
    settings.ambientOcclusion = 1;
    settings.fancyGraphics = false;
    settings.useVbo = true;
    settings.mipmapLevels = 0;
    settings.guiScale = 3;
    settings.limitFramerate = 90;
    settings.enableVsync = false;
    settings.clouds = 0;
    settings.snooperEnabled = false;
    settings.renderDistanceChunks = 10;
    settings.viewBobbing = false;
    if (Loader.isModLoaded("journeymap")) {
        // Hide the x/y/z location because the map default uses top-right on screen.
        configuration.general.displayLocationWidget = false;
    }
    saveAlmuraConfigs();
}
Also used : GameSettings(net.minecraft.client.settings.GameSettings) ClientConfiguration(com.almuradev.almura.core.client.config.ClientConfiguration)

Example 4 with ClientConfiguration

use of com.almuradev.almura.core.client.config.ClientConfiguration in project Almura by AlmuraDev.

the class MixinRenderItemFrame method onDoRender.

@Inject(method = "doRender", at = @At(value = "HEAD"), cancellable = true)
private void onDoRender(EntityItemFrame entity, double x, double y, double z, float entityYaw, float partialTicks, CallbackInfo ci) {
    // 0 means perform Minecraft logic only, we do not interfere
    final ClientConfiguration configuration = ClientStaticAccess.configAdapter.get();
    if (configuration.general.itemFrameRenderDistance == 0) {
        return;
    }
    EntityLivingBase viewer = (EntityLivingBase) Minecraft.getMinecraft().getRenderViewEntity();
    if (viewer == null) {
        viewer = Minecraft.getMinecraft().player;
    }
    if (viewer != null && entity.getDistance(viewer) > configuration.general.itemFrameRenderDistance) {
        ci.cancel();
    }
}
Also used : EntityLivingBase(net.minecraft.entity.EntityLivingBase) ClientConfiguration(com.almuradev.almura.core.client.config.ClientConfiguration) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with ClientConfiguration

use of com.almuradev.almura.core.client.config.ClientConfiguration in project Almura by AlmuraDev.

the class MixinTileEntitySignRenderer method render.

/**
 * @author Grinch - Steven Downer
 * @reason Do not render signposts past a configurable length. Fairly decent client optimization.
 */
@Overwrite
public void render(TileEntitySign te, double x, double y, double z, float partialTicks, int destroyStage, float val) {
    final ClientConfiguration configuration = ClientStaticAccess.configAdapter.get();
    Block block = te.getBlockType();
    GlStateManager.pushMatrix();
    float f = 0.6666667F;
    if (block == Blocks.STANDING_SIGN) {
        GlStateManager.translate((float) x + 0.5F, (float) y + 0.5F, (float) z + 0.5F);
        float f1 = (float) (te.getBlockMetadata() * 360) / 16.0F;
        GlStateManager.rotate(-f1, 0.0F, 1.0F, 0.0F);
        this.model.signStick.showModel = true;
    } else {
        int k = te.getBlockMetadata();
        float f2 = 0.0F;
        if (k == 2) {
            f2 = 180.0F;
        }
        if (k == 4) {
            f2 = 90.0F;
        }
        if (k == 5) {
            f2 = -90.0F;
        }
        GlStateManager.translate((float) x + 0.5F, (float) y + 0.5F, (float) z + 0.5F);
        GlStateManager.rotate(-f2, 0.0F, 1.0F, 0.0F);
        GlStateManager.translate(0.0F, -0.3125F, -0.4375F);
        this.model.signStick.showModel = false;
    }
    if (destroyStage >= 0) {
        this.bindTexture(DESTROY_STAGES[destroyStage]);
        GlStateManager.matrixMode(5890);
        GlStateManager.pushMatrix();
        GlStateManager.scale(4.0F, 2.0F, 1.0F);
        GlStateManager.translate(0.0625F, 0.0625F, 0.0625F);
        GlStateManager.matrixMode(5888);
    } else {
        this.bindTexture(SIGN_TEXTURE);
    }
    GlStateManager.enableRescaleNormal();
    GlStateManager.pushMatrix();
    GlStateManager.scale(0.6666667F, -0.6666667F, -0.6666667F);
    this.model.renderSign();
    GlStateManager.popMatrix();
    FontRenderer fontrenderer = this.getFontRenderer();
    float f3 = 0.010416667F;
    GlStateManager.translate(0.0F, 0.33333334F, 0.046666667F);
    GlStateManager.scale(0.010416667F, -0.010416667F, 0.010416667F);
    GlStateManager.glNormal3f(0.0F, 0.0F, -0.010416667F);
    GlStateManager.depthMask(false);
    int i = 0;
    // Almura start
    boolean renderText = te.signText.length > 0;
    if (renderText) {
        // Greater than 0 means the client has selected a non-Vanilla render distance
        if (configuration.general.signTextRenderDistance > 0) {
            EntityLivingBase viewer = (EntityLivingBase) Minecraft.getMinecraft().getRenderViewEntity();
            if (viewer == null) {
                viewer = Minecraft.getMinecraft().player;
            }
            if (viewer == null || !te.hasWorld() || te.getDistanceSq(viewer.posX, viewer.posY, viewer.posZ) > (configuration.general.signTextRenderDistance * 16)) {
                renderText = false;
            }
        }
    }
    if (renderText && destroyStage < 0) {
        // Almura End
        for (int j = 0; j < te.signText.length; ++j) {
            if (te.signText[j] != null) {
                ITextComponent itextcomponent = te.signText[j];
                List<ITextComponent> list = GuiUtilRenderComponents.splitText(itextcomponent, 90, fontrenderer, false, true);
                String s = list != null && !list.isEmpty() ? ((ITextComponent) list.get(0)).getFormattedText() : "";
                if (j == te.lineBeingEdited) {
                    s = "> " + s + " <";
                    fontrenderer.drawString(s, -fontrenderer.getStringWidth(s) / 2, j * 10 - te.signText.length * 5, 0);
                } else {
                    fontrenderer.drawString(s, -fontrenderer.getStringWidth(s) / 2, j * 10 - te.signText.length * 5, 0);
                }
            }
        }
    }
    GlStateManager.depthMask(true);
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    GlStateManager.popMatrix();
    if (destroyStage >= 0) {
        GlStateManager.matrixMode(5890);
        GlStateManager.popMatrix();
        GlStateManager.matrixMode(5888);
    }
}
Also used : EntityLivingBase(net.minecraft.entity.EntityLivingBase) ITextComponent(net.minecraft.util.text.ITextComponent) Block(net.minecraft.block.Block) FontRenderer(net.minecraft.client.gui.FontRenderer) ClientConfiguration(com.almuradev.almura.core.client.config.ClientConfiguration) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

ClientConfiguration (com.almuradev.almura.core.client.config.ClientConfiguration)9 EntityLivingBase (net.minecraft.entity.EntityLivingBase)4 Subscribe (com.google.common.eventbus.Subscribe)2 FontRenderer (net.minecraft.client.gui.FontRenderer)2 GameSettings (net.minecraft.client.settings.GameSettings)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 ResourcePackRepositoryAccessor (com.almuradev.almura.asm.mixin.accessors.client.resources.ResourcePackRepositoryAccessor)1 CacheBlock (com.almuradev.almura.feature.cache.block.CacheBlock)1 ISingleSlotItemHandler (com.almuradev.almura.shared.capability.ISingleSlotItemHandler)1 Block (net.minecraft.block.Block)1 ResourcePackRepository (net.minecraft.client.resources.ResourcePackRepository)1 ItemStack (net.minecraft.item.ItemStack)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1