Search in sources :

Example 46 with MinecraftClient

use of net.minecraft.client.MinecraftClient in project isometric-renders by gliscowo.

the class IsometricRenderPresets method setupBlockStateRender.

public static void setupBlockStateRender(IsometricRenderScreen screen, @NotNull BlockState state) {
    final MinecraftClient client = MinecraftClient.getInstance();
    final Identifier blockId = Registry.BLOCK.getId(state.getBlock());
    screen.setup((matrices, vertexConsumerProvider, tickDelta) -> {
        matrices.push();
        matrices.translate(-0.5, 0, -0.5);
        client.getBlockRenderManager().renderBlockAsEntity(state, matrices, vertexConsumerProvider, 15728880, OverlayTexture.DEFAULT_UV);
        double xOffset = client.player.getX() % 1d;
        double zOffset = client.player.getZ() % 1d;
        if (xOffset < 0)
            xOffset += 1;
        if (zOffset < 0)
            zOffset += 1;
        matrices.translate(xOffset, 1.65 + client.player.getY() % 1d, zOffset);
        client.particleManager.renderParticles(matrices, (VertexConsumerProvider.Immediate) vertexConsumerProvider, client.gameRenderer.getLightmapTextureManager(), getParticleCamera(), tickDelta);
        matrices.pop();
    }, blockId.getNamespace() + "/blocks/" + blockId.getPath());
    screen.setTickCallback(() -> {
        if (client.world.random.nextDouble() < 0.150) {
            state.getBlock().randomDisplayTick(state, client.world, client.player.getBlockPos(), client.world.random);
        }
    });
}
Also used : Identifier(net.minecraft.util.Identifier) MinecraftClient(net.minecraft.client.MinecraftClient) VertexConsumerProvider(net.minecraft.client.render.VertexConsumerProvider)

Example 47 with MinecraftClient

use of net.minecraft.client.MinecraftClient in project isometric-renders by gliscowo.

the class IsometricRenderPresets method setupEntityRender.

public static void setupEntityRender(IsometricRenderScreen screen, @NotNull Entity entity) {
    final MinecraftClient client = MinecraftClient.getInstance();
    final Identifier entityId = Registry.ENTITY_TYPE.getId(entity.getType());
    screen.setup((matrixStack, vertexConsumerProvider, delta) -> {
        matrixStack.push();
        matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(180));
        entity.setPos(client.player.getX(), client.player.getY(), client.player.getZ());
        client.getEntityRenderDispatcher().render(entity, 0, 0, 0, 0, delta, matrixStack, vertexConsumerProvider, 15728880);
        matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(-180));
        matrixStack.translate(0, 2, 0);
        client.particleManager.renderParticles(matrixStack, (VertexConsumerProvider.Immediate) vertexConsumerProvider, client.gameRenderer.getLightmapTextureManager(), getParticleCamera(), delta);
        matrixStack.pop();
    }, entityId.getNamespace() + "/entities/" + entityId.getPath());
    screen.setTickCallback(() -> {
        client.world.tickEntity(entity);
    });
    screen.setClosedCallback(() -> {
        entity.updatePosition(0, 0, 0);
    });
}
Also used : Identifier(net.minecraft.util.Identifier) MinecraftClient(net.minecraft.client.MinecraftClient) VertexConsumerProvider(net.minecraft.client.render.VertexConsumerProvider)

Example 48 with MinecraftClient

use of net.minecraft.client.MinecraftClient in project EarthMCEssentials by EarthMC-Stats.

the class NearbyCommand method register.

