Search in sources :

Example 11 with Environment

use of net.fabricmc.api.Environment in project GearReborn by loleq2105.

the class TaserItem method appendTooltip.

@Environment(EnvType.CLIENT)
@Override
public void appendTooltip(ItemStack stack, @Nullable World worldIn, List<Text> tooltip, TooltipContext flagIn) {
    Ag4trItemUtils.buildActiveTooltip(stack, tooltip);
    // TranslatableText line1 = new TranslatableText("ag4tr.misc.tasertooltipcapacitors");
    LiteralText line1 = new LiteralText("[");
    // line1.append(" [");
    line1.formatted(Formatting.GRAY);
    if (getCapCharge4ToolTip(stack) == capacitorChargeUnits) {
        line1.append(new LiteralText("■").formatted(Formatting.GREEN));
    } else if (getCapCharge4ToolTip(stack) == 0) {
        line1.append(new LiteralText("■").formatted(Formatting.DARK_GRAY));
    } else {
        line1.append(new LiteralText("■").formatted(Formatting.YELLOW));
    }
    line1.append("]");
    line1.formatted(Formatting.GRAY);
    tooltip.add(line1);
}
Also used : LiteralText(net.minecraft.text.LiteralText) Environment(net.fabricmc.api.Environment)

Example 12 with Environment

use of net.fabricmc.api.Environment in project architectury-api by architectury.

the class NetworkManagerImpl method registerS2CReceiver.

@SuppressWarnings("Convert2Lambda")
@Environment(EnvType.CLIENT)
private static void registerS2CReceiver(ResourceLocation id, List<PacketTransformer> packetTransformers, NetworkReceiver receiver) {
    S2C_RECEIVER.put(id, receiver);
    PacketTransformer transformer = PacketTransformer.concat(packetTransformers);
    ClientPlayNetworking.registerGlobalReceiver(id, new ClientPlayNetworking.PlayChannelHandler() {

        @Override
        public void receive(Minecraft client, ClientPacketListener handler, FriendlyByteBuf buf, PacketSender sender) {
            var context = context(client.player, client, true);
            transformer.inbound(NetworkManager.Side.S2C, id, buf, context, (side, id1, buf1) -> {
                NetworkReceiver networkReceiver = side == NetworkManager.Side.C2S ? C2S_RECEIVER.get(id1) : S2C_RECEIVER.get(id1);
                if (networkReceiver == null) {
                    throw new IllegalArgumentException("Network Receiver not found! " + id1);
                }
                networkReceiver.receive(buf1, context);
            });
        }
    });
    S2C_TRANSFORMERS.put(id, transformer);
}
Also used : FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) ResourceLocation(net.minecraft.resources.ResourceLocation) NetworkReceiver(dev.architectury.networking.NetworkManager.NetworkReceiver) PacketSender(net.fabricmc.fabric.api.networking.v1.PacketSender) ClientPlayNetworking(net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking) Environment(net.fabricmc.api.Environment) HashMap(java.util.HashMap) BlockableEventLoop(net.minecraft.util.thread.BlockableEventLoop) ClientPacketListener(net.minecraft.client.multiplayer.ClientPacketListener) FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) Player(net.minecraft.world.entity.player.Player) ServerPlayer(net.minecraft.server.level.ServerPlayer) NetworkManager(dev.architectury.networking.NetworkManager) List(java.util.List) Entity(net.minecraft.world.entity.Entity) Minecraft(net.minecraft.client.Minecraft) Map(java.util.Map) Env(dev.architectury.utils.Env) ServerPlayNetworking(net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking) PacketSink(dev.architectury.networking.transformers.PacketSink) EnvType(net.fabricmc.api.EnvType) Packet(net.minecraft.network.protocol.Packet) PacketTransformer(dev.architectury.networking.transformers.PacketTransformer) NetworkReceiver(dev.architectury.networking.NetworkManager.NetworkReceiver) PacketTransformer(dev.architectury.networking.transformers.PacketTransformer) ClientPacketListener(net.minecraft.client.multiplayer.ClientPacketListener) PacketSender(net.fabricmc.fabric.api.networking.v1.PacketSender) ClientPlayNetworking(net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking) Minecraft(net.minecraft.client.Minecraft) Environment(net.fabricmc.api.Environment)

Example 13 with Environment

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

the class AmbrosiumTorchWallBlock method randomDisplayTick.

@Environment(EnvType.CLIENT)
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
    int max = random.nextInt(3) + 2;
    for (int i = 0; i <= max; i++) {
        Direction direction = state.get(FACING).getOpposite();
        double e = (double) pos.getX() + 0.5D + (random.nextDouble() - 0.5D) * 0.23D + 0.3D * (double) direction.getOffsetX();
        double f = (double) pos.getY() + 0.6D + (random.nextDouble() - 0.5D) * 0.25D + 0.22D;
        double g = (double) pos.getZ() + 0.5D + (random.nextDouble() - 0.5D) * 0.23D + 0.3D * (double) direction.getOffsetZ();
        world.addParticle(this.particle, e, f, g, 0.0D, -4.0D, 0.0D);
    }
}
Also used : Direction(net.minecraft.util.math.Direction) Environment(net.fabricmc.api.Environment)

Example 14 with Environment

use of net.fabricmc.api.Environment in project LittleMaidModelLoader-Fabric by SistrScarlet.

the class LMSoundPacket method playSoundClient.

