use of de.siphalor.nbtcrafting.mixin.RecipeManagerAccessor 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));
});
}
use of de.siphalor.nbtcrafting.mixin.RecipeManagerAccessor 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)));
}
use of de.siphalor.nbtcrafting.mixin.RecipeManagerAccessor in project nbt-crafting by Siphalor.
the class MixinBrewingSlotIngredient 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() || BrewingRecipeRegistry.isValidIngredient(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).getIngredient().test(stack)));
}
Aggregations