use of net.minecraft.world.item.crafting.CraftingRecipe in project Polymorph by TheIllusiveC4.
the class TomsStorageModule method selectRecipe.
@Override
public boolean selectRecipe(BlockEntity tileEntity, Recipe<?> recipe) {
if (recipe instanceof CraftingRecipe && tileEntity instanceof TileEntityCraftingTerminal) {
AccessorTileEntityCraftingTerminal te = (AccessorTileEntityCraftingTerminal) tileEntity;
te.setCurrentRecipe((CraftingRecipe) recipe);
te.callOnCraftingMatrixChanged();
return true;
}
return false;
}
use of net.minecraft.world.item.crafting.CraftingRecipe in project improved-stations by shedaniel.
the class CraftingStationMenu method updateResult.
protected void updateResult(AbstractContainerMenu menu, Level level, Player player, CraftingContainer craftingInventory, ResultContainer resultInventory) {
if (!level.isClientSide) {
ServerPlayer serverPlayerEntity = (ServerPlayer) player;
ItemStack itemStack = ItemStack.EMPTY;
Optional<CraftingRecipe> optional = Objects.requireNonNull(level.getServer()).getRecipeManager().getRecipeFor(RecipeType.CRAFTING, craftingInventory, level);
if (optional.isPresent()) {
CraftingRecipe craftingRecipe = optional.get();
if (resultInventory.setRecipeUsed(level, serverPlayerEntity, craftingRecipe)) {
itemStack = craftingRecipe.assemble(craftingInventory);
}
}
resultInventory.setItem(0, itemStack);
menu.setRemoteSlot(0, itemStack);
serverPlayerEntity.connection.send(new ClientboundContainerSetSlotPacket(menu.containerId, menu.incrementStateId(), 0, itemStack));
}
}
use of net.minecraft.world.item.crafting.CraftingRecipe in project excavated_variants by lukebemish.
the class JeiCompat method registerRecipes.
@Override
public void registerRecipes(@NotNull IRecipeRegistration registration) {
if (ExcavatedVariants.getConfig().add_conversion_recipes && ExcavatedVariants.getConfig().jei_rei_compat) {
List<CraftingRecipe> recipes = new ArrayList<>();
OreConversionRecipe.assembleOrNull();
for (Pair<BaseOre, HashSet<BaseStone>> p : ExcavatedVariants.oreStoneList) {
ArrayList<Item> items = new ArrayList<>();
for (BaseStone stone : p.last()) {
ResourceLocation rl = new ResourceLocation(ExcavatedVariants.MOD_ID, stone.id + "_" + p.first().id);
Item item = Services.REGISTRY_UTIL.getItemById(rl);
if (item != null) {
items.add(item);
}
}
Item outItem = Services.REGISTRY_UTIL.getItemById(p.first().block_id.get(0));
if (items.size() > 0 && outItem != null) {
Ingredient input = Ingredient.of(items.stream().map(ItemStack::new));
ItemStack output = new ItemStack(outItem);
NonNullList<Ingredient> inputs = NonNullList.of(Ingredient.EMPTY, input);
String ore_id = p.first().id;
recipes.add(new ShapelessRecipe(new ResourceLocation(ExcavatedVariants.MOD_ID, ore_id + "_conversion"), "excavated_variants.ore_conversion", output, inputs));
}
}
registration.addRecipes(RecipeTypes.CRAFTING, recipes);
}
}
use of net.minecraft.world.item.crafting.CraftingRecipe in project EvilCraft by CyclopsMC.
the class ContainerExaltedCrafter method slotsChanged.
@Override
public void slotsChanged(Container inventory) {
if (initialized && !this.world.isClientSide()) {
ItemStack itemstack = ItemStack.EMPTY;
// Slightly altered logic from Container#slotChangedCraftingGrid
CraftingRecipe irecipe = world.getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, craftingGrid, world).orElse(null);
if (irecipe != null && result.setRecipeUsed(world, (ServerPlayer) player, irecipe)) {
itemstack = irecipe.assemble(craftingGrid);
}
result.setItem(0, itemstack);
((ServerPlayer) this.player).connection.send(new ClientboundContainerSetSlotPacket(this.containerId, getStateId(), 9, itemstack));
craftingGrid.save();
}
}
use of net.minecraft.world.item.crafting.CraftingRecipe in project Create by Creators-of-Create.
the class BlueprintEntity method interactAt.
@Override
public InteractionResult interactAt(Player player, Vec3 vec, InteractionHand hand) {
if (player instanceof FakePlayer)
return InteractionResult.PASS;
boolean holdingWrench = AllItems.WRENCH.isIn(player.getItemInHand(hand));
BlueprintSection section = getSectionAt(vec);
ItemStackHandler items = section.getItems();
if (!holdingWrench && !level.isClientSide && !items.getStackInSlot(9).isEmpty()) {
IItemHandlerModifiable playerInv = new InvWrapper(player.getInventory());
boolean firstPass = true;
int amountCrafted = 0;
ForgeHooks.setCraftingPlayer(player);
Optional<CraftingRecipe> recipe = Optional.empty();
do {
Map<Integer, ItemStack> stacksTaken = new HashMap<>();
Map<Integer, ItemStack> craftingGrid = new HashMap<>();
boolean success = true;
Search: for (int i = 0; i < 9; i++) {
ItemStack requestedItem = items.getStackInSlot(i);
if (requestedItem.isEmpty()) {
craftingGrid.put(i, ItemStack.EMPTY);
continue;
}
for (int slot = 0; slot < playerInv.getSlots(); slot++) {
if (!FilterItem.test(level, playerInv.getStackInSlot(slot), requestedItem))
continue;
ItemStack currentItem = playerInv.extractItem(slot, 1, false);
if (stacksTaken.containsKey(slot))
stacksTaken.get(slot).grow(1);
else
stacksTaken.put(slot, currentItem.copy());
craftingGrid.put(i, currentItem);
continue Search;
}
success = false;
break;
}
if (success) {
CraftingContainer craftingInventory = new BlueprintCraftingInventory(craftingGrid);
if (!recipe.isPresent())
recipe = level.getRecipeManager().getRecipeFor(RecipeType.CRAFTING, craftingInventory, level);
ItemStack result = recipe.filter(r -> r.matches(craftingInventory, level)).map(r -> r.assemble(craftingInventory)).orElse(ItemStack.EMPTY);
if (result.isEmpty()) {
success = false;
} else if (result.getCount() + amountCrafted > 64) {
success = false;
} else {
amountCrafted += result.getCount();
result.onCraftedBy(player.level, player, 1);
ForgeEventFactory.firePlayerCraftingEvent(player, result, craftingInventory);
NonNullList<ItemStack> nonnulllist = level.getRecipeManager().getRemainingItemsFor(RecipeType.CRAFTING, craftingInventory, level);
if (firstPass)
level.playSound(null, player.blockPosition(), SoundEvents.ITEM_PICKUP, SoundSource.PLAYERS, .2f, 1f + Create.RANDOM.nextFloat());
player.getInventory().placeItemBackInInventory(result);
for (ItemStack itemStack : nonnulllist) player.getInventory().placeItemBackInInventory(itemStack);
firstPass = false;
}
}
if (!success) {
for (Entry<Integer, ItemStack> entry : stacksTaken.entrySet()) playerInv.insertItem(entry.getKey(), entry.getValue(), false);
break;
}
} while (player.isShiftKeyDown());
ForgeHooks.setCraftingPlayer(null);
return InteractionResult.SUCCESS;
}
int i = section.index;
if (!level.isClientSide && player instanceof ServerPlayer) {
NetworkHooks.openGui((ServerPlayer) player, section, buf -> {
buf.writeVarInt(getId());
buf.writeVarInt(i);
});
}
return InteractionResult.SUCCESS;
}
Aggregations