Search in sources :

Example 6 with Sprite

use of net.minecraft.client.texture.Sprite in project BitsAndChisels by CoolMineman.

the class BitMeshes method transform.

private static void transform(MutableQuadView quad, Direction direction, int minx, int miny, int minz, int maxx, int maxy, int maxz, Vec3f tmp) {
    Sprite sprite = SpriteFinder.get(MinecraftClient.getInstance().getBakedModelManager().getAtlas(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE)).find(quad, 0);
    transform0(minx * ONE_PIXEL, (maxx + 1) * ONE_PIXEL, miny * ONE_PIXEL, (maxy + 1) * ONE_PIXEL, minz * ONE_PIXEL, (maxz + 1) * ONE_PIXEL, quad, tmp);
    int bake_flags = MutableQuadView.BAKE_LOCK_UV;
    if (direction == Direction.UP)
        bake_flags = bake_flags | MutableQuadView.BAKE_FLIP_V;
    quad.spriteBake(0, sprite, bake_flags);
}
Also used : Sprite(net.minecraft.client.texture.Sprite)

Example 7 with Sprite

use of net.minecraft.client.texture.Sprite in project BedrockIfy by juancarloscp52.

the class InGameHudMixin method renderStatusEffectOverlay.

/**
 * Render the status effect overlay with the screen border distance applied.
 */
@Inject(method = "renderStatusEffectOverlay", at = @At("HEAD"), cancellable = true)
public void renderStatusEffectOverlay(MatrixStack matrixStack, CallbackInfo info) {
    Collection<StatusEffectInstance> collection = Objects.requireNonNull(this.client.player).getStatusEffects();
    if (!collection.isEmpty()) {
        RenderSystem.enableBlend();
        int beneficialEffects = 0;
        int harmfulEffects = 0;
        StatusEffectSpriteManager statusEffectSpriteManager = this.client.getStatusEffectSpriteManager();
        List<Runnable> list = Lists.newArrayListWithExpectedSize(collection.size());
        this.client.getTextureManager().bindTexture(HandledScreen.BACKGROUND_TEXTURE);
        for (StatusEffectInstance statusEffectInstance : Ordering.natural().reverse().sortedCopy(collection)) {
            StatusEffect statusEffect = statusEffectInstance.getEffectType();
            if (statusEffectInstance.shouldShowIcon()) {
                int x = this.scaledWidth - screenBorder;
                int y = 1 + screenBorder;
                if (this.client.isDemo()) {
                    y += 15;
                }
                if (statusEffect.isBeneficial()) {
                    ++beneficialEffects;
                    x -= 25 * beneficialEffects;
                } else {
                    ++harmfulEffects;
                    x -= 25 * harmfulEffects;
                    y += 26;
                }
                RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
                float spriteAlpha = 1.0F;
                if (statusEffectInstance.isAmbient()) {
                    this.drawTexture(matrixStack, x, y, 165, 166, 24, 24);
                } else {
                    this.drawTexture(matrixStack, x, y, 141, 166, 24, 24);
                    if (statusEffectInstance.getDuration() <= 200) {
                        int m = 10 - statusEffectInstance.getDuration() / 20;
                        spriteAlpha = MathHelper.clamp((float) statusEffectInstance.getDuration() / 10.0F / 5.0F * 0.5F, 0.0F, 0.5F) + MathHelper.cos((float) statusEffectInstance.getDuration() * 3.1415927F / 5.0F) * MathHelper.clamp((float) m / 10.0F * 0.25F, 0.0F, 0.25F);
                    }
                }
                Sprite sprite = statusEffectSpriteManager.getSprite(statusEffect);
                int finalX = x + 3;
                int finalY = y + 3;
                float finalAlpha = spriteAlpha;
                list.add(() -> {
                    this.client.getTextureManager().bindTexture(sprite.getAtlas().getId());
                    RenderSystem.color4f(1.0F, 1.0F, 1.0F, finalAlpha);
                    drawSprite(matrixStack, finalX, finalY, this.getZOffset(), 18, 18, sprite);
                });
            }
        }
        list.forEach(Runnable::run);
    }
    info.cancel();
}
Also used : StatusEffect(net.minecraft.entity.effect.StatusEffect) Sprite(net.minecraft.client.texture.Sprite) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) StatusEffectSpriteManager(net.minecraft.client.texture.StatusEffectSpriteManager) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 8 with Sprite

