Search in sources :

Example 1 with Environment

use of net.fabricmc.api.Environment in project MCDoom by AzureDoom.

the class EntityPacketOnClient method onPacket.

@Environment(EnvType.CLIENT)
public static void onPacket(PacketContext context, PacketByteBuf byteBuf) {
    EntityType<?> type = Registry.ENTITY_TYPE.get(byteBuf.readVarInt());
    UUID entityUUID = byteBuf.readUuid();
    int entityID = byteBuf.readVarInt();
    double x = byteBuf.readDouble();
    double y = byteBuf.readDouble();
    double z = byteBuf.readDouble();
    float pitch = (byteBuf.readByte() * 360) / 256.0F;
    float yaw = (byteBuf.readByte() * 360) / 256.0F;
    context.getTaskQueue().execute(() -> {
        @SuppressWarnings("resource") ClientWorld world = MinecraftClient.getInstance().world;
        Entity entity = type.create(world);
        if (entity != null) {
            entity.updatePosition(x, y, z);
            entity.updateTrackedPosition(x, y, z);
            entity.setPitch(pitch);
            entity.setYaw(yaw);
            entity.setId(entityID);
            entity.setUuid(entityUUID);
            world.addEntity(entityID, entity);
        }
    });
}
Also used : Entity(net.minecraft.entity.Entity) ClientWorld(net.minecraft.client.world.ClientWorld) UUID(java.util.UUID) Environment(net.fabricmc.api.Environment)

Example 2 with Environment

use of net.fabricmc.api.Environment in project Blockus by Brandcraf06.

the class SpeedBlockItem method appendTooltip.

@Override
@Environment(EnvType.CLIENT)
public void appendTooltip(ItemStack stack, World world, List<Text> tooltip, TooltipContext context) {
    super.appendTooltip(stack, world, tooltip, context);
    this.getBlock().appendTooltip(stack, world, tooltip, context);
    tooltip.add((new TranslatableText(Blockus.MOD_ID + ".blockitem.givespeed")).formatted(Formatting.DARK_PURPLE));
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) Environment(net.fabricmc.api.Environment)

Example 3 with Environment

use of net.fabricmc.api.Environment in project Primeval by devs-immortal.

the class PrimevalFluids method setupFluidRendering.

/*
     * Fluid rendering setup from Spectrum,
     * Made by DaFaqs, credit to him for this
     * method
     */
@Environment(EnvType.CLIENT)
private static void setupFluidRendering(final Fluid still, final Fluid flowing, final Identifier textureFluidId, final int color) {
    final Identifier stillSpriteId = new Identifier(textureFluidId.getNamespace(), "block/" + textureFluidId.getPath());
    final Identifier flowingSpriteId = new Identifier(textureFluidId.getNamespace(), "block/" + textureFluidId.getPath() + "_flow");
    // If they're not already present, add the sprites to the block atlas
    ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE).register((atlasTexture, registry) -> {
        registry.register(stillSpriteId);
        registry.register(flowingSpriteId);
    });
    final Identifier fluidId = Registry.FLUID.getId(still);
    final Identifier listenerId = new Identifier(fluidId.getNamespace(), fluidId.getPath() + "_reload_listener");
    final Sprite[] fluidSprites = { null, null };
    ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() {

        /**
         * Get the sprites from the block atlas when resources are reloaded
         */
        @Override
        public void reload(ResourceManager manager) {
            final Function<Identifier, Sprite> atlas = MinecraftClient.getInstance().getSpriteAtlas(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE);
            fluidSprites[0] = atlas.apply(stillSpriteId);
            fluidSprites[1] = atlas.apply(flowingSpriteId);
        }

        @Override
        public Identifier getFabricId() {
            return listenerId;
        }
    });
    // The FluidRenderer gets the sprites and color from a FluidRenderHandler during rendering
    final FluidRenderHandler renderHandler = new FluidRenderHandler() {

        @Override
        public Sprite[] getFluidSprites(BlockRenderView view, BlockPos pos, FluidState state) {
            return fluidSprites;
        }

        @Override
        public int getFluidColor(BlockRenderView view, BlockPos pos, FluidState state) {
            return color;
        }
    };
    FluidRenderHandlerRegistry.INSTANCE.register(still, renderHandler);
