net.minecraft.recipe.Recipe Java Examples

The following examples show how to use net.minecraft.recipe.Recipe. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MixinClientPlayNetworkHandler.java    From multiconnect with MIT License 6 votes vote down vote up
@Inject(method = "onGameJoin", at = @At("RETURN"))
private void onOnGameJoin(GameJoinS2CPacket packet, CallbackInfo ci) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_12_2) {
        onSynchronizeTags(new SynchronizeTagsS2CPacket(new RegistryTagManager()));

        Protocol_1_12_2 protocol = (Protocol_1_12_2) ConnectionInfo.protocol;
        List<Recipe<?>> recipes = new ArrayList<>();
        List<RecipeInfo<?>> recipeInfos = protocol.getCraftingRecipes();
        for (int i = 0; i < recipeInfos.size(); i++) {
            recipes.add(recipeInfos.get(i).create(new Identifier(String.valueOf(i))));
        }
        onSynchronizeRecipes(new SynchronizeRecipesS2CPacket(recipes));

        CommandDispatcher<CommandSource> dispatcher = new CommandDispatcher<>();
        Commands_1_12_2.registerAll(dispatcher, null);
        onCommandTree(new CommandTreeS2CPacket(dispatcher.getRoot()));
        TabCompletionManager.requestCommandList();
    }
}
 
Example #2
Source File: GalacticraftREIPlugin.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public void registerRecipeDisplays(RecipeHelper recipeHelper) {
    for (Recipe<?> value : recipeHelper.getRecipeManager().values()) {
        if (value instanceof FabricationRecipe) {
            recipeHelper.registerDisplay(new DefaultFabricationDisplay((FabricationRecipe) value));
        } else if (value instanceof ShapelessCompressingRecipe) {
            recipeHelper.registerDisplay(new DefaultShapelessCompressingDisplay((ShapelessCompressingRecipe) value));
        } else if (value instanceof ShapedCompressingRecipe) {
            recipeHelper.registerDisplay(new DefaultShapedCompressingDisplay((ShapedCompressingRecipe) value));
        }
    }
}
 
Example #3
Source File: GalacticraftRecipes.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
private static <T extends Recipe<?>> RecipeType<T> registerType(String id) {
    return Registry.register(Registry.RECIPE_TYPE, new Identifier(Constants.MOD_ID, id), new RecipeType<T>() {
        public String toString() {
            return id;
        }
    });
}
 
Example #4
Source File: MixinClientPlayNetworkHandler.java    From multiconnect with MIT License 5 votes vote down vote up
@Inject(method = "onSynchronizeRecipes", at = @At("TAIL"))
private void onOnSynchronizeRecipes(SynchronizeRecipesS2CPacket packet, CallbackInfo ci) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_11_2) {
        onUnlockRecipes(new UnlockRecipesS2CPacket(
                UnlockRecipesS2CPacket.Action.INIT,
                Collections2.transform(packet.getRecipes(), Recipe::getId),
                Collections2.transform(packet.getRecipes(), Recipe::getId),
                false,
                false,
                false,
                false
        ));
    }
}
 
Example #5
Source File: RecipeBook_1_12.java    From multiconnect with MIT License 5 votes vote down vote up
public void handleRecipeClicked(Recipe<C> recipe, RecipeResultCollection recipes) {
    assert mc.player != null;
    assert mc.getNetworkHandler() != null;

    boolean craftable = recipes.isCraftable(recipe);

    if (!craftable && iRecipeBookWidget.getGhostSlots().getRecipe() == recipe) {
        return;
    }

    if (!canClearCraftMatrix() && !mc.player.isCreative()) {
        return;
    }

    if (craftable) {
        tryPlaceRecipe(recipe, container.slots);
    } else {
        // clear craft matrix and show ghost recipe
        List<PlaceRecipeC2SPacket_1_12.Transaction> transactionFromMatrix = clearCraftMatrix();
        recipeBookWidget.showGhostRecipe(recipe, container.slots);

        if (!transactionFromMatrix.isEmpty()) {
            short transactionId = mc.player.currentScreenHandler.getNextActionId(mc.player.inventory);
            mc.getNetworkHandler().sendPacket(new PlaceRecipeC2SPacket_1_12(container.syncId, transactionId, transactionFromMatrix, new ArrayList<>()));

            if (iRecipeBookWidget.getRecipeBook().isFilteringCraftable()) {
                mc.player.inventory.markDirty();
            }
        }
    }

    if (!iRecipeBookWidget.multiconnect_isWide()) {
        recipeBookWidget.toggleOpen();
    }
}
 