public static void register() {
    ClientCommandManager.DISPATCHER.register(ClientCommandManager.literal("nearby").executes(c -> {
        MinecraftClient client = MinecraftClient.getInstance();
        if (client.player == null)
            return -1;
        Formatting headingFormatting = Formatting.byName(instance().getConfig().nearby.headingTextColour.name());
        Formatting textFormatting = Formatting.byName(instance().getConfig().nearby.playerTextColour.name());
        MsgUtils.sendPlayer("text_nearby_header", false, headingFormatting, false);
        for (int i = 0; i < instance().getNearbyPlayers().size(); i++) {
            JsonObject currentPlayer = instance().getNearbyPlayers().get(i).getAsJsonObject();
            JsonElement xElement = currentPlayer.get("x");
            JsonElement zElement = currentPlayer.get("z");
            if (xElement == null || zElement == null)
                continue;
            int distance = Math.abs(xElement.getAsInt() - (int) client.player.getX()) + Math.abs(zElement.getAsInt() - (int) client.player.getZ());
            String prefix = "";
            if (instance().getConfig().nearby.showRank) {
                if (!currentPlayer.has("town"))
                    prefix = new TranslatableText("text_nearby_rank_townless").toString();
                else
                    prefix = "(" + currentPlayer.get("rank").getAsString() + ") ";
            }
            MsgUtils.sendPlayer(prefix + currentPlayer.get("name").getAsString() + ": " + distance + "m", false, textFormatting, false);
        }
        return 1;
    }).then(ClientCommandManager.literal("refresh").executes(c -> {
        instance().scheduler().stop();
        instance().scheduler().start();
        MsgUtils.sendPlayer("msg_nearby_refresh", false, Formatting.AQUA, true);
        return 1;
    })).then(ClientCommandManager.literal("clear").executes(c -> {
        instance().setNearbyPlayers(new JsonArray());
        MsgUtils.sendPlayer("msg_nearby_clear", false, Formatting.AQUA, true);
        return 1;
    })));
}
Also used : JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) Formatting(net.minecraft.util.Formatting) TranslatableText(net.minecraft.text.TranslatableText) EarthMCEssentials(net.emc.emce.EarthMCEssentials) MsgUtils(net.emc.emce.utils.MsgUtils) MinecraftClient(net.minecraft.client.MinecraftClient) EarthMCEssentials.instance(net.emc.emce.EarthMCEssentials.instance) ClientCommandManager(net.fabricmc.fabric.api.client.command.v1.ClientCommandManager) TranslatableText(net.minecraft.text.TranslatableText) JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) MinecraftClient(net.minecraft.client.MinecraftClient) Formatting(net.minecraft.util.Formatting) JsonObject(com.google.gson.JsonObject)

Example 49 with MinecraftClient

use of net.minecraft.client.MinecraftClient in project Terracraft by SimplyCmd.

the class MirrorItem method use.

@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity playerEntity, Hand hand) {
    if (// Get server player
    playerEntity instanceof ServerPlayerEntity)
        // Get server player
        player = (ServerPlayerEntity) playerEntity;
    else // Get client player
    if (playerEntity instanceof ClientPlayerEntity)
        clientPlayer = (ClientPlayerEntity) playerEntity;
    if (!tick) {
        final MinecraftClient client = MinecraftClient.getInstance();
        client.particleManager.addEmitter(clientPlayer, ParticleTypes.END_ROD, 30);
        client.gameRenderer.showFloatingItem(this.getDefaultStack());
        player.getWorld().playSound(playerEntity, playerEntity.getBlockPos(), SoundRegistry.ITEM_MAGIC_MIRROR_USE_EVENT, SoundCategory.PLAYERS, 1f, 1f);
        tick = true;
        return TypedActionResult.success(playerEntity.getStackInHand(hand));
    } else {
        return TypedActionResult.fail(playerEntity.getStackInHand(hand));
    }
}
Also used : MinecraftClient(net.minecraft.client.MinecraftClient) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity)

Example 50 with MinecraftClient

use of net.minecraft.client.MinecraftClient in project Hypnotic-Client by Hypnotic-Development.

the class WorldUtils method getForwardBlock.

public static BlockPos getForwardBlock(double length) {
    MinecraftClient mc = MinecraftClient.getInstance();
    final double yaw = Math.toRadians(mc.player.getYaw());
    BlockPos fPos = new BlockPos(mc.player.getX() + (-Math.sin(yaw) * length), mc.player.getY(), mc.player.getZ() + (Math.cos(yaw) * length));
    return fPos;
}
Also used : MinecraftClient(net.minecraft.client.MinecraftClient) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

MinecraftClient (net.minecraft.client.MinecraftClient)84 ItemStack (net.minecraft.item.ItemStack)12 Text (net.minecraft.text.Text)7 Identifier (net.minecraft.util.Identifier)7 Inject (org.spongepowered.asm.mixin.injection.Inject)7 BlockPos (net.minecraft.util.math.BlockPos)6 BlockEntity (net.minecraft.block.entity.BlockEntity)5 TextRenderer (net.minecraft.client.font.TextRenderer)5 ClientPlayNetworkHandler (net.minecraft.client.network.ClientPlayNetworkHandler)5 BlockHitResult (net.minecraft.util.hit.BlockHitResult)5 List (java.util.List)4 BlockState (net.minecraft.block.BlockState)4 MatrixStack (net.minecraft.client.util.math.MatrixStack)4 Entity (net.minecraft.entity.Entity)4 PlayerEntity (net.minecraft.entity.player.PlayerEntity)4 NbtCompound (net.minecraft.nbt.NbtCompound)4 AreaIsometricRenderScreen (com.glisco.isometricrenders.client.gui.AreaIsometricRenderScreen)3 IsometricRenderScreen (com.glisco.isometricrenders.client.gui.IsometricRenderScreen)3 GameRenderer (net.minecraft.client.render.GameRenderer)3 VertexConsumerProvider (net.minecraft.client.render.VertexConsumerProvider)3