use of net.minecraft.client.texture.Sprite in project VisualOverhaul by TeamMidnightDust.

the class FurnaceBlockEntityRenderer method render.

public void render(E blockEntity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {
    if (VOConfig.furnace && blockEntity != null) {
        BlockState blockState = blockEntity.getCachedState();
        int lightAtBlock = WorldRenderer.getLightmapCoordinates(Objects.requireNonNull(blockEntity.getWorld()), blockEntity.getPos().offset(blockState.get(AbstractFurnaceBlock.FACING)));
        ItemStack item1 = blockEntity.getStack(0);
        ItemStack item2 = blockEntity.getStack(1);
        float angle = (blockState.get(AbstractFurnaceBlock.FACING)).asRotation();
        if (!item1.isEmpty()) {
            matrices.push();
            matrices.translate(0.5f, 0.58f, 0.5f);
            if (blockEntity.getCachedState().getBlock().equals(Blocks.SMOKER))
                matrices.translate(0f, -0.06f, 0f);
            if (blockEntity.getCachedState().getBlock().equals(Blocks.BLAST_FURNACE))
                matrices.translate(0f, -0.25f, 0f);
            matrices.scale(1f, 1f, 1f);
            matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(angle * 3 + 180));
            matrices.translate(0.0f, 0.0f, -0.4f);
            matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(90));
            MinecraftClient.getInstance().getItemRenderer().renderItem(item1, ModelTransformation.Mode.GROUND, lightAtBlock, overlay, matrices, vertexConsumers, 0);
            matrices.pop();
        }
        if (!item2.isEmpty() && !item2.isIn(ItemTags.LOGS_THAT_BURN) && !item2.isIn(ItemTags.PLANKS)) {
            matrices.push();
            matrices.translate(0.5f, 0.08f, 0.5f);
            if (blockEntity.getCachedState().getBlock().equals(Blocks.SMOKER))
                matrices.translate(0f, 0.06f, 0f);
            if (blockEntity.getCachedState().getBlock().equals(Blocks.BLAST_FURNACE))
                matrices.translate(0f, 0.24f, 0f);
            matrices.scale(1f, 1f, 1f);
            matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(angle * 3 + 180));
            matrices.translate(0.0f, 0.0f, -0.4f);
            matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(90));
            MinecraftClient.getInstance().getItemRenderer().renderItem(item2, ModelTransformation.Mode.GROUND, lightAtBlock, overlay, matrices, vertexConsumers, 0);
            matrices.pop();
        } else if (!item2.isEmpty()) {
            matrices.push();
            BlockState state = Block.getBlockFromItem(item2.getItem()).getDefaultState();
            Sprite texture = MinecraftClient.getInstance().getBlockRenderManager().getModel(state).getParticleSprite();
            VertexConsumer vertexConsumer = vertexConsumers.getBuffer(RenderLayer.getEntityCutoutNoCull(spriteToTexture(texture)));
            matrices.translate(0.5f, -1.3f, 0.5f);
            if (blockEntity.getCachedState().getBlock().equals(Blocks.SMOKER))
                matrices.translate(0f, 0.06f, 0f);
            if (blockEntity.getCachedState().getBlock().equals(Blocks.BLAST_FURNACE))
                matrices.translate(0f, 0.2f, 0f);
            matrices.scale(1f, 1f, 1f);
            matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(angle * 3 + 180));
            planks.getPart().render(matrices, vertexConsumer, lightAtBlock, overlay);
            matrices.pop();
        }
    }
}
Also used : Sprite(net.minecraft.client.texture.Sprite) VertexConsumer(net.minecraft.client.render.VertexConsumer) ItemStack(net.minecraft.item.ItemStack)

Example 9 with Sprite

use of net.minecraft.client.texture.Sprite in project Potions-HUD-Fabric by Samuel-Martineau.

the class InGameHudMixin method renderStatusEffectOverlay.

