use of net.minecraft.inventory.CraftingInventory in project minecolonies by Minecolonies.
the class PrivateCraftingTeachingTransferHandler method transferRecipe.
@Nullable
@Override
public IRecipeTransferError transferRecipe(@NotNull final ContainerCrafting craftingGUIBuilding, @NotNull final Object recipe, @NotNull final IRecipeLayout recipeLayout, @NotNull final PlayerEntity player, final boolean maxTransfer, final boolean doTransfer) {
final IGuiItemStackGroup itemStackGroup = recipeLayout.getItemStacks();
// compact the crafting grid into a 2x2 area
final Map<Integer, ItemStack> guiIngredients = new HashMap<>();
guiIngredients.put(0, ItemStackUtils.EMPTY);
guiIngredients.put(1, ItemStackUtils.EMPTY);
guiIngredients.put(3, ItemStackUtils.EMPTY);
guiIngredients.put(4, ItemStackUtils.EMPTY);
// indexes that do not fit into the player crafting grid
final Set<Integer> badIndexes;
if (craftingGUIBuilding.isComplete()) {
guiIngredients.put(2, ItemStackUtils.EMPTY);
guiIngredients.put(5, ItemStackUtils.EMPTY);
guiIngredients.put(6, ItemStackUtils.EMPTY);
guiIngredients.put(7, ItemStackUtils.EMPTY);
guiIngredients.put(8, ItemStackUtils.EMPTY);
badIndexes = ImmutableSet.of();
} else {
badIndexes = ImmutableSet.of(2, 5, 6, 7, 8);
}
int inputIndex = 0;
for (final IGuiIngredient<ItemStack> ingredient : itemStackGroup.getGuiIngredients().values()) {
if (ingredient.isInput()) {
if (!ingredient.getAllIngredients().isEmpty()) {
if (badIndexes.contains(inputIndex)) {
final ITextComponent tooltipMessage = new TranslationTextComponent("jei.tooltip.error.recipe.transfer.too.large.player.inventory");
return handlerHelper.createUserErrorForSlots(tooltipMessage, badIndexes);
}
guiIngredients.put(inputIndex, ingredient.getDisplayedIngredient());
}
inputIndex++;
}
}
if (doTransfer) {
final CraftingInventory craftMatrix = craftingGUIBuilding.getInv();
if (craftingGUIBuilding.isComplete()) {
craftMatrix.setItem(0, guiIngredients.get(0));
craftMatrix.setItem(1, guiIngredients.get(1));
craftMatrix.setItem(2, guiIngredients.get(2));
craftMatrix.setItem(3, guiIngredients.get(3));
craftMatrix.setItem(4, guiIngredients.get(4));
craftMatrix.setItem(5, guiIngredients.get(5));
craftMatrix.setItem(6, guiIngredients.get(6));
craftMatrix.setItem(7, guiIngredients.get(7));
craftMatrix.setItem(8, guiIngredients.get(8));
} else {
craftMatrix.setItem(0, guiIngredients.get(0));
craftMatrix.setItem(1, guiIngredients.get(1));
craftMatrix.setItem(2, guiIngredients.get(3));
craftMatrix.setItem(3, guiIngredients.get(4));
}
final TransferRecipeCraftingTeachingMessage message = new TransferRecipeCraftingTeachingMessage(guiIngredients, craftingGUIBuilding.isComplete());
Network.getNetwork().sendToServer(message);
}
return null;
}
use of net.minecraft.inventory.CraftingInventory in project minecolonies by Minecolonies.
the class JEIPlugin method buildVanillaRecipesMap.
private Map<IRecipeType<?>, List<IGenericRecipe>> buildVanillaRecipesMap() {
final RecipeManager recipeManager = Minecraft.getInstance().level.getRecipeManager();
final List<IGenericRecipe> craftingRecipes = new ArrayList<>();
for (final IRecipe<CraftingInventory> recipe : recipeManager.byType(IRecipeType.CRAFTING).values()) {
if (!recipe.canCraftInDimensions(3, 3))
continue;
tryAddingVanillaRecipe(craftingRecipes, recipe);
}
final List<IGenericRecipe> smeltingRecipes = new ArrayList<>();
for (final IRecipe<IInventory> recipe : recipeManager.byType(IRecipeType.SMELTING).values()) {
tryAddingVanillaRecipe(smeltingRecipes, recipe);
}
return new ImmutableMap.Builder<IRecipeType<?>, List<IGenericRecipe>>().put(IRecipeType.CRAFTING, craftingRecipes).put(IRecipeType.SMELTING, smeltingRecipes).build();
}
use of net.minecraft.inventory.CraftingInventory in project minecolonies by Minecolonies.
the class GenericRecipe method calculateSecondaryOutputs.
@NotNull
private static List<ItemStack> calculateSecondaryOutputs(@NotNull final IRecipe<?> recipe) {
if (recipe instanceof ICraftingRecipe) {
final List<Ingredient> inputs = recipe.getIngredients();
final CraftingInventory inv = new CraftingInventory(new Container(ContainerType.CRAFTING, 0) {
@Override
public boolean stillValid(@NotNull final PlayerEntity playerIn) {
return false;
}
}, 3, 3);
for (int slot = 0; slot < inputs.size(); ++slot) {
final ItemStack[] stacks = inputs.get(slot).getItems();
if (stacks.length > 0) {
inv.setItem(slot, stacks[0]);
}
}
if (((ICraftingRecipe) recipe).matches(inv, null)) {
return ((ICraftingRecipe) recipe).getRemainingItems(inv).stream().filter(ItemStackUtils::isNotEmpty).filter(// this is filtered out of the inputs too
stack -> stack.getItem() != buildTool.get()).collect(Collectors.toList());
}
}
return Collections.emptyList();
}
use of net.minecraft.inventory.CraftingInventory in project MCMOD-Industria by M-Marvin.
the class TileEntityMStoringCraftingTable method tick.
@Override
public void tick() {
if (!this.level.isClientSide()) {
ElectricityNetworkHandler.getHandlerForWorld(level).updateNetwork(level, worldPosition);
ElectricityNetwork network = ElectricityNetworkHandler.getHandlerForWorld(level).getNetwork(worldPosition);
CraftingInventory craftMatrix = makeCraftMatrix();
ICraftingRecipe recipe = findRecipe(craftMatrix);
canWork = false;
if (recipe != null) {
ItemStack result = recipe.assemble(craftMatrix);
ItemStack stack = this.getItem(9);
if (stack.isEmpty()) {
canWork = true;
} else if (stack.getItem() == result.getItem() && stack.getCount() + result.getCount() <= result.getMaxStackSize()) {
canWork = true;
}
}
this.hasPower = network.canMachinesRun() == Voltage.NormalVoltage;
this.isWorking = this.canWork && hasPower;
if (this.isWorking) {
if (this.progress >= 100) {
ItemStack result = recipe.assemble(craftMatrix);
ItemStack stack = this.getItem(9);
this.remainingItems = recipe.getRemainingItems(craftMatrix);
if (stack.isEmpty()) {
this.inventory.set(9, result.copy());
} else if (stack.getItem() == result.getItem() && stack.getCount() + result.getCount() <= result.getMaxStackSize()) {
stack.grow(result.getCount());
}
for (int i = 0; i < 9; i++) {
if (this.inventory.get(i).getItem() != this.inventory.get(10).getItem())
this.inventory.get(i).shrink(1);
}
for (int i = 0; i < 9; i++) {
ItemStack remainingItem = remainingItems.get(i);
if (!remainingItem.isEmpty())
this.inventory.set(i, remainingItem.copy());
}
this.progress = 0;
} else {
this.progress++;
}
}
}
}
use of net.minecraft.inventory.CraftingInventory in project SophisticatedBackpacks by P3pp3rF1y.
the class RecipeHelper method getCompactingResult.
private static CompactingResult getCompactingResult(Item item, World w, int width, int height) {
CompactedItem compactedItem = new CompactedItem(item, width, height);
if (COMPACTING_RESULTS.containsKey(compactedItem)) {
return COMPACTING_RESULTS.get(compactedItem);
}
CraftingInventory craftingInventory = getFilledCraftingInventory(item, width, height);
List<ItemStack> remainingItems = new ArrayList<>();
ItemStack result = w.getRecipeManager().getRecipeFor(IRecipeType.CRAFTING, craftingInventory, w).map(r -> {
r.getRemainingItems(craftingInventory).forEach(stack -> {
if (!stack.isEmpty()) {
remainingItems.add(stack);
}
});
return r.assemble(craftingInventory);
}).orElse(ItemStack.EMPTY);
CompactingResult compactingResult = new CompactingResult(result, remainingItems);
if (!result.isEmpty()) {
COMPACTING_RESULTS.put(compactedItem, compactingResult);
}
return compactingResult;
}
Aggregations