001/* 002 * Colonel -- a brigadier expansion library 003 * Copyright (C) zml and Colonel contributors 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package ca.stellardrift.colonel.impl; 018 019import fudge.Entrypoint; 020import net.fabricmc.api.EnvType; 021import net.fabricmc.api.ModInitializer; 022import net.fabricmc.fabric.api.client.networking.v1.C2SPlayChannelEvents; 023import net.fabricmc.loader.api.FabricLoader; 024import net.minecraft.util.Identifier; 025 026@Entrypoint(Entrypoint.MAIN) 027public class Colonel implements ModInitializer { 028 private static final String MOD_FAPI_NETWORKING = "fabric-networking-v0"; 029 030 static Identifier id(final String value) { 031 return new Identifier("colonel", value); 032 } 033 034 @Override 035 public void onInitialize() { 036 // sync is optional, so fapi is not required 037 if (FabricLoader.getInstance().isModLoaded(MOD_FAPI_NETWORKING)) { 038 RegisteredArgumentTypesC2SPacket.register(); 039 if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { // we need to send the packet 040 C2SPlayChannelEvents.REGISTER.register((handler, sender, client, channels) -> { 041 if (channels.contains(RegisteredArgumentTypesC2SPacket.ID)) { 042 client.execute(() -> RegisteredArgumentTypesC2SPacket.of(ServerArgumentTypes.getIds()).sendTo(sender)); 043 } 044 }); 045 } 046 } 047 } 048}