Example #6
Source File: RecipeBook_1_12.java    From multiconnect with MIT License 5 votes vote down vote up
private void placeRecipe(Recipe<C> recipe, List<Slot> slots, int placeCount, IntList inputItemIds, List<PlaceRecipeC2SPacket_1_12.Transaction> transactionsToMatrix) {
    int width = container.getCraftingWidth();
    int height = container.getCraftingHeight();

    if (recipe instanceof ShapedRecipe) {
        ShapedRecipe shaped = (ShapedRecipe) recipe;
        width = shaped.getWidth();
        height = shaped.getHeight();
    }

    int serverSlot = 1;
    Iterator<Integer> inputItemItr = inputItemIds.iterator();

    // :thonkjang: probably meant to swap craftingWidth and craftingHeight here, but oh well because width = height
    for (int y = 0; y < container.getCraftingWidth() && y != height; y++) {
        for (int x = 0; x < container.getCraftingHeight(); x++) {
            if (x == width || !inputItemItr.hasNext()) {
                serverSlot += container.getCraftingWidth() - x;
                break;
            }

            Slot slot = slots.get(serverSlot);

            ItemStack stackNeeded = RecipeFinder.getStackFromId(inputItemItr.next());
            if (!stackNeeded.isEmpty()) {
                for (int i = 0; i < placeCount; i++) {
                    PlaceRecipeC2SPacket_1_12.Transaction transaction = findAndMoveToCraftMatrix(serverSlot, slot, stackNeeded);
                    if (transaction != null) {
                        transactionsToMatrix.add(transaction);
                    }
                }
            }
            serverSlot++;
        }

        if (!inputItemItr.hasNext()) {
            break;
        }
    }
}
 
Example #7
Source File: RecipeManager_scarpetMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Override
public List<Recipe<?>> getAllMatching(RecipeType type, Identifier output)
{
    Map<Identifier, Recipe<?>> typeRecipes = recipes.get(type);
    if (typeRecipes.containsKey(output)) return Collections.singletonList(typeRecipes.get(output));
    return Lists.newArrayList(typeRecipes.values().stream().filter(
            r -> Registry.ITEM.getId(r.getOutput().getItem()).equals(output)).collect(Collectors.toList()));
}
 
Example #8
Source File: GalacticraftRecipes.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
private static <S extends RecipeSerializer<T>, T extends Recipe<?>> S registerSerializer(String id, S serializer) {
    return Registry.register(Registry.RECIPE_SERIALIZER, new Identifier(Constants.MOD_ID, id), serializer);
}
 
