Search in sources :

Example 6 with Identifier

use of net.minecraft.util.Identifier in project nbt-crafting by Siphalor.

the class NbtCraftingClient method onInitializeClient.

@Override
public void onInitializeClient() {
    ClientLoginNetworking.registerGlobalReceiver(NbtCrafting.PRESENCE_CHANNEL, (client, handler, buf, listenerAdder) -> {
        return CompletableFuture.completedFuture(new PacketByteBuf(Unpooled.buffer()));
    });
    ClientSidePacketRegistry.INSTANCE.register(NbtCrafting.UPDATE_ANVIL_TEXT_S2C_PACKET_ID, (packetContext, packetByteBuf) -> {
        if (MinecraftClient.getInstance().currentScreen instanceof AnvilScreen) {
            ((AnvilScreenAccessor) MinecraftClient.getInstance().currentScreen).getNameField().setText(packetByteBuf.readString());
        } else
            packetByteBuf.readString();
    });
    ClientPlayNetworking.registerGlobalReceiver(NbtCrafting.UPDATE_ADVANCED_RECIPES_PACKET_ID, (client, handler, buf, responseSender) -> {
        RecipeManager recipeManager = handler.getRecipeManager();
        Map<RecipeType<?>, Map<Identifier, Recipe<?>>> recipeMap = ((RecipeManagerAccessor) recipeManager).getRecipes();
        recipeMap = new HashMap<>(recipeMap);
        int recipeCount = buf.readVarInt();
        NbtCrafting.advancedIngredientSerializationEnabled.set(true);
        for (int i = 0; i < recipeCount; i++) {
            RecipeSerializer<?> serializer = Registry.RECIPE_SERIALIZER.get(buf.readIdentifier());
            Identifier id = buf.readIdentifier();
            Recipe<?> recipe = serializer.read(id, buf);
            Map<Identifier, Recipe<?>> recipeType = recipeMap.computeIfAbsent(recipe.getType(), rt -> new HashMap<>());
            recipeType.put(id, recipe);
        }
        NbtCrafting.advancedIngredientSerializationEnabled.set(false);
        ((RecipeManagerAccessor) recipeManager).setRecipes(ImmutableMap.copyOf(recipeMap));
    });
}
Also used : Recipe(net.minecraft.recipe.Recipe) AnvilScreen(net.minecraft.client.gui.screen.ingame.AnvilScreen) RecipeManagerAccessor(de.siphalor.nbtcrafting.mixin.RecipeManagerAccessor) Identifier(net.minecraft.util.Identifier) RecipeType(net.minecraft.recipe.RecipeType) PacketByteBuf(net.minecraft.util.PacketByteBuf) RecipeManager(net.minecraft.recipe.RecipeManager) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with Identifier

use of net.minecraft.util.Identifier in project nbt-crafting by Siphalor.

the class MixinBrewingSlotPotion method canInsert.

@Inject(method = "canInsert(Lnet/minecraft/item/ItemStack;)Z", at = @At("RETURN"), cancellable = true)
public void canInsert(ItemStack stack, CallbackInfoReturnable<Boolean> callbackInfoReturnable) {
    if (callbackInfoReturnable.getReturnValue() || matches(stack)) {
        callbackInfoReturnable.setReturnValue(true);
        return;
    }
    RecipeManagerAccessor recipeManager;
    if (inventory instanceof BrewingStandBlockEntity) {
        recipeManager = (RecipeManagerAccessor) ((BrewingStandBlockEntity) inventory).getWorld().getRecipeManager();
    } else if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
        recipeManager = (RecipeManagerAccessor) NbtCraftingClient.getClientRecipeManager();
    } else {
        NbtCrafting.logError("Failed to get recipe manager in brewing stand container class!");
        return;
    }
    Map<Identifier, Recipe<Inventory>> recipes = recipeManager.callGetAllOfType(NbtCrafting.BREWING_RECIPE_TYPE);
    callbackInfoReturnable.setReturnValue(recipes.values().stream().anyMatch(recipe -> recipe instanceof BrewingRecipe && ((BrewingRecipe) recipe).getBase().test(stack)));
}
Also used : FabricLoader(net.fabricmc.loader.api.FabricLoader) BrewingStandBlockEntity(net.minecraft.block.entity.BrewingStandBlockEntity) NbtCraftingClient(de.siphalor.nbtcrafting.client.NbtCraftingClient) Inject(org.spongepowered.asm.mixin.injection.Inject) Slot(net.minecraft.container.Slot) Inventory(net.minecraft.inventory.Inventory) Recipe(net.minecraft.recipe.Recipe) BrewingRecipe(de.siphalor.nbtcrafting.recipe.BrewingRecipe) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) RecipeManagerAccessor(de.siphalor.nbtcrafting.mixin.RecipeManagerAccessor) ItemStack(net.minecraft.item.ItemStack) Mixin(org.spongepowered.asm.mixin.Mixin) Map(java.util.Map) EnvType(net.fabricmc.api.EnvType) Identifier(net.minecraft.util.Identifier) Shadow(org.spongepowered.asm.mixin.Shadow) NbtCrafting(de.siphalor.nbtcrafting.NbtCrafting) At(org.spongepowered.asm.mixin.injection.At) RecipeManagerAccessor(de.siphalor.nbtcrafting.mixin.RecipeManagerAccessor) Identifier(net.minecraft.util.Identifier) Recipe(net.minecraft.recipe.Recipe) BrewingRecipe(de.siphalor.nbtcrafting.recipe.BrewingRecipe) BrewingStandBlockEntity(net.minecraft.block.entity.BrewingStandBlockEntity) BrewingRecipe(de.siphalor.nbtcrafting.recipe.BrewingRecipe) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 8 with Identifier

