use of net.minecraft.world.inventory.CraftingContainer in project SpongeCommon by SpongePowered.
the class RecipeManagerMixin_API method findMatchingRecipe.
@Override
@SuppressWarnings("unchecked")
public Optional<Recipe> findMatchingRecipe(final Inventory inventory, final ServerWorld world) {
Preconditions.checkNotNull(inventory);
Preconditions.checkNotNull(world);
if (inventory instanceof AbstractFurnaceBlockEntity) {
final net.minecraft.world.item.crafting.RecipeType<? extends AbstractCookingRecipe> type = ((AbstractFurnaceBlockEntityAccessor) inventory).accessor$recipeType();
return this.<Container, AbstractCookingRecipe>shadow$getRecipeFor((net.minecraft.world.item.crafting.RecipeType<AbstractCookingRecipe>) type, (Container) inventory, (net.minecraft.world.level.Level) world).map(Recipe.class::cast);
}
if (inventory instanceof CampfireBlockEntity) {
return this.shadow$getRecipeFor(net.minecraft.world.item.crafting.RecipeType.CAMPFIRE_COOKING, (Container) inventory, (net.minecraft.world.level.Level) world).map(Recipe.class::cast);
}
if (inventory instanceof CraftingMenu) {
final CraftingContainer craftingInventory = ((CraftingMenuAccessor) inventory).accessor$craftSlots();
return this.shadow$getRecipeFor(net.minecraft.world.item.crafting.RecipeType.CRAFTING, craftingInventory, (net.minecraft.world.level.Level) world).map(Recipe.class::cast);
}
if (inventory instanceof InventoryMenu) {
final CraftingContainer craftingInventory = ((InventoryMenuAccessor) inventory).accessor$craftSlots();
return this.shadow$getRecipeFor(net.minecraft.world.item.crafting.RecipeType.CRAFTING, craftingInventory, (net.minecraft.world.level.Level) world).map(Recipe.class::cast);
}
if (inventory instanceof StonecutterMenu) {
final Container stonecutterInventory = ((StonecutterMenu) inventory).container;
return this.shadow$getRecipeFor(net.minecraft.world.item.crafting.RecipeType.STONECUTTING, stonecutterInventory, (net.minecraft.world.level.Level) world).map(Recipe.class::cast);
}
return Optional.empty();
}
use of net.minecraft.world.inventory.CraftingContainer in project SpongeCommon by SpongePowered.
the class ContainerUtil method generateAdapterLens.
@SuppressWarnings({ "unchecked", "rawtypes" })
private static Lens generateAdapterLens(final SlotLensProvider slots, final int index, final org.spongepowered.common.inventory.util.ContainerUtil.CraftingInventoryData crafting, final List<Slot> slotList, final net.minecraft.world.@Nullable Container subInventory) {
Lens lens = ((InventoryBridge) subInventory).bridge$getAdapter().inventoryAdapter$getRootLens();
if (lens instanceof PlayerInventoryLens) {
if (slotList.size() == 36) {
return new DelegatingLens(index, new PrimaryPlayerInventoryLens(0, slots, true), slots);
}
return lens;
}
// For Crafting Result we need the Slot to get Filter logic
if (subInventory instanceof ResultContainer) {
final Slot slot = slotList.get(0);
if (slot instanceof ResultSlotAccessor) {
crafting.out = index;
if (crafting.base == null) {
// In case we do not find the InventoryCrafting later assume it is directly after the SlotCrafting
// e.g. for IC2 ContainerIndustrialWorkbench
crafting.base = index + 1;
crafting.grid = ((ResultSlotAccessor) slot).accessor$craftSlots();
}
}
}
if (subInventory instanceof CraftingContainer) {
crafting.base = index;
crafting.grid = ((CraftingContainer) subInventory);
}
return new DelegatingLens(index, slotList, lens, slots);
}
use of net.minecraft.world.inventory.CraftingContainer in project SpongeCommon by SpongePowered.
the class SpongeShapedCraftingRecipeSerializer method fromJson.
@Override
public ShapedRecipe fromJson(ResourceLocation recipeId, JsonObject json) {
final String s = GsonHelper.getAsString(json, Constants.Recipe.GROUP, "");
final JsonObject ingredientKey = GsonHelper.getAsJsonObject(json, Constants.Recipe.SHAPED_INGREDIENTS);
final Map<String, Ingredient> map = this.deserializeIngredientKey(ingredientKey);
final String[] astring = ShapedRecipeAccessor.invoker$shrink(ShapedRecipeAccessor.invoker$patternFromJson(GsonHelper.getAsJsonArray(json, Constants.Recipe.SHAPED_PATTERN)));
final int i = astring[0].length();
final int j = astring.length;
final NonNullList<Ingredient> nonnulllist = ShapedRecipeAccessor.invoker$dissolvePattern(astring, map, i, j);
final ItemStack itemstack = ShapedRecipe.itemFromJson(GsonHelper.getAsJsonObject(json, Constants.Recipe.RESULT));
final ItemStack spongeStack = IngredientResultUtil.deserializeItemStack(json.getAsJsonObject(Constants.Recipe.SPONGE_RESULT));
final Function<CraftingContainer, ItemStack> resultFunction = IngredientResultUtil.deserializeResultFunction(json);
final Function<CraftingContainer, NonNullList<ItemStack>> remainingItemsFunction = IngredientResultUtil.deserializeRemainingItemsFunction(json);
return new SpongeShapedRecipe(recipeId, s, i, j, nonnulllist, spongeStack == null ? itemstack : spongeStack, resultFunction, remainingItemsFunction);
}
use of net.minecraft.world.inventory.CraftingContainer in project SpongeCommon by SpongePowered.
the class SpongeShapelessCraftingRecipeSerializer method fromJson.
@Override
public ShapelessRecipe fromJson(ResourceLocation recipeId, JsonObject json) {
final String s = GsonHelper.getAsString(json, Constants.Recipe.GROUP, "");
final NonNullList<Ingredient> nonnulllist = this.readIngredients(GsonHelper.getAsJsonArray(json, Constants.Recipe.SHAPELESS_INGREDIENTS));
if (nonnulllist.isEmpty()) {
throw new JsonParseException("No ingredients for shapeless recipe");
}
if (nonnulllist.size() > 9) {
throw new JsonParseException("Too many ingredients for shapeless recipe");
}
final ItemStack itemstack = ShapedRecipe.itemFromJson(GsonHelper.getAsJsonObject(json, Constants.Recipe.RESULT));
final ItemStack spongeStack = IngredientResultUtil.deserializeItemStack(json.getAsJsonObject(Constants.Recipe.SPONGE_RESULT));
final Function<CraftingContainer, ItemStack> resultFunction = IngredientResultUtil.deserializeResultFunction(json);
final Function<CraftingContainer, NonNullList<ItemStack>> remainingItemsFunction = IngredientResultUtil.deserializeRemainingItemsFunction(json);
return new SpongeShapelessRecipe(recipeId, s, spongeStack == null ? itemstack : spongeStack, nonnulllist, resultFunction, remainingItemsFunction);
}
use of net.minecraft.world.inventory.CraftingContainer in project SpongeCommon by SpongePowered.
the class LensRegistrar method generateLens.
@SuppressWarnings("unchecked")
private static Lens generateLens(Object inventory, int size, SlotLensProvider slotLensProvider) {
if (size == 0) {
return new DefaultEmptyLens();
}
LensFactory lensFactory = LensRegistrar.lensFactories.get(inventory.getClass());
Lens lens = null;
if (lensFactory != null) {
lens = lensFactory.apply(inventory.getClass(), size, slotLensProvider);
if (lens != null) {
return lens;
}
}
if (inventory instanceof CraftingContainer) {
lens = LensRegistrar.lensCraftingInventory(size, ((CraftingContainer) inventory).getWidth(), ((CraftingContainer) inventory).getHeight(), slotLensProvider);
} else if (inventory instanceof AbstractContainerMenu) {
lens = ContainerUtil.generateLens(((AbstractContainerMenu) inventory), slotLensProvider);
} else if (size == 1) {
return slotLensProvider.getSlotLens(0);
}
if (lens != null) {
return lens;
}
return new SingleIndexedLens(0, size, (Class<? extends Inventory>) inventory.getClass(), slotLensProvider);
}
Aggregations