/**
 * @author Samuel-Martineau
 * @reason Prevents the default status effects overlay from being rendered
 */
@Overwrite()
public void renderStatusEffectOverlay(MatrixStack matrices) {
    MinecraftClient client = MinecraftClient.getInstance();
    InGameHud inGameHud = client.inGameHud;
    TextRenderer textRenderer = inGameHud.getTextRenderer();
    int spriteSize = 18;
    assert client.player != null;
    Collection<StatusEffectInstance> statusEffectsCollection = client.player.getStatusEffects();
    if (!statusEffectsCollection.isEmpty()) {
        RenderSystem.enableBlend();
        StatusEffectSpriteManager statusEffectSpriteManager = client.getStatusEffectSpriteManager();
        List<Runnable> statusEffectsRunnableList = Lists.newArrayListWithExpectedSize(statusEffectsCollection.size());
        RenderSystem.setShaderTexture(0, HandledScreen.BACKGROUND_TEXTURE);
        Iterator<StatusEffectInstance> statusEffectsIterator = Ordering.natural().reverse().sortedCopy(statusEffectsCollection).iterator();
        int i = 0;
        while (statusEffectsIterator.hasNext()) {
            int x = PotionsHUDMod.CONFIG_MANAGER.X_OFFSET;
            int y = spriteSize * i + PotionsHUDMod.CONFIG_MANAGER.Y_OFFSET;
            StatusEffectInstance statusEffectInstance = statusEffectsIterator.next();
            StatusEffect statusEffect = statusEffectInstance.getEffectType();
            if (statusEffectInstance.shouldShowIcon()) {
                Sprite statusEffectSprite = statusEffectSpriteManager.getSprite(statusEffect);
                statusEffectsRunnableList.add(() -> {
                    RenderSystem.setShaderTexture(0, statusEffectSprite.getAtlas().getId());
                    DrawableHelper.drawSprite(matrices, x, y, inGameHud.getZOffset(), spriteSize, spriteSize, statusEffectSprite);
                    int duration = statusEffectInstance.getDuration() / 20;
                    long mins = TimeUnit.SECONDS.toMinutes(duration);
                    long secs = duration - TimeUnit.MINUTES.toSeconds(mins);
                    String formattedDuration;
                    if (statusEffectInstance.isPermanent())
                        formattedDuration = "∞";
                    else if (mins == 0)
                        formattedDuration = secs + " sec";
                    else
                        formattedDuration = String.format("%d min, %d sec", mins, secs);
                    float textX = x + spriteSize + 3;
                    float textY = y + (spriteSize / 2f - textRenderer.fontHeight / 2.5f);
                    int color;
                    if (duration <= 5)
                        color = 0xFF5555;
                    else if (duration <= 15)
                        color = 0xFFAA00;
                    else if (duration <= 25)
                        color = 0xFFFF55;
                    else
                        color = 0xFFFFFF;
                    textRenderer.draw(matrices, formattedDuration, textX, textY, color);
                });
            }
            i++;
        }
        statusEffectsRunnableList.forEach(Runnable::run);
    }
}
Also used : Sprite(net.minecraft.client.texture.Sprite) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) StatusEffectSpriteManager(net.minecraft.client.texture.StatusEffectSpriteManager) StatusEffect(net.minecraft.entity.effect.StatusEffect) InGameHud(net.minecraft.client.gui.hud.InGameHud) MinecraftClient(net.minecraft.client.MinecraftClient) TextRenderer(net.minecraft.client.font.TextRenderer) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 10 with Sprite

use of net.minecraft.client.texture.Sprite in project Potions-HUD-Fabric by Samuel-Martineau.

the class HUD method render.

