use of net.minecraft.block.entity.BrewingStandBlockEntity 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 net.minecraft.block.entity.BrewingStandBlockEntity 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)));
}
use of net.minecraft.block.entity.BrewingStandBlockEntity in project nbt-crafting by Siphalor.
the class MixinBrewingStandBlockEntity method craft.
@Inject(method = "craft", at = @At("HEAD"), cancellable = true)
private void craft(CallbackInfo callbackInfo) {
Optional<BrewingRecipe> recipe = world.getRecipeManager().getFirstMatch(NbtCrafting.BREWING_RECIPE_TYPE, (BrewingStandBlockEntity) (Object) this, world);
if (recipe.isPresent()) {
BrewingStandBlockEntity inv = (BrewingStandBlockEntity) (Object) this;
DefaultedList<ItemStack> remainingStacks = recipe.get().getRemainingStacks(inv);
ItemStack[] results = recipe.get().craftAll(inv);
getInvStack(3).decrement(1);
for (int i = 0; i < 3; i++) {
if (results[i] != null) {
setInvStack(i, results[i]);
}
}
RecipeUtil.putRemainders(remainingStacks, inv, world, pos);
world.playLevelEvent(1035, pos, 0);
callbackInfo.cancel();
}
}
Aggregations