use of net.minecraft.util.Identifier in project nbt-crafting by Siphalor.

the class MixinShapedRecipe method handlePotions.

@Inject(method = "getItemStack", at = @At("HEAD"))
private static void handlePotions(JsonObject json, CallbackInfoReturnable<ItemStack> ci) {
    if (json.has("potion")) {
        Identifier identifier = new Identifier(JsonHelper.getString(json, "potion"));
        if (!Registry.POTION.getOrEmpty(identifier).isPresent())
            throw new JsonParseException("The given resulting potion does not exist!");
        JsonObject dataObject;
        if (!json.has("data")) {
            dataObject = new JsonObject();
            json.add("data", dataObject);
        } else
            dataObject = JsonHelper.getObject(json, "data");
        dataObject.addProperty("Potion", identifier.toString());
        json.addProperty("item", "minecraft:potion");
    }
}
Also used : Identifier(net.minecraft.util.Identifier) JsonObject(com.google.gson.JsonObject) JsonParseException(com.google.gson.JsonParseException) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 9 with Identifier

use of net.minecraft.util.Identifier in project MasaGadget by plusls.

the class BborProtocol method parse.

public static void parse(PacketByteBuf buf) {
    Identifier dimensionId = buf.readIdentifier();
    ModInfo.LOGGER.debug("dimensionId = {}", dimensionId.toString());
    NbtCompound tag = BoundingBoxDeserializer.deserializeStructure(buf);
    if (!structuresCache.containsKey(dimensionId)) {
        structuresCache.put(dimensionId, new NbtList());
    }
    if (tag != null) {
        structuresCache.get(dimensionId).add(tag);
        if (enable && Configs.Minihud.COMPACT_BBOR_PROTOCOL.getBooleanValue() && MinecraftClient.getInstance().world != null) {
            BborProtocol.lock.lock();
            try {
                DataStorage.getInstance().addOrUpdateStructuresFromServer(structuresCache.get(dimensionId), 0x7fffffff - 0x1000, false);
            } catch (Exception e) {
                e.printStackTrace();
            }
            BborProtocol.lock.unlock();
        }
    }
}
Also used : Identifier(net.minecraft.util.Identifier) NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList)

Example 10 with Identifier

use of net.minecraft.util.Identifier in project MasaGadget by plusls.

the class BborProtocol method init.

public static void init() {
    // fabric-api 的实现有 bug 该事件仅会响应服务端主动断开连接的情况
    // ClientPlayConnectionEvents.DISCONNECT.register(BborProtocol::onDisconnect);
    DisconnectEvent.register(BborProtocol::onDisconnect);
    MultiConnectAPI.instance().addClientboundIdentifierCustomPayloadListener(event -> {
        Identifier channel = event.getChannel();
        bborProtocolHandler(event.getNetworkHandler(), channel, event.getData());
    });
    MultiConnectAPI.instance().addServerboundIdentifierCustomPayloadListener(event -> {
        Identifier channel = event.getChannel();
        if (channel.equals(SUBSCRIBE)) {
            ModInfo.LOGGER.debug("Multiconnect send bbor:SUBSCRIBE");
            MultiConnectAPI.instance().forceSendCustomPayload(event.getNetworkHandler(), event.getChannel(), event.getData());
        }
    });
}
Also used : Identifier(net.minecraft.util.Identifier)

Aggregations

Identifier (net.minecraft.util.Identifier)343 NbtList (net.minecraft.nbt.NbtList)36 ItemStack (net.minecraft.item.ItemStack)31 Item (net.minecraft.item.Item)28 NbtCompound (net.minecraft.nbt.NbtCompound)22 NbtElement (net.minecraft.nbt.NbtElement)22 Inject (org.spongepowered.asm.mixin.injection.Inject)22 IOException (java.io.IOException)18 Block (net.minecraft.block.Block)18 MinecraftClient (net.minecraft.client.MinecraftClient)15 BlockItem (net.minecraft.item.BlockItem)15 BlockPos (net.minecraft.util.math.BlockPos)15 Map (java.util.Map)12 BlockState (net.minecraft.block.BlockState)12 ArrayList (java.util.ArrayList)11 VertexConsumer (net.minecraft.client.render.VertexConsumer)11 ResourceManager (net.minecraft.resource.ResourceManager)11 SoundEvent (net.minecraft.sound.SoundEvent)11 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)10 LiteralText (net.minecraft.text.LiteralText)10