@Environment(EnvType.CLIENT)
public static void playSoundClient(int entityId, String soundName) {
    PlayerEntity player = MinecraftClient.getInstance().player;
    if (player == null)
        return;
    Entity entity = player.world.getEntityById(entityId);
    if (entity instanceof SoundPlayable) {
        ((SoundPlayable) entity).play(soundName);
    }
}
Also used : SoundPlayable(net.sistr.littlemaidmodelloader.entity.compound.SoundPlayable) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Environment(net.fabricmc.api.Environment)

Example 15 with Environment

use of net.fabricmc.api.Environment in project LittleMaidModelLoader-Fabric by SistrScarlet.

the class SyncMultiModelPacket method applyMultiModelClient.

// context.getTaskQueue().execute()の中では@Environmentの効力が及ばないため別メソッドに分離
@Environment(EnvType.CLIENT)
public static void applyMultiModelClient(int entityId, boolean isContract, TextureColors color, String textureName, ArmorSets<String> armorTextureName) {
    World world = MinecraftClient.getInstance().world;
    if (world == null)
        return;
    Entity entity = world.getEntityById(entityId);
    if (!(entity instanceof IHasMultiModel))
        return;
    IHasMultiModel multiModel = (IHasMultiModel) entity;
    multiModel.setContract(isContract);
    multiModel.setColor(color);
    LMTextureManager textureManager = LMTextureManager.INSTANCE;
    textureManager.getTexture(textureName).filter(textureHolder -> multiModel.isAllowChangeTexture(entity, textureHolder, Layer.SKIN, Part.HEAD)).ifPresent(textureHolder -> multiModel.setTextureHolder(textureHolder, Layer.SKIN, Part.HEAD));
    for (Part part : Part.values()) {
        String armorName = armorTextureName.getArmor(part).orElseThrow(() -> new IllegalStateException("テクスチャが存在しません。"));
        textureManager.getTexture(armorName).filter(textureHolder -> multiModel.isAllowChangeTexture(entity, textureHolder, Layer.INNER, part)).ifPresent(textureHolder -> multiModel.setTextureHolder(textureHolder, Layer.INNER, part));
    }
}
Also used : IHasMultiModel(net.sistr.littlemaidmodelloader.entity.compound.IHasMultiModel) Entity(net.minecraft.entity.Entity) PacketSender(net.fabricmc.fabric.api.networking.v1.PacketSender) ClientPlayNetworking(net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking) PlayerEntity(net.minecraft.entity.player.PlayerEntity) IHasMultiModel(net.sistr.littlemaidmodelloader.entity.compound.IHasMultiModel) World(net.minecraft.world.World) Layer(net.sistr.littlemaidmodelloader.entity.compound.IHasMultiModel.Layer) LMTextureManager(net.sistr.littlemaidmodelloader.resource.manager.LMTextureManager) Environment(net.fabricmc.api.Environment) PacketByteBuf(net.minecraft.network.PacketByteBuf) PlayerLookup(net.fabricmc.fabric.api.networking.v1.PlayerLookup) Unpooled(io.netty.buffer.Unpooled) MinecraftServer(net.minecraft.server.MinecraftServer) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) LittleMaidModelLoader(net.sistr.littlemaidmodelloader.LittleMaidModelLoader) Part(net.sistr.littlemaidmodelloader.entity.compound.IHasMultiModel.Part) TextureColors(net.sistr.littlemaidmodelloader.resource.util.TextureColors) ServerPlayNetworking(net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking) EnvType(net.fabricmc.api.EnvType) Identifier(net.minecraft.util.Identifier) MinecraftClient(net.minecraft.client.MinecraftClient) ClientPlayNetworkHandler(net.minecraft.client.network.ClientPlayNetworkHandler) ArmorSets(net.sistr.littlemaidmodelloader.resource.util.ArmorSets) ServerPlayNetworkHandler(net.minecraft.server.network.ServerPlayNetworkHandler) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) Part(net.sistr.littlemaidmodelloader.entity.compound.IHasMultiModel.Part) World(net.minecraft.world.World) LMTextureManager(net.sistr.littlemaidmodelloader.resource.manager.LMTextureManager) Environment(net.fabricmc.api.Environment)

Aggregations

Environment (net.fabricmc.api.Environment)190 ResourceLocation (net.minecraft.resources.ResourceLocation)46 PacketByteBuf (net.minecraft.network.PacketByteBuf)19 Entity (net.minecraft.entity.Entity)18 Nullable (org.jetbrains.annotations.Nullable)18 EnvType (net.fabricmc.api.EnvType)17 Identifier (net.minecraft.util.Identifier)17 TranslatableText (net.minecraft.text.TranslatableText)14 CompoundTag (net.minecraft.nbt.CompoundTag)13 MinecraftClient (net.minecraft.client.MinecraftClient)12 PlayerEntity (net.minecraft.entity.player.PlayerEntity)12 BlockPos (net.minecraft.util.math.BlockPos)12 List (java.util.List)11 ClientWorld (net.minecraft.client.world.ClientWorld)11 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)11 Map (java.util.Map)10 PacketSender (net.fabricmc.fabric.api.networking.v1.PacketSender)10 BlockModelRotation (net.minecraft.client.resources.model.BlockModelRotation)10 LivingEntity (net.minecraft.entity.LivingEntity)10 Sprite (net.minecraft.client.texture.Sprite)8