// FluidRenderHandlerRegistry.INSTANCE.register(flowing, renderHandler); // Temp removed because of flowing shenanigans
}
Also used : SimpleSynchronousResourceReloadListener(net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener) Function(java.util.function.Function) Identifier(net.minecraft.util.Identifier) BlockRenderView(net.minecraft.world.BlockRenderView) Sprite(net.minecraft.client.texture.Sprite) BlockPos(net.minecraft.util.math.BlockPos) ResourceManager(net.minecraft.resource.ResourceManager) FluidRenderHandler(net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler) FluidState(net.minecraft.fluid.FluidState) Environment(net.fabricmc.api.Environment)

Example 4 with Environment

use of net.fabricmc.api.Environment in project Primeval by devs-immortal.

the class ClayMoldItem method appendTooltip.

@Environment(EnvType.CLIENT)
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
    NbtCompound nbt = stack.getOrCreateNbt();
    NbtCompound fluidNbt = nbt.getCompound("Fluid");
    int fluidAmount = fluidNbt.getInt("Amount");
    if (fluidAmount > 0) {
        tooltip.add((new TranslatableText("text.primeval.fluid.contains", fluidAmount, new TranslatableText("block." + fluidNbt.getString("fluid").replace(':', '.')))).formatted(Formatting.GRAY));
    }
    tooltip.add((new TranslatableText("⚖ ").append(this.weight.getText()).append(" ⤧ ").append(this.size.getText())).formatted(Formatting.GRAY));
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) NbtCompound(net.minecraft.nbt.NbtCompound) Environment(net.fabricmc.api.Environment)

Example 5 with Environment

use of net.fabricmc.api.Environment in project StationAPI by ModificationStation.

the class MixinSoundHelper method loadModAudio.

@Environment(EnvType.CLIENT)
private static void loadModAudio(SoundMap array, String channel) {
    try {
        for (ModContainer modContainer : FabricLoader.getInstance().getAllMods()) {
            ModMetadata stationMod = modContainer.getMetadata();
            Path basePath = Paths.get("/assets/" + stationMod.getId() + "/stationapi/sounds/" + channel);
            if (MixinSoundHelper.class.getResource(basePath.toString().replace("\\", "/")) != null) {
                RecursiveReader recursiveReader = new RecursiveReader("/assets/" + stationMod.getId() + "/stationapi/sounds/" + channel, (filepath) -> filepath.endsWith(".ogg") || filepath.endsWith(".mp3") || filepath.endsWith(".wav"));
                for (URL audioUrl : recursiveReader.read()) {
                    String audioID = audioUrl.toString().replace("\\", "/").split("/stationapi/sounds/" + channel)[1].replaceFirst("/", "");
                    ((CustomSoundMap) array).putSound(stationMod.getId() + ":" + audioID, audioUrl);
                }
            }
        }
    } catch (IOException | URISyntaxException e) {
        e.printStackTrace();
    }
}
Also used : RecursiveReader(net.modificationstation.stationapi.api.resource.RecursiveReader) ModContainer(net.fabricmc.loader.api.ModContainer) ModMetadata(net.fabricmc.loader.api.metadata.ModMetadata) CustomSoundMap(net.modificationstation.stationapi.api.client.resource.CustomSoundMap) Environment(net.fabricmc.api.Environment)

Aggregations

Environment (net.fabricmc.api.Environment)59 CompoundTag (net.minecraft.nbt.CompoundTag)9 PacketByteBuf (net.minecraft.network.PacketByteBuf)7 TranslatableText (net.minecraft.text.TranslatableText)7 Entity (net.minecraft.entity.Entity)5 PlayerEntity (net.minecraft.entity.player.PlayerEntity)5 Identifier (net.minecraft.util.Identifier)5 Direction (net.minecraft.util.math.Direction)5 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)4 Entity (net.minecraft.world.entity.Entity)4 IEPlayerMoveC2SPacket (com.qouteall.immersive_portals.ducks.IEPlayerMoveC2SPacket)3 EnvType (net.fabricmc.api.EnvType)3 ClientPlayNetworking (net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking)3 PacketSender (net.fabricmc.fabric.api.networking.v1.PacketSender)3 ServerPlayNetworking (net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking)3 BlockState (net.minecraft.block.BlockState)3 MinecraftClient (net.minecraft.client.MinecraftClient)3 ClientWorld (net.minecraft.client.world.ClientWorld)3 NbtCompound (net.minecraft.nbt.NbtCompound)3 BlockPos (net.minecraft.util.math.BlockPos)3