private void render() {
    final PlayerEntity player = client.player;
    final InGameHud inGameHud = client.inGameHud;
    final TextRenderer textRenderer = client.textRenderer;
    final MatrixStack matrixStack = new MatrixStack();
    if (player == null)
        return;
    Collection<StatusEffectInstance> statusEffects = player.getStatusEffects();
    final GameOptions gameOptions = ((MinecraftClientMixin) MinecraftClient.getInstance()).getGameOptions();
    if (!statusEffects.isEmpty() && !gameOptions.debugEnabled) {
        RenderSystem.enableBlend();
        StatusEffectSpriteManager statusEffectSpriteManager = client.getStatusEffectSpriteManager();
        List<Runnable> statusEffectsRunnables = Lists.newArrayListWithExpectedSize(statusEffects.size());
        final int spriteSize = 18;
        for (StatusEffectInstance statusEffectInstance : Ordering.natural().reverse().sortedCopy(statusEffects)) {
            StatusEffect statusEffect = statusEffectInstance.getEffectType();
            final int duration = statusEffectInstance.getDuration() / 20;
            final long mins = TimeUnit.SECONDS.toMinutes(duration);
            final long secs = duration - TimeUnit.MINUTES.toSeconds(mins);
            String formattedDuration;
            if (statusEffectInstance.isPermanent())
                formattedDuration = "∞";
            else if (mins == 0)
                formattedDuration = secs + " sec";
            else
                formattedDuration = String.format("%d min, %d sec", mins, secs);
            final int x = 3;
            final int y = spriteSize * statusEffectsRunnables.size() + 3;
            System.out.println("\n   \n---\n   ");
            Sprite sprite = statusEffectSpriteManager.getSprite(statusEffect);
            System.out.println(sprite);
            System.out.println(sprite.getAtlas().getId());
            System.out.println(x);
            System.out.println(y);
            System.out.println(inGameHud.getZOffset());
            statusEffectsRunnables.add(() -> {
                client.getTextureManager().bindTexture(sprite.getAtlas().getId());
                DrawableHelper.drawSprite(matrixStack, x, y, inGameHud.getZOffset(), 18, 18, sprite);
                final float textYOffset = spriteSize / 2f - textRenderer.fontHeight / 2.5f;
                int color;
                if (duration <= 5)
                    color = 0xFF5555;
                else if (duration <= 15)
                    color = 0xFFAA00;
                else if (duration <= 25)
                    color = 0xFFFF55;
                else
                    color = 0xFFFFFF;
                textRenderer.draw(matrixStack, formattedDuration, x + spriteSize + 3, y + textYOffset, color);
            });
        }
        statusEffectsRunnables.forEach(Runnable::run);
    }
}
Also used : MinecraftClientMixin(me.smartineau.mixin.MinecraftClientMixin) Sprite(net.minecraft.client.texture.Sprite) MatrixStack(net.minecraft.client.util.math.MatrixStack) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) StatusEffectSpriteManager(net.minecraft.client.texture.StatusEffectSpriteManager) PlayerEntity(net.minecraft.entity.player.PlayerEntity) StatusEffect(net.minecraft.entity.effect.StatusEffect) InGameHud(net.minecraft.client.gui.hud.InGameHud) GameOptions(net.minecraft.client.option.GameOptions) TextRenderer(net.minecraft.client.font.TextRenderer)

Aggregations

Sprite (net.minecraft.client.texture.Sprite)17 StatusEffectInstance (net.minecraft.entity.effect.StatusEffectInstance)5 Identifier (net.minecraft.util.Identifier)5 Function (java.util.function.Function)4 FluidRenderHandler (net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler)4 StatusEffectSpriteManager (net.minecraft.client.texture.StatusEffectSpriteManager)4 StatusEffect (net.minecraft.entity.effect.StatusEffect)4 FluidState (net.minecraft.fluid.FluidState)4 BlockPos (net.minecraft.util.math.BlockPos)4 SimpleSynchronousResourceReloadListener (net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener)3 ResourceManager (net.minecraft.resource.ResourceManager)3 ModelQuadView (me.jellysquid.mods.sodium.client.model.quad.ModelQuadView)2 ModelQuadOrientation (me.jellysquid.mods.sodium.client.model.quad.properties.ModelQuadOrientation)2 BlockState (net.minecraft.block.BlockState)2 MinecraftClient (net.minecraft.client.MinecraftClient)2 TextRenderer (net.minecraft.client.font.TextRenderer)2 InGameHud (net.minecraft.client.gui.hud.InGameHud)2 Direction (net.minecraft.util.math.Direction)2 BlockRenderView (net.minecraft.world.BlockRenderView)2 Random (java.util.Random)1