Example #9
Source File: RecipeBook_1_12.java    From multiconnect with MIT License 4 votes vote down vote up
private void tryPlaceRecipe(Recipe<C> recipe, List<Slot> slots) {
    assert mc.player != null;
    assert mc.getNetworkHandler() != null;

    boolean alreadyPlaced = container.matches(recipe);
    int possibleCraftCount = iRecipeBookWidget.getRecipeFinder().countRecipeCrafts(recipe, null);

    if (alreadyPlaced) {
        // check each item in the input to see if we're already at the max crafts possible
        boolean canPlaceMore = false;

        for (int i = 0; i < container.getCraftingSlotCount(); i++) {
            if (i == container.getCraftingResultSlotIndex())
                continue;

            ItemStack stack = container.getSlot(i).getStack();

            if (!stack.isEmpty() && stack.getCount() < possibleCraftCount) {
                canPlaceMore = true;
            }
        }

        if (!canPlaceMore) {
            return;
        }
    }

    int craftCount = calcCraftCount(possibleCraftCount, alreadyPlaced);

    IntList inputItemIds = new IntArrayList();
    if (iRecipeBookWidget.getRecipeFinder().findRecipe(recipe, inputItemIds, craftCount)) {
        // take into account max stack sizes now we've found the actual inputs
        int actualCount = craftCount;

        for (int itemId : inputItemIds) {
            int maxCount = RecipeFinder.getStackFromId(itemId).getMaxCount();

            if (actualCount > maxCount) {
                actualCount = maxCount;
            }
        }

        if (iRecipeBookWidget.getRecipeFinder().findRecipe(recipe, inputItemIds, actualCount)) {
            // clear the craft matrix and place the recipe
            List<PlaceRecipeC2SPacket_1_12.Transaction> transactionsFromMatrix = clearCraftMatrix();
            List<PlaceRecipeC2SPacket_1_12.Transaction> transactionsToMatrix = new ArrayList<>();
            placeRecipe(recipe, slots, actualCount, inputItemIds, transactionsToMatrix);
            short transactionId = mc.player.currentScreenHandler.getNextActionId(mc.player.inventory);
            mc.getNetworkHandler().sendPacket(new PlaceRecipeC2SPacket_1_12(container.syncId, transactionId, transactionsFromMatrix, transactionsToMatrix));
            mc.player.inventory.markDirty();
        }
    }
}
 
Example #10
Source File: MixinRecipeBookWidget.java    From multiconnect with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Unique
private static <C extends Inventory> void handleRecipeClicked(RecipeBook_1_12<C> recipeBook112, Recipe<?> recipe, RecipeResultCollection results) {
    recipeBook112.handleRecipeClicked((Recipe<C>) recipe, results);
}
 
Example #11
Source File: MixinRecipeGridAligner.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * @author qouteall
 * @reason https://github.com/FabricMC/Mixin/issues/15
 */
@Overwrite
default void alignRecipeToGrid(
		int gridWidth, int gridHeight, int gridOutputSlot,
		Recipe<?> recipe, Iterator<?> inputs, int amount
) {
	int width = gridWidth;
	int height = gridHeight;

	// change start
	if (recipe instanceof IShapedRecipe) {
		IShapedRecipe<?> shapedRecipe = (IShapedRecipe<?>) recipe;
		width = shapedRecipe.getRecipeWidth();
		height = shapedRecipe.getRecipeHeight();
	}

	// change end

	int slot = 0;

	for (int y = 0; y < gridHeight; ++y) {
		if (slot == gridOutputSlot) {
			++slot;
		}

		boolean bl = (float) height < (float) gridHeight / 2.0F;

		int m = MathHelper.floor((float) gridHeight / 2.0F - (float) height / 2.0F);

		if (bl && m > y) {
			slot += gridWidth;
			++y;
		}

		for (int x = 0; x < gridWidth; ++x) {
			if (!inputs.hasNext()) {
				return;
			}

			bl = (float) width < (float) gridWidth / 2.0F;
			m = MathHelper.floor((float) gridWidth / 2.0F - (float) width / 2.0F);
			int o = width;

			boolean bl2 = x < width;

			if (bl) {
				o = m + width;
				bl2 = m <= x && x < m + width;
			}

			if (bl2) {
				this.acceptAlignedInput(inputs, slot, amount, y, x);
			} else if (o == x) {
				slot += gridWidth - x;
				break;
			}

			++slot;
		}
	}
}
 
Example #12
Source File: RecipeManagerInterface.java    From fabric-carpet with MIT License votes vote down vote up
List<Recipe<?>> getAllMatching(RecipeType type, Identifier output);